diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-07-28 15:23:09 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-10-14 14:34:29 +0000 |
commit | b8b8de2b123ff96e6469196934359485bcd06b04 (patch) | |
tree | 2bb774dcaf3db88d6dafb8ab34322b5df4550ce0 /morphlib/morphloader_tests.py | |
parent | 3c59628c80ffe47992bf7347268ca587fc6d368d (diff) | |
download | morph-b8b8de2b123ff96e6469196934359485bcd06b04.tar.gz |
Add support for Baserock definitions version 7
This adds a new 'Defaults' class to represent definitions defaults
The Python 'jsonschema' module is used to validate the contents of the
Defaults file. This module is already included in Baserock 'build' and
'devel' reference systems by way of the 'openstack-common' stratum.
This commit embeds a copy of the JSON-Schema schema for the DEFAULTS
file. I think the canonical location of this schema should be in the
reference definitions.git, for now. In future, the schemas should maybe
have their own repos. Either way, Morph should embed a copy for the time
being so that we are sure the schema matches how Morph expects to parse
the file.
Morph's automated tests are all updated to use definitions version 7.
I removed most of the tests for built-in build systems, because the
built-ins themselves are no longer part of Morph. Only the mechanism for
defining them needs to be tested now.
Change-Id: I65f8f1c967683ef605852bfae5c68518e53f9981
Diffstat (limited to 'morphlib/morphloader_tests.py')
-rw-r--r-- | morphlib/morphloader_tests.py | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py index 6117573e..392b0cbc 100644 --- a/morphlib/morphloader_tests.py +++ b/morphlib/morphloader_tests.py @@ -60,12 +60,12 @@ class MorphologyLoaderTests(unittest.TestCase): string = '''\ name: foo kind: chunk -build-system: dummy +build-system: manual ''' morph = self.loader.parse_morphology_text(string, 'test') self.assertEqual(morph['kind'], 'chunk') self.assertEqual(morph['name'], 'foo') - self.assertEqual(morph['build-system'], 'dummy') + self.assertEqual(morph['build-system'], 'manual') def test_fails_to_parse_utter_garbage(self): self.assertRaises( @@ -494,43 +494,43 @@ chunks: string = '''\ name: foo kind: chunk -build-system: dummy +build-system: manual ''' morph = self.loader.load_from_string(string) self.assertEqual(morph['kind'], 'chunk') self.assertEqual(morph['name'], 'foo') - self.assertEqual(morph['build-system'], 'dummy') + self.assertEqual(morph['build-system'], 'manual') def test_loads_json_from_string(self): string = '''\ { "name": "foo", "kind": "chunk", - "build-system": "dummy" + "build-system": "manual" } ''' morph = self.loader.load_from_string(string) self.assertEqual(morph['kind'], 'chunk') self.assertEqual(morph['name'], 'foo') - self.assertEqual(morph['build-system'], 'dummy') + self.assertEqual(morph['build-system'], 'manual') def test_loads_from_file(self): with open(self.filename, 'w') as f: f.write('''\ name: foo kind: chunk -build-system: dummy +build-system: manual ''') morph = self.loader.load_from_file(self.filename) self.assertEqual(morph['kind'], 'chunk') self.assertEqual(morph['name'], 'foo') - self.assertEqual(morph['build-system'], 'dummy') + self.assertEqual(morph['build-system'], 'manual') def test_saves_to_string(self): morph = morphlib.morphology.Morphology({ 'name': 'foo', 'kind': 'chunk', - 'build-system': 'dummy', + 'build-system': 'manual', }) text = self.loader.save_to_string(morph) @@ -539,14 +539,14 @@ build-system: dummy self.assertEqual(text, '''\ name: foo kind: chunk -build-system: dummy +build-system: manual ''') def test_saves_to_file(self): morph = morphlib.morphology.Morphology({ 'name': 'foo', 'kind': 'chunk', - 'build-system': 'dummy', + 'build-system': 'manual', }) self.loader.save_to_file(self.filename, morph) @@ -558,7 +558,7 @@ build-system: dummy self.assertEqual(text, '''\ name: foo kind: chunk -build-system: dummy +build-system: manual ''') def test_validate_does_not_set_defaults(self): @@ -966,11 +966,12 @@ build-system: dummy ) s = self.loader.save_to_string(m) - def test_smoketest_strip_commands(self): - dummy_buildsystem = morphlib.buildsystem.DummyBuildSystem() - loader = morphlib.morphloader.MorphologyLoader( - lookup_build_system=lambda x: dummy_buildsystem) - m = morphlib.morphology.Morphology( - {'name': 'test', 'kind': 'chunk', 'build-system': 'dummy'}) - loader.set_commands(m) - self.assertEqual(m['strip-commands'], dummy_buildsystem.strip_commands) + + def test_unknown_build_system(self): + m = morphlib.morphology.Morphology({ + 'kind': 'chunk', + 'name': 'foo', + 'build-system': 'monkey scientist', + }) + with self.assertRaises(morphlib.morphloader.UnknownBuildSystemError): + s = self.loader.set_commands(m) |