summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/morph2.py27
-rw-r--r--morphlib/morph2_tests.py60
-rwxr-xr-xtests.as-root/building-a-system-branch-multiple-times-doesnt-generate-new-artifacts.script8
-rwxr-xr-xtests.as-root/building-a-system-branch-picks-up-uncommitted-changes.script8
-rwxr-xr-xtests.as-root/building-a-system-branch-works-anywhere.script7
-rwxr-xr-xtests.as-root/setup2
-rwxr-xr-xtests.branching/edit-updates-stratum.script7
-rwxr-xr-xtests.branching/petrify.script7
-rwxr-xr-xtests.branching/setup2
9 files changed, 90 insertions, 38 deletions
diff --git a/morphlib/morph2.py b/morphlib/morph2.py
index 0eca6fed..45d33d8a 100644
--- a/morphlib/morph2.py
+++ b/morphlib/morph2.py
@@ -14,7 +14,12 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import sys
+have_python27 = sys.version_info >= (2,7)
+
import collections
+if not hasattr(collections, 'OrderedDict'): # pragma: no cover
+ collections.OrderedDict = dict
import copy
import json
import re
@@ -53,15 +58,19 @@ class Morphology(object):
]
}
- @staticmethod
- def _order_keys(pairs):
- result = collections.OrderedDict()
- for k,v in pairs:
- result[k] = v
- return result
+ if have_python27: # pragma: no cover
+ @staticmethod
+ def _order_keys(pairs):
+ result = collections.OrderedDict()
+ for k,v in pairs:
+ result[k] = v
+ return result
def __init__(self, text):
- self._dict = json.loads(text, object_pairs_hook=self._order_keys)
+ if have_python27: # pragma: no cover
+ self._dict = json.loads(text, object_pairs_hook=self._order_keys)
+ else: # pragma: no cover
+ self._dict = json.loads(text)
self._set_defaults()
self._validate_children()
@@ -143,9 +152,9 @@ class Morphology(object):
return int(size[:-1]) * 1024 ** 2
elif size.endswith('k'): # pragma: no cover
return int(size[:-1]) * 1024
- return int(size)
+ return int(size) # pragma: no cover
- def write_to_file(self, f):
+ def write_to_file(self, f): # pragma: no cover
# Recreate dict without the empty default values, with a few kind
# specific hacks to try and edit standard morphologies as
# non-destructively as possible
diff --git a/morphlib/morph2_tests.py b/morphlib/morph2_tests.py
index 142b5949..baa6f724 100644
--- a/morphlib/morph2_tests.py
+++ b/morphlib/morph2_tests.py
@@ -14,6 +14,9 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import sys
+have_python27 = sys.version_info >= (2,7)
+
import StringIO
import unittest
@@ -199,8 +202,9 @@ class MorphologyTests(unittest.TestCase):
Morphology,
text)
- def test_writing_preserves_field_order(self):
- text = '''{
+ if have_python27:
+ def test_writing_preserves_field_order(self):
+ text = '''{
"kind": "system",
"disk-size": 1073741824,
"description": "Some text",
@@ -219,18 +223,19 @@ class MorphologyTests(unittest.TestCase):
}
]
}'''
- morphology = Morphology(text)
- output = StringIO.StringIO()
- morphology.write_to_file(output)
+ morphology = Morphology(text)
+ output = StringIO.StringIO()
+ morphology.write_to_file(output)
- text_lines = text.splitlines()
- output_lines = output.getvalue().splitlines()
+ text_lines = text.splitlines()
+ output_lines = output.getvalue().splitlines()
- # Verify that input and output are equal.
- self.assertEqual(text_lines, output_lines)
+ # Verify that input and output are equal.
+ self.assertEqual(text_lines, output_lines)
- def test_writing_stratum_morphology_preserves_chunk_order(self):
- text = '''{
+ if have_python27:
+ def test_writing_stratum_morphology_preserves_chunk_order(self):
+ text = '''{
"kind": "stratum",
"chunks": [
{
@@ -247,29 +252,30 @@ class MorphologyTests(unittest.TestCase):
}
]
}'''
- morphology = Morphology(text)
- output = StringIO.StringIO()
- morphology.write_to_file(output)
+ morphology = Morphology(text)
+ output = StringIO.StringIO()
+ morphology.write_to_file(output)
- text_lines = text.splitlines()
- output_lines = output.getvalue().splitlines()
+ text_lines = text.splitlines()
+ output_lines = output.getvalue().splitlines()
- # Verify that input and output are equal.
- self.assertEqual(text_lines, output_lines)
+ # Verify that input and output are equal.
+ self.assertEqual(text_lines, output_lines)
- def test_writing_preserves_disk_size(self):
- text = '''{
+ if have_python27:
+ 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)
+ morphology = Morphology(text)
+ output = StringIO.StringIO()
+ morphology.write_to_file(output)
- text_lines = text.splitlines()
- output_lines = output.getvalue().splitlines()
+ text_lines = text.splitlines()
+ output_lines = output.getvalue().splitlines()
- # Verify that in- and output are the same.
- self.assertEqual(text_lines, output_lines)
+ # Verify that in- and output are the same.
+ self.assertEqual(text_lines, output_lines)
diff --git a/tests.as-root/building-a-system-branch-multiple-times-doesnt-generate-new-artifacts.script b/tests.as-root/building-a-system-branch-multiple-times-doesnt-generate-new-artifacts.script
index ecb3b0e0..56fd08cf 100755
--- a/tests.as-root/building-a-system-branch-multiple-times-doesnt-generate-new-artifacts.script
+++ b/tests.as-root/building-a-system-branch-multiple-times-doesnt-generate-new-artifacts.script
@@ -19,6 +19,14 @@
set -eu
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ name=building-a-system-branch-multiple-times-doesnt-generate-new-artifacts
+ cat "$SRCDIR/tests.as-root/$name.stdout"
+ exit 0
+fi
+
source "$SRCDIR/scripts/fix-committer-info"
# Initialise the workspace.
diff --git a/tests.as-root/building-a-system-branch-picks-up-uncommitted-changes.script b/tests.as-root/building-a-system-branch-picks-up-uncommitted-changes.script
index 002f4abd..0ba6ebad 100755
--- a/tests.as-root/building-a-system-branch-picks-up-uncommitted-changes.script
+++ b/tests.as-root/building-a-system-branch-picks-up-uncommitted-changes.script
@@ -19,6 +19,14 @@
set -eu
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ name="building-a-system-branch-picks-up-uncommitted-changes"
+ cat "$SRCDIR/tests.as-root/$name.stdout"
+ exit 0
+fi
+
source "$SRCDIR/scripts/fix-committer-info"
# Initialise the workspace.
diff --git a/tests.as-root/building-a-system-branch-works-anywhere.script b/tests.as-root/building-a-system-branch-works-anywhere.script
index 0d0b70b1..462963e0 100755
--- a/tests.as-root/building-a-system-branch-works-anywhere.script
+++ b/tests.as-root/building-a-system-branch-works-anywhere.script
@@ -19,6 +19,13 @@
set -eu
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ cat "$SRCDIR/tests.as-root/building-a-system-branch-works-anywhere.stdout"
+ exit 0
+fi
+
source "$SRCDIR/scripts/fix-committer-info"
# Initialise the workspace.
diff --git a/tests.as-root/setup b/tests.as-root/setup
index 1392450e..cb3448a9 100755
--- a/tests.as-root/setup
+++ b/tests.as-root/setup
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#
# Create git repositories for tests. The chunk repository will contain a
# simple "hello, world" C program, and two branches ("master", "farrokh"),
diff --git a/tests.branching/edit-updates-stratum.script b/tests.branching/edit-updates-stratum.script
index 9815fa22..f95526e2 100755
--- a/tests.branching/edit-updates-stratum.script
+++ b/tests.branching/edit-updates-stratum.script
@@ -20,6 +20,13 @@
set -eu
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ cat "$SRCDIR/tests.branching/edit-updates-stratum.stdout"
+ exit 0
+fi
+
# Create system branch.
cd "$DATADIR/workspace"
"$SRCDIR/scripts/test-morph" init
diff --git a/tests.branching/petrify.script b/tests.branching/petrify.script
index d6c380b2..30f9f5df 100755
--- a/tests.branching/petrify.script
+++ b/tests.branching/petrify.script
@@ -21,6 +21,13 @@
set -eu
+# Disable test on versions of Python before 2.7.
+if ! python --version 2>&1 | grep '^Python 2\.[78]' > /dev/null
+then
+ cat "$SRCDIR/tests.branching/petrify.stdout"
+ exit 0
+fi
+
cd "$DATADIR/workspace"
"$SRCDIR/scripts/test-morph" init
"$SRCDIR/scripts/test-morph" update-gits baserock:morphs master hello-stratum
diff --git a/tests.branching/setup b/tests.branching/setup
index cce3b672..f075e7b1 100755
--- a/tests.branching/setup
+++ b/tests.branching/setup
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# Copyright (C) 2012 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify