summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Waldon <bcwaldon@gmail.com>2012-06-01 15:00:38 -0700
committerBrian Waldon <bcwaldon@gmail.com>2012-06-01 15:00:38 -0700
commit96ef8b7a5faa6b8c744e658f33923cb571f50564 (patch)
treec4793b928e95febe24e5f279feef5a1ef47b8aa7
parent4160dc4e65dc4c5c8ba2f2245512586490072f60 (diff)
downloadwarlock-96ef8b7a5faa6b8c744e658f33923cb571f50564.tar.gz
Add basic test and implement minimal logic
-rw-r--r--.gitignore1
-rw-r--r--README.md6
-rw-r--r--setup.py9
-rw-r--r--test/test_core.py23
-rw-r--r--tox.ini6
-rw-r--r--warlock/__init__.py1
-rw-r--r--warlock/core.py21
7 files changed, 60 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 3949107..59ae20d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
build/
dist/
warlock.egg-info/
+.tox/
diff --git a/README.md b/README.md
index 760fd12..af36483 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/setup.py b/setup.py
index ce3df3a..f7cde72 100644
--- a/setup.py
+++ b/setup.py
@@ -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')
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..5b0b661
--- /dev/null
+++ b/tox.ini
@@ -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