diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2014-02-17 15:01:24 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-02-17 15:25:57 +0000 |
commit | 22d3fe2832cf758b1efa75d2fdecf6e061fbdb0d (patch) | |
tree | c70cc7f3b0c5f9419c51f26e2f3175f80e75d6ae /morphlib/morphloader_tests.py | |
parent | a859a3377f488ef11ebed2631dbd51b2aa82afe4 (diff) | |
download | morph-22d3fe2832cf758b1efa75d2fdecf6e061fbdb0d.tar.gz |
morphloader: Dump dicts with a nicer key order
Diffstat (limited to 'morphlib/morphloader_tests.py')
-rw-r--r-- | morphlib/morphloader_tests.py | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py index b8738804..a050e10b 100644 --- a/morphlib/morphloader_tests.py +++ b/morphlib/morphloader_tests.py @@ -505,9 +505,9 @@ build-system: dummy # The following verifies that the YAML is written in a normalised # fashion. self.assertEqual(text, '''\ -build-system: dummy -kind: chunk name: foo +kind: chunk +build-system: dummy ''') def test_saves_to_file(self): @@ -524,9 +524,9 @@ name: foo # The following verifies that the YAML is written in a normalised # fashion. self.assertEqual(text, '''\ -build-system: dummy -kind: chunk name: foo +kind: chunk +build-system: dummy ''') def test_validate_does_not_set_defaults(self): @@ -862,3 +862,35 @@ name: foo self.assertEqual(warning.morphology_name, 'foo') self.assertEqual(warning.stratum_name, 'bar') self.assertEqual(warning.field, obsolete_field) + + def test_unordered_asciibetically_after_ordered(self): + # We only get morphologies with arbitrary keys in clusters + m = morphlib.morph3.Morphology( + name='foo', + kind='cluster', + systems=[ + { + 'morph': 'system-name', + 'repo': 'test:morphs', + 'ref': 'master', + 'deploy': { + 'deployment-foo': { + 'type': 'tarball', + 'location': '/tmp/path.tar', + 'HOSTNAME': 'aasdf', + } + } + } + ] + ) + s = self.loader.save_to_string(m) + # root field order + self.assertLess(s.find('name'), s.find('kind')) + self.assertLess(s.find('kind'), s.find('systems')) + # systems field order + self.assertLess(s.find('morph'), s.find('repo')) + self.assertLess(s.find('repo'), s.find('ref')) + self.assertLess(s.find('ref'), s.find('deploy')) + # deployment keys field order + self.assertLess(s.find('type'), s.find('location')) + self.assertLess(s.find('location'), s.find('HOSTNAME')) |