diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-09-04 15:52:07 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-09-04 16:59:09 +0100 |
commit | 99e80f647f9ef1c17da203342d932fb5ffc440ee (patch) | |
tree | bb8cb9a6b377653193d0ea45b9224a5c49c3814b /morphlib/morph2_tests.py | |
parent | a0ba0157c77bc3230f9de2b58d3a3fb40db0ab76 (diff) | |
download | morph-99e80f647f9ef1c17da203342d932fb5ffc440ee.tar.gz |
Rework morphology child lookup to be more useful for branch/merge
In order to modify morphologies in place and then write them back to
disk in system branches (e.g. when running "morph edit"), we need to
have access to the dicts that store references to strata in system
morphologies and chunks in stratum morphologies, respectively.
Therefor, the previous triplet-returning child lookup is replaced
with a new internal method to ensure uniqueness of names in
morphologies and a new method to lookup children in this commit.
The unit tests are adjusted to cover everything in appropriate ways.
Diffstat (limited to 'morphlib/morph2_tests.py')
-rw-r--r-- | morphlib/morph2_tests.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/morphlib/morph2_tests.py b/morphlib/morph2_tests.py index afa55769..60917537 100644 --- a/morphlib/morph2_tests.py +++ b/morphlib/morph2_tests.py @@ -101,10 +101,11 @@ class MorphologyTests(unittest.TestCase): ] } ''') - self.assertEqual(m.lookup_morphology_by_name("stratum1"), - ("repo", "ref", "stratum1.morph")) - self.assertEqual(m.lookup_morphology_by_name("aliased-stratum"), - ("repo", "ref", "stratum2.morph")) + self.assertEqual(m.lookup_child_by_name('stratum1'), + {'morph': 'stratum1', 'repo': 'repo', 'ref': 'ref' }) + self.assertEqual(m.lookup_child_by_name('aliased-stratum'), + {'alias': 'aliased-stratum', 'morph': 'stratum2', + 'repo': 'repo', 'ref': 'ref'}) def test_stratum_indexes_chunks(self): m = Morphology(''' @@ -119,8 +120,27 @@ class MorphologyTests(unittest.TestCase): ] } ''') - self.assertEqual(m.lookup_morphology_by_name("chunk"), - ("repo", "ref", "chunk.morph")) + + child = m.lookup_child_by_name('chunk') + self.assertEqual(child['name'], 'chunk') + self.assertEqual(child['repo'], 'repo') + self.assertEqual(child['ref'], 'ref') + + def test_raises_error_when_child_lookup_fails(self): + m = Morphology(''' + { + "kind": "stratum", + "chunks": [ + { + "name": "chunk", + "repo": "repo", + "ref": "ref" + } + ] + } + ''') + + self.assertRaises(KeyError, m.lookup_child_by_name, 'foo') ## Validation tests |