summaryrefslogtreecommitdiff
path: root/morphlib/morphloader_tests.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-08-29 11:25:36 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-08-30 10:34:53 +0000
commitb0096f15bb3624207b1df71b22070b4780b03658 (patch)
treeffcf474dd043d404b0a9e791c7a8cd69f6fb5e1e /morphlib/morphloader_tests.py
parent4ee24ddb0c89723a3e6c1c15ccdea9c8d454d084 (diff)
downloadmorph-b0096f15bb3624207b1df71b22070b4780b03658.tar.gz
morphloader: Add method to unset default values
The original contents of the morphology is not generally trackable, comments are lost for example, and it's simpler to output a canonical format than attempt to preserve everything of the original. However, we don't want to clutter the output with fields that have been filled out to be the defaults, so provide a method to remove fields that are the same as their default. This also removes a check in set_defaults that it is a valid kind, since it explicitly declares it assumes the morphology is valid.
Diffstat (limited to 'morphlib/morphloader_tests.py')
-rw-r--r--morphlib/morphloader_tests.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py
index 6e957510..ac0fef53 100644
--- a/morphlib/morphloader_tests.py
+++ b/morphlib/morphloader_tests.py
@@ -385,6 +385,20 @@ name: foo
'max-jobs': None,
})
+ def test_unsets_defaults_for_chunks(self):
+ m = morphlib.morph3.Morphology({
+ 'kind': 'chunk',
+ 'name': 'foo',
+ 'build-system': 'manual',
+ })
+ self.loader.unset_defaults(m)
+ self.assertEqual(
+ dict(m),
+ {
+ 'kind': 'chunk',
+ 'name': 'foo',
+ })
+
def test_sets_defaults_for_strata(self):
m = morphlib.morph3.Morphology({
'kind': 'stratum',
@@ -421,6 +435,27 @@ name: foo
],
})
+ def test_unsets_defaults_for_strata(self):
+ test_dict = {
+ 'kind': 'stratum',
+ 'name': 'foo',
+ 'chunks': [
+ {
+ 'name': 'bar',
+ "ref": "bar",
+ 'build-mode': 'bootstrap',
+ 'build-depends': [],
+ },
+ ],
+ }
+ test_dict_with_build_depends = dict(test_dict)
+ test_dict_with_build_depends["build-depends"] = []
+ m = morphlib.morph3.Morphology(test_dict_with_build_depends)
+ self.loader.unset_defaults(m)
+ self.assertEqual(
+ dict(m),
+ test_dict)
+
def test_sets_defaults_for_system(self):
m = morphlib.morph3.Morphology({
'kind': 'system',
@@ -442,6 +477,22 @@ name: foo
'disk-size': '1G',
})
+ def test_unsets_defaults_for_system(self):
+ m = morphlib.morph3.Morphology({
+ 'kind': 'system',
+ 'name': 'foo',
+ 'arch': 'x86_64',
+ 'strata': [],
+ })
+ self.loader.unset_defaults(m)
+ self.assertEqual(
+ dict(m),
+ {
+ 'kind': 'system',
+ 'name': 'foo',
+ 'arch': 'x86_64',
+ })
+
def test_sets_stratum_chunks_repo_and_morph_from_name(self):
m = morphlib.morph3.Morphology(
{
@@ -461,6 +512,26 @@ name: foo
self.assertEqual(m['chunks'][0]['repo'], 'le-chunk')
self.assertEqual(m['chunks'][0]['morph'], 'le-chunk')
+ def test_collapses_stratum_chunks_repo_and_morph_from_name(self):
+ m = morphlib.morph3.Morphology(
+ {
+ "name": "foo",
+ "kind": "stratum",
+ "chunks": [
+ {
+ "name": "le-chunk",
+ "repo": "le-chunk",
+ "morph": "le-chunk",
+ "ref": "ref",
+ "build-depends": [],
+ }
+ ]
+ })
+
+ self.loader.unset_defaults(m)
+ self.assertTrue('repo' not in m['chunks'][0])
+ self.assertTrue('morph' not in m['chunks'][0])
+
def test_convertes_max_jobs_to_an_integer(self):
m = morphlib.morph3.Morphology(
{