Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ad97349
[setup.py] Remove rdflib-jsonld dependency
mpsonntag Feb 21, 2018
9efe3f3
[MANIFEST] Remove obsolete desktop entry
mpsonntag Feb 21, 2018
a6175ef
[info.json] Add info file
mpsonntag Feb 21, 2018
a1be888
[info.py] Read information from info.json file
mpsonntag Feb 21, 2018
8b350b0
[setup] Read project information from info.json
mpsonntag Feb 21, 2018
3ff8b2e
[MANIFEST] Export odml/info.json
mpsonntag Feb 21, 2018
d510fc5
[dtypes] Additional dtype bool check
mpsonntag Feb 22, 2018
84a8e13
[tests] Update changed boolean behavior tests
mpsonntag Feb 22, 2018
e8503aa
[tests] Add dtype boolean test
mpsonntag Feb 22, 2018
2659eb9
[README] Update dependencies
mpsonntag Feb 23, 2018
b3e3ffd
[test] Add basic xml_parser testfile
mpsonntag Feb 27, 2018
0702b29
[test] Add basic xmlparser example files
mpsonntag Feb 27, 2018
25a836a
[test] Add xmlparser main tag tests
mpsonntag Feb 27, 2018
a913fab
[test] Add basic jsonparser testfile
mpsonntag Feb 27, 2018
5b381a9
[tools/DictReader] Check for Document in file root
mpsonntag Feb 27, 2018
823bd76
[test] Add basic jsonparser example files
mpsonntag Feb 27, 2018
3a2aeba
[test] Add jsonparser main tag tests
mpsonntag Feb 27, 2018
13438e3
[test] xmlparser: Distinguish ParserExceptions
mpsonntag Feb 27, 2018
e9d61d4
[test] Add basic yamlparser testfile
mpsonntag Feb 27, 2018
48113e7
[test] Add basic yamlparser example files
mpsonntag Feb 27, 2018
9de14eb
[test] Add yamlparser main tag tests
mpsonntag Feb 27, 2018
621181b
[setup] Properly use path.join reading info.json
mpsonntag Feb 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include LICENSE
include README.rst
include odml.desktop
include odml/info.json
21 changes: 16 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
-------------
Expand All @@ -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 <https://github.com/G-Node/python-odml/issues>`_.

If you have questions regarding the use of the library or the editor, feel free to join the `#gnode <http://webchat.freenode.net?channels=%23gnode>`_ IRC channel on freenode.
If you have questions regarding the use of the library or the editor, feel free to
join the `#gnode <http://webchat.freenode.net?channels=%23gnode>`_ IRC channel
on freenode.
4 changes: 2 additions & 2 deletions odml/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 16 additions & 0 deletions odml/info.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
30 changes: 15 additions & 15 deletions odml/info.py
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 4 additions & 1 deletion odml/tools/dict_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 15 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import json
import os
import sys

try:
from setuptools import setup
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',
Expand All @@ -32,7 +27,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"]
Expand All @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions test/resources/invalid_root.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<invalid>
<date>2018-02-27</date>
<version>1.0</version>
<author>Test author</author>
</invalid>
9 changes: 9 additions & 0 deletions test/resources/invalid_version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"odml-version": "invalid",
"Document": {
"date": "2018-02-27",
"version": "1.0",
"sections": [],
"author": "Test author"
}
}
5 changes: 5 additions & 0 deletions test/resources/invalid_version.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<odML version="invalid">
<date>2018-02-27</date>
<version>1.0</version>
<author>Test author</author>
</odML>
6 changes: 6 additions & 0 deletions test/resources/invalid_version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Document:
author: Test author
date: '2018-02-27'
sections: []
version: '1.0'
odml-version: 'totallyUnsupported'
6 changes: 6 additions & 0 deletions test/resources/missing_root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"odml-version": "1.1",
"sometag": {
"Document": "somecontent"
}
}
2 changes: 2 additions & 0 deletions test/resources/missing_root.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Root:
some: value
8 changes: 8 additions & 0 deletions test/resources/missing_version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Document": {
"date": "2018-02-27",
"version": "1.0",
"sections": [],
"author": "Test author"
}
}
5 changes: 5 additions & 0 deletions test/resources/missing_version.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<odML>
<date>2018-02-27</date>
<version>1.0</version>
<author>Test author</author>
</odML>
5 changes: 5 additions & 0 deletions test/resources/missing_version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Document:
author: Test author
date: '2018-02-27'
sections: []
version: '1.0'
18 changes: 18 additions & 0 deletions test/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
50 changes: 50 additions & 0 deletions test/test_json_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import json
import os
import unittest

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()

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))
23 changes: 20 additions & 3 deletions test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading