diff options
-rw-r--r-- | morphlib/morph3.py | 12 | ||||
-rw-r--r-- | morphlib/morph3_tests.py | 36 |
2 files changed, 46 insertions, 2 deletions
diff --git a/morphlib/morph3.py b/morphlib/morph3.py index 477cac1a..a91ff390 100644 --- a/morphlib/morph3.py +++ b/morphlib/morph3.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,6 +18,8 @@ import UserDict +import morphlib + class Morphology(UserDict.IterableUserDict): @@ -43,3 +45,11 @@ class Morphology(UserDict.IterableUserDict): self.filename = None self.dirty = None + def get_commands(self, which): + '''Return the commands to run from a morphology or the build system''' + if self.get(which, None) is None: + attr = '_'.join(which.split('-')) + bs = morphlib.buildsystem.lookup_build_system(self['build-system']) + return getattr(bs, attr) + else: + return self[which] diff --git a/morphlib/morph3_tests.py b/morphlib/morph3_tests.py index e150bf33..51b70597 100644 --- a/morphlib/morph3_tests.py +++ b/morphlib/morph3_tests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -46,3 +46,37 @@ class MorphologyTests(unittest.TestCase): self.morph.dirty = True self.assertEqual(self.morph.dirty, True) + def test_uses_morphology_commands_when_given(self): + m = morphlib.morph3.Morphology( + { + 'name': 'foo', + 'kind': 'chunk', + 'build-system': 'dummy', + 'build-commands': ['build-it'] + } + ) + cmds = m.get_commands('build-commands') + self.assertEqual(cmds, ['build-it']) + + def test_uses_build_system_commands_when_morphology_doesnt(self): + m = morphlib.morph3.Morphology( + { + 'name': 'foo', + 'kind': 'chunk', + 'build-system': 'dummy', + } + ) + cmds = m.get_commands('build-commands') + self.assertEqual(cmds, ['echo dummy build']) + + def test_uses_morphology_commands_when_morphology_has_empty_list(self): + m = morphlib.morph3.Morphology( + { + 'name': 'foo', + 'kind': 'chunk', + 'build-system': 'dummy', + 'build-commands': [] + } + ) + cmds = m.get_commands('build-commands') + self.assertEqual(cmds, []) |