From ad973491d6c0f2d97d6e15951b59aa7d9e2a0adf Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Wed, 21 Feb 2018 18:38:15 +0100 Subject: [PATCH 01/22] [setup.py] Remove rdflib-jsonld dependency The rdflib-jsonld dependency is currently not used in the project, therefore remove the dependency since 'python setup.py install' breaks on first install if both 'rdflib' and 'rdflib-jsonld' are in the requirements for some non-obvious reason. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a5e1ff11..5280b9b7 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ with open('README.rst') as f: description_text = f.read() -install_req = ["lxml", "pyyaml", "rdflib", "rdflib-jsonld"] +install_req = ["lxml", "pyyaml", "rdflib"] if sys.version_info < (3, 4): install_req += ["enum34"] From 9efe3f35378d2d23d43a30c18443b8106f6f4216 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Wed, 21 Feb 2018 18:59:18 +0100 Subject: [PATCH 02/22] [MANIFEST] Remove obsolete desktop entry --- MANIFEST.in | 1 - 1 file changed, 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 01e330b6..9d5d250d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,2 @@ include LICENSE include README.rst -include odml.desktop From a6175ef1bddf2275434e484967207c45333345b5 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Wed, 21 Feb 2018 19:16:45 +0100 Subject: [PATCH 03/22] [info.json] Add info file --- odml/info.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 odml/info.json diff --git a/odml/info.json b/odml/info.json new file mode 100644 index 00000000..8194bd0a --- /dev/null +++ b/odml/info.json @@ -0,0 +1,16 @@ +{ + "VERSION": "1.4.0", + "FORMAT_VERSION": "1.1", + "AUTHOR": "Hagen Fritsch, Christian Kellner, Jan Grewe, Achilleas Koutsou, Michael Sonntag, Lyuba Zehl", + "COPYRIGHT": "(c) 2011-2017, German Neuroinformatics Node", + "CONTACT": "dev@g-node.org", + "HOMEPAGE": "https://github.com/G-Node/python-odml", + "CLASSIFIERS": [ + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: BSD License", + "Development Status :: 5 - Production/Stable", + "Topic :: Scientific/Engineering", + "Intended Audience :: Science/Research" + ] +} From a1be88811bb0b3cb57b0c7791f2e31c43ccf02ac Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Wed, 21 Feb 2018 19:17:15 +0100 Subject: [PATCH 04/22] [info.py] Read information from info.json file --- odml/info.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/odml/info.py b/odml/info.py index 709e19fb..210d06b1 100644 --- a/odml/info.py +++ b/odml/info.py @@ -1,15 +1,15 @@ -VERSION = '1.4.0' -FORMAT_VERSION = '1.1' -AUTHOR = 'Hagen Fritsch, Christian Kellner, Jan Grewe, ' \ - 'Achilleas Koutsou, Michael Sonntag, Lyuba Zehl' -COPYRIGHT = '(c) 2011-2017, German Neuroinformatics Node' -CONTACT = 'dev@g-node.org' -HOMEPAGE = 'https://github.com/G-Node/python-odml' -CLASSIFIERS = [ - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 3', - 'License :: OSI Approved :: BSD License', - 'Development Status :: 5 - Production/Stable', - 'Topic :: Scientific/Engineering', - 'Intended Audience :: Science/Research' -] +import os +import json + +here = os.path.dirname(__file__) + +with open(os.path.join(here, "info.json")) as infofile: + infodict = json.load(infofile) + +VERSION = infodict["VERSION"] +FORMAT_VERSION = infodict["FORMAT_VERSION"] +AUTHOR = infodict["AUTHOR"] +COPYRIGHT = infodict["COPYRIGHT"] +CONTACT = infodict["CONTACT"] +HOMEPAGE = infodict["HOMEPAGE"] +CLASSIFIERS = infodict["CLASSIFIERS"] From 8b350b09c227cc3109347434e9d1e5b1f4a34d95 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Wed, 21 Feb 2018 19:17:37 +0100 Subject: [PATCH 05/22] [setup] Read project information from info.json --- setup.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/setup.py b/setup.py index 5280b9b7..d4f977cb 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +import json +import os import sys try: @@ -5,24 +7,17 @@ except ImportError as ex: from distutils.core import setup -try: - from odml.info import AUTHOR, CONTACT, CLASSIFIERS, HOMEPAGE, VERSION -except ImportError as ex: - # Read the information from odml.info.py if package dependencies - # are not yet available during a local install. - CLASSIFIERS = "" - with open('odml/info.py') as f: - for line in f: - curr_args = line.split(" = ") - if len(curr_args) == 2: - if curr_args[0] == "AUTHOR": - AUTHOR = curr_args[1].replace('\'', '').replace('\\', '').strip() - elif curr_args[0] == "CONTACT": - CONTACT = curr_args[1].replace('\'', '').strip() - elif curr_args[0] == "HOMEPAGE": - HOMEPAGE = curr_args[1].replace('\'', '').strip() - elif curr_args[0] == "VERSION": - VERSION = curr_args[1].replace('\'', '').strip() +with open(os.path.join("odml/info.json")) as infofile: + infodict = json.load(infofile) + +VERSION = infodict["VERSION"] +FORMAT_VERSION = infodict["FORMAT_VERSION"] +AUTHOR = infodict["AUTHOR"] +COPYRIGHT = infodict["COPYRIGHT"] +CONTACT = infodict["CONTACT"] +HOMEPAGE = infodict["HOMEPAGE"] +CLASSIFIERS = infodict["CLASSIFIERS"] + packages = [ 'odml', @@ -47,6 +42,7 @@ packages=packages, test_suite='test', install_requires=install_req, + include_package_data=True, long_description=description_text, classifiers=CLASSIFIERS, license="BSD" From 3ff8b2e65c1b0581c4e78ab31bf8038e3763ada3 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Wed, 21 Feb 2018 19:18:08 +0100 Subject: [PATCH 06/22] [MANIFEST] Export odml/info.json --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index 9d5d250d..00ee1263 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include LICENSE include README.rst +include odml/info.json From d510fc5c36f3161c1d63038ba44e8c9bd4ac76da Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Thu, 22 Feb 2018 16:17:03 +0100 Subject: [PATCH 07/22] [dtypes] Additional dtype bool check Closes #224 Disallow setting a value that cannot be interpreted as boolean for a boolean DType. --- odml/dtypes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odml/dtypes.py b/odml/dtypes.py index 36af0205..39d1e8df 100644 --- a/odml/dtypes.py +++ b/odml/dtypes.py @@ -204,8 +204,8 @@ def boolean_get(string): false = ["false", "0", False, "f"] if string in false: return False - return bool(string) - + # disallow any values that cannot be interpreted as boolean. + raise ValueError # Alias boolean_set to boolean_get. Both perform same function. From 84a8e13491725a819a380f1b99cb803d96550107 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Thu, 22 Feb 2018 16:28:53 +0100 Subject: [PATCH 08/22] [tests] Update changed boolean behavior tests --- test/test_property.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/test_property.py b/test/test_property.py index ba62e45e..debe542c 100644 --- a/test/test_property.py +++ b/test/test_property.py @@ -16,19 +16,36 @@ def test_value(self): def test_bool_conversion(self): - p = Property(name='received', value=[3, 0, 1, 0, 8]) + # Success tests + p = Property(name='received', value=[1, 0, 1, 0, 1]) assert(p.dtype == 'int') p.dtype = DType.boolean assert(p.dtype == 'boolean') assert(p.value == [True, False, True, False, True]) - q = Property(name='sent', - value=['False', True, 'TRUE', '0', 't', 'F', 'Ft']) + q = Property(name='sent', value=['False', True, 'TRUE', '0', 't', 'F', '1']) assert(q.dtype == 'string') q.dtype = DType.boolean assert(q.dtype == 'boolean') assert(q.value == [False, True, True, False, True, False, True]) + # Failure tests + curr_val = [3, 0, 1, 0, 8] + curr_type = 'int' + p = Property(name='received', value=curr_val) + assert(p.dtype == curr_type) + with self.assertRaises(ValueError): + p.dtype = DType.boolean + assert(p.dtype == curr_type) + assert(p.value == curr_val) + + curr_type = 'string' + q = Property(name='sent', value=['False', True, 'TRUE', '0', 't', '12', 'Ft']) + assert(q.dtype == curr_type) + with self.assertRaises(ValueError): + q.dtype = DType.boolean + assert(q.dtype == curr_type) + def test_str_to_int_convert(self): # Success Test From e8503aa8e60834c1a9dd939c5d3857df904540f7 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Thu, 22 Feb 2018 16:43:27 +0100 Subject: [PATCH 09/22] [tests] Add dtype boolean test --- test/test_dtypes.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_dtypes.py b/test/test_dtypes.py index 56d6bd30..6e90e5e4 100644 --- a/test/test_dtypes.py +++ b/test/test_dtypes.py @@ -45,6 +45,24 @@ def test_str(self): self.assertEqual(s.value[0], 'Jerin') self.assertEqual(s.dtype, 'string') + def test_bool(self): + self.assertEqual(None, typ.boolean_get(None)) + + true_values = [True, "TRUE", "true", "T", "t", "1", 1] + for val in true_values: + self.assertTrue(typ.boolean_get(val)) + + false_values = [False, "FALSE", "false", "F", "f", "0", 0] + for val in false_values: + self.assertFalse(typ.boolean_get(val)) + + with self.assertRaises(ValueError): + typ.boolean_get("text") + with self.assertRaises(ValueError): + typ.boolean_get(12) + with self.assertRaises(ValueError): + typ.boolean_get(2.1) + def test_tuple(self): # Success test t = odml.Property(name="Location", value='(39.12; 67.19)', dtype='2-tuple') From 2659eb93d45eac32eeb9923f3bbf5d18444ee58d Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Fri, 23 Feb 2018 13:01:16 +0100 Subject: [PATCH 10/22] [README] Update dependencies --- README.rst | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 86d5dd10..3ea6b4b4 100644 --- a/README.rst +++ b/README.rst @@ -21,13 +21,20 @@ Dependencies * enum (version 0.4.4) * lxml (version 3.7.2) + * yaml (version 3.12) + * rdflib (version >=4.2.2) -* These packages will be downloaded and installed automatically if the :code:`pip` method is used to install odML. Alternatively, they can be installed from the OS package manager. On Ubuntu, they are available as: +* These packages will be downloaded and installed automatically if the :code:`pip` + method is used to install odML. Alternatively, they can be installed from the OS + package manager. On Ubuntu, they are available as: * python-enum * python-lxml + * python-yaml + * python-rdflib -* If you prefer installing using the Python package manager, the following packages are required to build the lxml Python package on Ubuntu 14.04: +* If you prefer installing using the Python package manager, the following packages are + required to build the lxml Python package on Ubuntu 14.04: * libxml2-dev * libxslt1-dev @@ -43,7 +50,8 @@ The simplest way to install Python-odML is from PyPI using the pip tool:: On Ubuntu, the pip package manager is available in the repositories as :code:`python-pip`. -If this method is used, the appropriate Python dependencies (enum and lxml) are downloaded and installed automatically. +If this method is used, the appropriate Python dependencies are downloaded and installed +automatically. Building from source @@ -63,7 +71,8 @@ To install the Python-odML library, enter the corresponding directory and run:: $ cd python-odml $ python setup.py install -**Note** The master branch is our current development branch, not all features might be working as expected. Use the release tags instead. +**Note** The master branch is our current development branch, not all features might be +working as expected. Use the release tags instead. Documentation ------------- @@ -76,4 +85,6 @@ Bugs & Questions Should you find a behaviour that is likely a bug, please file a bug report at `the github bug tracker `_. -If you have questions regarding the use of the library or the editor, feel free to join the `#gnode `_ IRC channel on freenode. +If you have questions regarding the use of the library or the editor, feel free to +join the `#gnode `_ IRC channel +on freenode. From b3e3ffd5bb67f6a64a6e11a1cab05bc653f1dae2 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 16:52:44 +0100 Subject: [PATCH 11/22] [test] Add basic xml_parser testfile --- test/test_xml_parser.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/test_xml_parser.py diff --git a/test/test_xml_parser.py b/test/test_xml_parser.py new file mode 100644 index 00000000..3ba2c29a --- /dev/null +++ b/test/test_xml_parser.py @@ -0,0 +1,12 @@ +import unittest +import os +from odml.tools import xmlparser +from odml.tools.parser_utils import ParserException + + +class TestParser(unittest.TestCase): + + def setUp(self): + self.basepath = 'test/resources/' + + self.xml_reader = xmlparser.XMLReader() From 0702b295c5d88b0b5fecdf82ea1f58cae1bb7921 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 16:53:41 +0100 Subject: [PATCH 12/22] [test] Add basic xmlparser example files --- test/resources/invalid_root.xml | 5 +++++ test/resources/invalid_version.xml | 5 +++++ test/resources/missing_version.xml | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 test/resources/invalid_root.xml create mode 100644 test/resources/invalid_version.xml create mode 100644 test/resources/missing_version.xml diff --git a/test/resources/invalid_root.xml b/test/resources/invalid_root.xml new file mode 100644 index 00000000..4e53f342 --- /dev/null +++ b/test/resources/invalid_root.xml @@ -0,0 +1,5 @@ + + 2018-02-27 + 1.0 + Test author + \ No newline at end of file diff --git a/test/resources/invalid_version.xml b/test/resources/invalid_version.xml new file mode 100644 index 00000000..d9720c80 --- /dev/null +++ b/test/resources/invalid_version.xml @@ -0,0 +1,5 @@ + + 2018-02-27 + 1.0 + Test author + \ No newline at end of file diff --git a/test/resources/missing_version.xml b/test/resources/missing_version.xml new file mode 100644 index 00000000..181d1e89 --- /dev/null +++ b/test/resources/missing_version.xml @@ -0,0 +1,5 @@ + + 2018-02-27 + 1.0 + Test author + \ No newline at end of file From 25a836af7bb1d4c4af3ba0e747e9a51bba6776d4 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 16:53:57 +0100 Subject: [PATCH 13/22] [test] Add xmlparser main tag tests --- test/test_xml_parser.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/test_xml_parser.py b/test/test_xml_parser.py index 3ba2c29a..ca60d3a2 100644 --- a/test/test_xml_parser.py +++ b/test/test_xml_parser.py @@ -4,9 +4,27 @@ from odml.tools.parser_utils import ParserException -class TestParser(unittest.TestCase): +class TestXMLParser(unittest.TestCase): def setUp(self): self.basepath = 'test/resources/' self.xml_reader = xmlparser.XMLReader() + + def test_invalid_root(self): + filename = "invalid_root.xml" + + with self.assertRaises(ParserException): + _ = self.xml_reader.from_file(os.path.join(self.basepath, filename)) + + def test_missing_version(self): + filename = "missing_version.xml" + + with self.assertRaises(ParserException): + _ = self.xml_reader.from_file(os.path.join(self.basepath, filename)) + + def test_invalid_version(self): + filename = "invalid_version.xml" + + with self.assertRaises(ParserException): + _ = self.xml_reader.from_file(os.path.join(self.basepath, filename)) From a913fabdac3a4d3921803e52c892f7dac7a04244 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 17:07:34 +0100 Subject: [PATCH 14/22] [test] Add basic jsonparser testfile --- test/test_json_parser.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/test_json_parser.py diff --git a/test/test_json_parser.py b/test/test_json_parser.py new file mode 100644 index 00000000..502584db --- /dev/null +++ b/test/test_json_parser.py @@ -0,0 +1,12 @@ +import unittest +import os +from odml.tools import dict_parser +from odml.tools.parser_utils import ParserException + + +class TestJSONParser(unittest.TestCase): + + def setUp(self): + self.basepath = 'test/resources/' + + self.json_reader = dict_parser.DictReader() From 5b381a9187a68d924c5d97278ec1551b905a1adf Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 17:35:34 +0100 Subject: [PATCH 15/22] [tools/DictReader] Check for Document in file root --- odml/tools/dict_parser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/odml/tools/dict_parser.py b/odml/tools/dict_parser.py index eeaf4df8..47ea641c 100644 --- a/odml/tools/dict_parser.py +++ b/odml/tools/dict_parser.py @@ -114,7 +114,10 @@ def to_odml(self, parsed_doc): self.parsed_doc = parsed_doc # Parse only odML documents of supported format versions. - if 'odml-version' not in self.parsed_doc: + if 'Document' not in self.parsed_doc: + msg = "Missing root element 'Document'" + raise ParserException(msg) + elif 'odml-version' not in self.parsed_doc: raise ParserException("Invalid odML document: Could not find odml-version.") elif self.parsed_doc.get('odml-version') != FORMAT_VERSION: From 823bd769cdb41c6715aab7bc4ff2f5ca3a07fa63 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 17:36:26 +0100 Subject: [PATCH 16/22] [test] Add basic jsonparser example files --- test/resources/invalid_version.json | 9 +++++++++ test/resources/missing_root.json | 6 ++++++ test/resources/missing_version.json | 8 ++++++++ 3 files changed, 23 insertions(+) create mode 100644 test/resources/invalid_version.json create mode 100644 test/resources/missing_root.json create mode 100644 test/resources/missing_version.json diff --git a/test/resources/invalid_version.json b/test/resources/invalid_version.json new file mode 100644 index 00000000..b037933e --- /dev/null +++ b/test/resources/invalid_version.json @@ -0,0 +1,9 @@ +{ + "odml-version": "invalid", + "Document": { + "date": "2018-02-27", + "version": "1.0", + "sections": [], + "author": "Test author" + } +} \ No newline at end of file diff --git a/test/resources/missing_root.json b/test/resources/missing_root.json new file mode 100644 index 00000000..ef8a1af6 --- /dev/null +++ b/test/resources/missing_root.json @@ -0,0 +1,6 @@ +{ + "odml-version": "1.1", + "sometag": { + "Document": "somecontent" + } +} \ No newline at end of file diff --git a/test/resources/missing_version.json b/test/resources/missing_version.json new file mode 100644 index 00000000..ddeaf022 --- /dev/null +++ b/test/resources/missing_version.json @@ -0,0 +1,8 @@ +{ + "Document": { + "date": "2018-02-27", + "version": "1.0", + "sections": [], + "author": "Test author" + } +} \ No newline at end of file From 3a2aebaceb9991275e719f33351f6eac1451a062 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 17:36:58 +0100 Subject: [PATCH 17/22] [test] Add jsonparser main tag tests --- test/test_json_parser.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/test/test_json_parser.py b/test/test_json_parser.py index 502584db..999cd3fa 100644 --- a/test/test_json_parser.py +++ b/test/test_json_parser.py @@ -1,5 +1,7 @@ -import unittest +import json import os +import unittest + from odml.tools import dict_parser from odml.tools.parser_utils import ParserException @@ -10,3 +12,39 @@ def setUp(self): self.basepath = 'test/resources/' self.json_reader = dict_parser.DictReader() + + def test_missing_root(self): + filename = "missing_root.json" + message = "Missing root element" + + with open(os.path.join(self.basepath, filename)) as json_data: + parsed_doc = json.load(json_data) + + with self.assertRaises(ParserException) as exc: + _ = self.json_reader.to_odml(parsed_doc) + + self.assertIn(message, str(exc.exception)) + + def test_missing_version(self): + filename = "missing_version.json" + message = "Could not find odml-version" + + with open(os.path.join(self.basepath, filename)) as json_data: + parsed_doc = json.load(json_data) + + with self.assertRaises(ParserException) as exc: + _ = self.json_reader.to_odml(parsed_doc) + + self.assertIn(message, str(exc.exception)) + + def test_invalid_version(self): + filename = "invalid_version.json" + message = "invalid odML document format version" + + with open(os.path.join(self.basepath, filename)) as json_data: + parsed_doc = json.load(json_data) + + with self.assertRaises(ParserException) as exc: + _ = self.json_reader.to_odml(parsed_doc) + + self.assertIn(message, str(exc.exception)) From 13438e355120fdee01ef28c483db30ce9767cf05 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 17:40:21 +0100 Subject: [PATCH 18/22] [test] xmlparser: Distinguish ParserExceptions --- test/test_xml_parser.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/test_xml_parser.py b/test/test_xml_parser.py index ca60d3a2..fb557e16 100644 --- a/test/test_xml_parser.py +++ b/test/test_xml_parser.py @@ -1,5 +1,6 @@ -import unittest import os +import unittest + from odml.tools import xmlparser from odml.tools.parser_utils import ParserException @@ -13,18 +14,27 @@ def setUp(self): def test_invalid_root(self): filename = "invalid_root.xml" + message = "Expecting " - with self.assertRaises(ParserException): + with self.assertRaises(ParserException) as exc: _ = self.xml_reader.from_file(os.path.join(self.basepath, filename)) + self.assertIn(message, str(exc.exception)) + def test_missing_version(self): filename = "missing_version.xml" + message = "Could not find format version attribute" - with self.assertRaises(ParserException): + with self.assertRaises(ParserException) as exc: _ = self.xml_reader.from_file(os.path.join(self.basepath, filename)) + self.assertIn(message, str(exc.exception)) + def test_invalid_version(self): filename = "invalid_version.xml" + message = "invalid odML document format version" - with self.assertRaises(ParserException): + with self.assertRaises(ParserException) as exc: _ = self.xml_reader.from_file(os.path.join(self.basepath, filename)) + + self.assertIn(message, str(exc.exception)) From e9d61d4f4e09847c175581694b30873653a99f0b Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 17:44:09 +0100 Subject: [PATCH 19/22] [test] Add basic yamlparser testfile --- test/test_yaml_parser.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/test_yaml_parser.py diff --git a/test/test_yaml_parser.py b/test/test_yaml_parser.py new file mode 100644 index 00000000..9940d691 --- /dev/null +++ b/test/test_yaml_parser.py @@ -0,0 +1,14 @@ +import os +import unittest +import yaml + +from odml.tools import dict_parser +from odml.tools.parser_utils import ParserException + + +class TestYAMLParser(unittest.TestCase): + + def setUp(self): + self.basepath = 'test/resources/' + + self.yaml_reader = dict_parser.DictReader() From 48113e7104668fa9b1d170382a80297017a1c5fd Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 17:49:13 +0100 Subject: [PATCH 20/22] [test] Add basic yamlparser example files --- test/resources/invalid_version.yaml | 6 ++++++ test/resources/missing_root.yaml | 2 ++ test/resources/missing_version.yaml | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 test/resources/invalid_version.yaml create mode 100644 test/resources/missing_root.yaml create mode 100644 test/resources/missing_version.yaml diff --git a/test/resources/invalid_version.yaml b/test/resources/invalid_version.yaml new file mode 100644 index 00000000..362838be --- /dev/null +++ b/test/resources/invalid_version.yaml @@ -0,0 +1,6 @@ +Document: + author: Test author + date: '2018-02-27' + sections: [] + version: '1.0' +odml-version: 'totallyUnsupported' \ No newline at end of file diff --git a/test/resources/missing_root.yaml b/test/resources/missing_root.yaml new file mode 100644 index 00000000..5b069050 --- /dev/null +++ b/test/resources/missing_root.yaml @@ -0,0 +1,2 @@ +Root: + some: value diff --git a/test/resources/missing_version.yaml b/test/resources/missing_version.yaml new file mode 100644 index 00000000..6fc66ef2 --- /dev/null +++ b/test/resources/missing_version.yaml @@ -0,0 +1,5 @@ +Document: + author: Test author + date: '2018-02-27' + sections: [] + version: '1.0' From 9de14eb5f2b2a576325c38781ed04e7b8504df25 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Tue, 27 Feb 2018 17:49:31 +0100 Subject: [PATCH 21/22] [test] Add yamlparser main tag tests --- test/test_yaml_parser.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/test_yaml_parser.py b/test/test_yaml_parser.py index 9940d691..20dfc0b3 100644 --- a/test/test_yaml_parser.py +++ b/test/test_yaml_parser.py @@ -12,3 +12,39 @@ def setUp(self): self.basepath = 'test/resources/' self.yaml_reader = dict_parser.DictReader() + + def test_missing_root(self): + filename = "missing_root.yaml" + message = "Missing root element" + + with open(os.path.join(self.basepath, filename)) as raw_data: + parsed_doc = yaml.load(raw_data) + + with self.assertRaises(ParserException) as exc: + _ = self.yaml_reader.to_odml(parsed_doc) + + self.assertIn(message, str(exc.exception)) + + def test_missing_version(self): + filename = "missing_version.yaml" + message = "Could not find odml-version" + + with open(os.path.join(self.basepath, filename)) as raw_data: + parsed_doc = yaml.load(raw_data) + + with self.assertRaises(ParserException) as exc: + _ = self.yaml_reader.to_odml(parsed_doc) + + self.assertIn(message, str(exc.exception)) + + def test_invalid_version(self): + filename = "invalid_version.yaml" + message = "invalid odML document format version" + + with open(os.path.join(self.basepath, filename)) as raw_data: + parsed_doc = yaml.load(raw_data) + + with self.assertRaises(ParserException) as exc: + _ = self.yaml_reader.to_odml(parsed_doc) + + self.assertIn(message, str(exc.exception)) From 621181b92fabe87f048de7b43cb8f6ae5c9ef922 Mon Sep 17 00:00:00 2001 From: "M. Sonntag" Date: Wed, 28 Feb 2018 11:15:11 +0100 Subject: [PATCH 22/22] [setup] Properly use path.join reading info.json --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d4f977cb..6419bf28 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ except ImportError as ex: from distutils.core import setup -with open(os.path.join("odml/info.json")) as infofile: +with open(os.path.join("odml", "info.json")) as infofile: infodict = json.load(infofile) VERSION = infodict["VERSION"]