summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2013-02-15 16:41:30 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2013-02-18 11:24:01 +0000
commit8875864676a8d8b5fe08a861eb8662947f8fe115 (patch)
tree881efdd7532e7ad1b9a49845a46cc90594a5235e
parent76826aa85806243c778a78611fdd8a9239496396 (diff)
downloadmorph-8875864676a8d8b5fe08a861eb8662947f8fe115.tar.gz
Handle morphs that are not dicts (By failing)
-rw-r--r--morphlib/morph2.py2
-rw-r--r--morphlib/morph2_tests.py7
2 files changed, 6 insertions, 3 deletions
diff --git a/morphlib/morph2.py b/morphlib/morph2.py
index a32ecbb9..ae720cfb 100644
--- a/morphlib/morph2.py
+++ b/morphlib/morph2.py
@@ -77,6 +77,8 @@ class Morphology(object):
if data is None:
raise morphlib.YAMLError("Morphology is empty")
+ if type(data) not in [dict, OrderedDict]:
+ raise morphlib.YAMLError("Morphology did not parse as a dict")
self._set_defaults()
self._validate_children()
diff --git a/morphlib/morph2_tests.py b/morphlib/morph2_tests.py
index a2c44753..61e1744b 100644
--- a/morphlib/morph2_tests.py
+++ b/morphlib/morph2_tests.py
@@ -164,11 +164,12 @@ class MorphologyTests(unittest.TestCase):
## Validation tests
- def test_morphology_must_not_be_empty(self):
- # Causes crashes if not handled, because code expecting a dict gets
- # None instead.
+ def test_not_empty(self):
self.assertRaises(morphlib.YAMLError, Morphology, '')
+ def test_is_dict(self):
+ self.assertRaises(morphlib.YAMLError, Morphology, 'foo')
+
def test_makes_max_jobs_be_an_integer(self):
m = Morphology('''
{