diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-09-10 11:09:51 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-09-10 20:04:06 +0100 |
commit | a12cbe6e106c9f62e08a89a3c012a3f3d4a48e9d (patch) | |
tree | 0315b2f2b1835886030922671c5712f3c6ddd866 /morphlib/morph2_tests.py | |
parent | 02f4c93a143b7121c5bd84ec2e20c665149db4c8 (diff) | |
download | morph-a12cbe6e106c9f62e08a89a3c012a3f3d4a48e9d.tar.gz |
Preserve sort order of morphologies, so they can be edited by Morph
Diffstat (limited to 'morphlib/morph2_tests.py')
-rw-r--r-- | morphlib/morph2_tests.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/morphlib/morph2_tests.py b/morphlib/morph2_tests.py index 60917537..142b5949 100644 --- a/morphlib/morph2_tests.py +++ b/morphlib/morph2_tests.py @@ -14,6 +14,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import StringIO import unittest from morphlib.morph2 import Morphology @@ -197,3 +198,78 @@ class MorphologyTests(unittest.TestCase): self.assertRaises(ValueError, Morphology, text) + + def test_writing_preserves_field_order(self): + text = '''{ + "kind": "system", + "disk-size": 1073741824, + "description": "Some text", + "arch": "x86_64", + "system-kind": "syslinux-disk", + "strata": [ + { + "morph": "foundation", + "repo": "morphs", + "ref": "ref" + }, + { + "morph": "devel", + "repo": "morphs", + "ref": "ref" + } + ] +}''' + morphology = Morphology(text) + output = StringIO.StringIO() + morphology.write_to_file(output) + + text_lines = text.splitlines() + output_lines = output.getvalue().splitlines() + + # Verify that input and output are equal. + self.assertEqual(text_lines, output_lines) + + def test_writing_stratum_morphology_preserves_chunk_order(self): + text = '''{ + "kind": "stratum", + "chunks": [ + { + "name": "foo", + "repo": "morphs", + "ref": "ref", + "build-depends": [] + }, + { + "name": "bar", + "repo": "morphs", + "ref": "ref", + "build-depends": [] + } + ] +}''' + morphology = Morphology(text) + output = StringIO.StringIO() + morphology.write_to_file(output) + + text_lines = text.splitlines() + output_lines = output.getvalue().splitlines() + + # Verify that input and output are equal. + self.assertEqual(text_lines, output_lines) + + def test_writing_preserves_disk_size(self): + text = '''{ + "kind": "system", + "disk-size": "1g", + "arch": "x86_64", + "system-kind": "syslinux-disk" +}''' + morphology = Morphology(text) + output = StringIO.StringIO() + morphology.write_to_file(output) + + text_lines = text.splitlines() + output_lines = output.getvalue().splitlines() + + # Verify that in- and output are the same. + self.assertEqual(text_lines, output_lines) |