Skip to content

Commit

Permalink
More tests. I <3 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
azaroth42 committed Dec 20, 2016
1 parent b38e1b9 commit d5578d2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions README
2 changes: 2 additions & 0 deletions cromulent/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ def __setattr__(self, which, value):
ok = self._check_prop(which, value)
if not ok:
raise DataError("Can't set non-standard field '%s' on resource of type '%s'" % (which, self._type))
else:
ok = 1

# Allow per class setter functions to do extra magic
if hasattr(self, which) and hasattr(self, 'set_%s' % which):
Expand Down
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[wheel]
universal = 1

[check-manifest]
ignore =
.travis.yml
tox.ini
.gitignore

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2",
"License :: OSI Approved :: Apache License",
"Development Status :: pre-Alpha",
"License :: OSI Approved :: Apache Software License",
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand Down
18 changes: 18 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def test_toFile(self):
self.assertTrue(os.path.isfile('tests/InformationObject/collection.json'))
shutil.rmtree('tests/InformationObject')



class TestProcessTSV(unittest.TestCase):

def test_process_tsv(self):
Expand Down Expand Up @@ -199,6 +201,22 @@ def test_set_magic_resource_inverse(self):
artist._set_magic_resource('parent_of', son)
self.assertEqual(son.parent, artist)

def test_validation_unknown(self):
model.factory.validate_properties = True
artist = model.Person('00001', 'Jane Doe')
self.assertRaises(model.DataError, artist.__setattr__, 'unknown_property', 1)

def test_validation_wrong_type(self):
model.factory.validate_properties = True
artist = model.Person('00001', 'Jane Doe')
self.assertRaises(model.DataError, artist.__setattr__, 'parent_of', 'Bad Value')

def test_validation_off(self):
model.factory.validate_properties = False
artist = model.Person('00001', 'Jane Doe')
artist.unknown_property = 1
self.assertEqual(artist.unknown_property, 1)


if __name__ == '__main__':
unittest.main()

0 comments on commit d5578d2

Please sign in to comment.