diff options
author | Brian Waldon <bcwaldon@gmail.com> | 2012-06-01 15:00:38 -0700 |
---|---|---|
committer | Brian Waldon <bcwaldon@gmail.com> | 2012-06-01 15:00:38 -0700 |
commit | 96ef8b7a5faa6b8c744e658f33923cb571f50564 (patch) | |
tree | c4793b928e95febe24e5f279feef5a1ef47b8aa7 | |
parent | 4160dc4e65dc4c5c8ba2f2245512586490072f60 (diff) | |
download | warlock-96ef8b7a5faa6b8c744e658f33923cb571f50564.tar.gz |
Add basic test and implement minimal logic
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | setup.py | 9 | ||||
-rw-r--r-- | test/test_core.py | 23 | ||||
-rw-r--r-- | tox.ini | 6 | ||||
-rw-r--r-- | warlock/__init__.py | 1 | ||||
-rw-r--r-- | warlock/core.py | 21 |
7 files changed, 60 insertions, 7 deletions
@@ -2,3 +2,4 @@ build/ dist/ warlock.egg-info/ +.tox/ @@ -5,14 +5,14 @@ import warlock schema = { - 'name': 'Country': + 'name': 'Country', 'properties': { 'name': {'type': 'string'}, 'abbreviation': {'type': 'string'}, }, } - Country = warlock.schema_class(schema) + Country = warlock.Class(schema) 2) Create an object using your class @@ -23,5 +23,5 @@ sweden.name = 5 # Raises ValueError - sweden.overlord = 'Brian' + sweden.overlord = 'Bears' # Raises AttributeError @@ -2,10 +2,11 @@ import setuptools def parse_requirements(): - fap = open('requirements.txt', 'r') - raw_req = fap.read() - fap.close() - return raw_req.split('\n') +# fap = open('requirements.txt', 'r') +# raw_req = fap.read() +# fap.close() +# return raw_req.split('\n') + return ['jsonschema'] setuptools.setup( diff --git a/test/test_core.py b/test/test_core.py new file mode 100644 index 0000000..a59778c --- /dev/null +++ b/test/test_core.py @@ -0,0 +1,23 @@ +import unittest + +import warlock + + +class TestCore(unittest.TestCase): + def test_core(self): + schema = { + 'name': 'Country', + 'properties': { + 'name': {'type': 'string'}, + 'abbreviation': {'type': 'string'}, + }, + } + + Country = warlock.Class(schema) + + sweden = Country(name='Sweden', abbreviation='SE') + + self.assertEqual(sweden.name, 'Sweden') + self.assertEqual(sweden.abbreviation, 'SE') + self.assertRaises(AttributeError, getattr, sweden, 'overlord') + self.assertRaises(AttributeError, setattr, sweden, 'overlord', 'Bears') @@ -0,0 +1,6 @@ +[tox] +envlist = py27 + +[testenv] +deps=pytest +commands=py.test diff --git a/warlock/__init__.py b/warlock/__init__.py index e69de29..2bdde37 100644 --- a/warlock/__init__.py +++ b/warlock/__init__.py @@ -0,0 +1 @@ +from core import Class diff --git a/warlock/core.py b/warlock/core.py new file mode 100644 index 0000000..741d137 --- /dev/null +++ b/warlock/core.py @@ -0,0 +1,21 @@ +#import jsonschema + + +def Class(schema): + class schema_class(object): + def __init__(self, **kwargs): + self.__dict__['raw'] = kwargs + + def __getattr__(self, key): + try: + return self.__dict__['raw'][key] + except KeyError: + raise AttributeError(key) + + def __setattr__(self, key, value): + if key in self.__dict__['raw']: + self.__dict__['raw'][key] = value + else: + raise AttributeError(key) + + return schema_class |