From 5f705f1e2c95b988ae39df7820f4034c49f375e4 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 8 Aug 2014 15:42:03 +0000 Subject: Rename morph3 to morphology Instead of leaving morph3 with a potentially confusing name, rename it to `morphology` since it is now the only implementation of the Morphology class. --- morphlib/__init__.py | 2 +- morphlib/morph3.py | 45 -------------------- morphlib/morph3_tests.py | 48 --------------------- morphlib/morphloader.py | 2 +- morphlib/morphloader_tests.py | 98 +++++++++++++++++++++---------------------- morphlib/morphology.py | 45 ++++++++++++++++++++ morphlib/morphology_tests.py | 48 +++++++++++++++++++++ morphlib/morphset_tests.py | 6 +-- 8 files changed, 147 insertions(+), 147 deletions(-) delete mode 100644 morphlib/morph3.py delete mode 100644 morphlib/morph3_tests.py create mode 100644 morphlib/morphology.py create mode 100644 morphlib/morphology_tests.py (limited to 'morphlib') diff --git a/morphlib/__init__.py b/morphlib/__init__.py index a31cf04c..f98c11aa 100644 --- a/morphlib/__init__.py +++ b/morphlib/__init__.py @@ -70,7 +70,7 @@ import localrepocache import mountableimage import morphologyfactory import morphologyfinder -import morph3 +import morphology import morphloader import morphset import remoteartifactcache diff --git a/morphlib/morph3.py b/morphlib/morph3.py deleted file mode 100644 index 477cac1a..00000000 --- a/morphlib/morph3.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (C) 2013 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# =*= License: GPL-2 =*= - - -import UserDict - - -class Morphology(UserDict.IterableUserDict): - - '''A container for a morphology, plus its metadata. - - A morphology is, basically, a dict. This class acts as that dict, - plus stores additional metadata about the morphology, such as where - it came from, and the ref that was used for it. It also has a dirty - attribute, to indicate whether the morphology has had changes done - to it, but does not itself set that attribute: the caller has to - maintain the flag themselves. - - This class does NO validation of the data, nor does it parse the - morphology text, or produce a textual form of itself. For those - things, see MorphologyLoader. - - ''' - - def __init__(self, *args, **kwargs): - UserDict.IterableUserDict.__init__(self, *args, **kwargs) - self.repo_url = None - self.ref = None - self.filename = None - self.dirty = None - diff --git a/morphlib/morph3_tests.py b/morphlib/morph3_tests.py deleted file mode 100644 index e150bf33..00000000 --- a/morphlib/morph3_tests.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (C) 2013 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# =*= License: GPL-2 =*= - - -import unittest - -import morphlib - - -class MorphologyTests(unittest.TestCase): - - def setUp(self): - self.morph = morphlib.morph3.Morphology() - - def test_has_repo_url_attribute(self): - self.assertEqual(self.morph.repo_url, None) - self.morph.repo_url = 'foo' - self.assertEqual(self.morph.repo_url, 'foo') - - def test_has_ref_attribute(self): - self.assertEqual(self.morph.ref, None) - self.morph.ref = 'foo' - self.assertEqual(self.morph.ref, 'foo') - - def test_has_filename_attribute(self): - self.assertEqual(self.morph.filename, None) - self.morph.filename = 'foo' - self.assertEqual(self.morph.filename, 'foo') - - def test_has_dirty_attribute(self): - self.assertEqual(self.morph.dirty, None) - self.morph.dirty = True - self.assertEqual(self.morph.dirty, True) - diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index d06c06dc..05dcb62c 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -394,7 +394,7 @@ class MorphologyLoader(object): if not isinstance(obj, dict): raise NotADictionaryError(morph_filename) - return morphlib.morph3.Morphology(obj) + return morphlib.morphology.Morphology(obj) def load_from_string(self, string, filename='string'): '''Load a morphology from a string. diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py index 738f1c32..d47ec750 100644 --- a/morphlib/morphloader_tests.py +++ b/morphlib/morphloader_tests.py @@ -59,21 +59,21 @@ build-system: dummy self.loader.parse_morphology_text, '- item1\n- item2\n', 'test') def test_fails_to_validate_dict_without_kind(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'invalid': 'field', }) self.assertRaises( morphlib.morphloader.MissingFieldError, self.loader.validate, m) def test_fails_to_validate_chunk_with_no_fields(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'chunk', }) self.assertRaises( morphlib.morphloader.MissingFieldError, self.loader.validate, m) def test_fails_to_validate_chunk_with_invalid_field(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'chunk', 'name': 'foo', 'invalid': 'field', @@ -82,7 +82,7 @@ build-system: dummy morphlib.morphloader.InvalidFieldError, self.loader.validate, m) def test_validate_requires_products_list(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='chunk', name='foo', products={ @@ -98,7 +98,7 @@ build-system: dummy self.assertEqual(e.morphology_name, 'foo') def test_validate_requires_products_list_of_mappings(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='chunk', name='foo', products=[ @@ -113,7 +113,7 @@ build-system: dummy self.assertEqual(e.morphology_name, 'foo') def test_validate_requires_products_list_required_fields(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='chunk', name='foo', products=[ @@ -136,7 +136,7 @@ build-system: dummy self.assertEqual(exs[3].field, 'products[0].factiart') def test_validate_requires_products_list_include_is_list(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='chunk', name='foo', products=[ @@ -154,7 +154,7 @@ build-system: dummy self.assertEqual(ex.morphology_name, 'foo') def test_validate_requires_products_list_include_is_list_of_strings(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind='chunk', name='foo', products=[ @@ -175,14 +175,14 @@ build-system: dummy def test_fails_to_validate_stratum_with_no_fields(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'stratum', }) self.assertRaises( morphlib.morphloader.MissingFieldError, self.loader.validate, m) def test_fails_to_validate_stratum_with_invalid_field(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'stratum', 'name': 'foo', 'invalid': 'field', @@ -191,7 +191,7 @@ build-system: dummy morphlib.morphloader.InvalidFieldError, self.loader.validate, m) def test_validate_requires_chunk_refs_in_stratum_to_be_strings(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'stratum', 'name': 'foo', 'build-depends': [], @@ -209,7 +209,7 @@ build-system: dummy self.loader.validate(m) def test_fails_to_validate_stratum_with_empty_refs_for_a_chunk(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'stratum', 'name': 'foo', 'build-depends': [], @@ -227,7 +227,7 @@ build-system: dummy self.loader.validate(m) def test_fails_to_validate_system_with_obsolete_system_kind_field(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'system', 'name': 'foo', 'arch': 'x86_64', @@ -240,7 +240,7 @@ build-system: dummy morphlib.morphloader.ObsoleteFieldsError, self.loader.validate, m) def test_fails_to_validate_system_with_obsolete_disk_size_field(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'system', 'name': 'foo', 'arch': 'x86_64', @@ -253,14 +253,14 @@ build-system: dummy morphlib.morphloader.ObsoleteFieldsError, self.loader.validate, m) def test_fails_to_validate_system_with_no_fields(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'system', }) self.assertRaises( morphlib.morphloader.MissingFieldError, self.loader.validate, m) def test_fails_to_validate_system_with_invalid_field(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind="system", name="foo", arch="blah", @@ -272,14 +272,14 @@ build-system: dummy morphlib.morphloader.InvalidFieldError, self.loader.validate, m) def test_fails_to_validate_morphology_with_unknown_kind(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'invalid', }) self.assertRaises( morphlib.morphloader.UnknownKindError, self.loader.validate, m) def test_validate_requires_unique_stratum_names_within_a_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "kind": "system", "name": "foo", @@ -301,7 +301,7 @@ build-system: dummy self.loader.validate, m) def test_validate_requires_unique_chunk_names_within_a_stratum(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "kind": "stratum", "name": "foo", @@ -322,7 +322,7 @@ build-system: dummy self.loader.validate, m) def test_validate_requires_a_valid_architecture(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind="system", name="foo", arch="blah", @@ -334,7 +334,7 @@ build-system: dummy self.loader.validate, m) def test_validate_normalises_architecture_armv7_to_armv7l(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( kind="system", name="foo", arch="armv7", @@ -345,7 +345,7 @@ build-system: dummy self.assertEqual(m['arch'], 'armv7l') def test_validate_requires_build_deps_for_chunks_in_strata(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "kind": "stratum", "name": "foo", @@ -365,7 +365,7 @@ build-system: dummy self.loader.validate, m) def test_validate_requires_build_deps_or_bootstrap_mode_for_strata(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "name": "stratum-no-bdeps-no-bootstrap", "kind": "stratum", @@ -395,7 +395,7 @@ build-system: dummy self.loader.validate(m) def test_validate_requires_chunks_in_strata(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "name": "stratum", "kind": "stratum", @@ -415,7 +415,7 @@ build-system: dummy self.loader.validate, m) def test_validate_requires_strata_in_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='system', kind='system', arch='testarch') @@ -425,7 +425,7 @@ build-system: dummy def test_validate_requires_list_of_strata_in_system(self): for v in (None, {}): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='system', kind='system', arch='testarch', @@ -437,7 +437,7 @@ build-system: dummy self.assertEqual(cm.exception.strata_type, type(v)) def test_validate_requires_non_empty_strata_in_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='system', kind='system', arch='testarch', @@ -447,7 +447,7 @@ build-system: dummy self.loader.validate, m) def test_validate_requires_stratum_specs_in_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='system', kind='system', arch='testarch', @@ -460,7 +460,7 @@ build-system: dummy def test_validate_requires_unique_deployment_names_in_cluster(self): subsystem = [{'morph': 'baz', 'deploy': {'foobar': None}}] - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='cluster', kind='cluster', systems=[{'morph': 'foo', @@ -513,7 +513,7 @@ build-system: dummy self.assertEqual(morph['build-system'], 'dummy') def test_saves_to_string(self): - morph = morphlib.morph3.Morphology({ + morph = morphlib.morphology.Morphology({ 'name': 'foo', 'kind': 'chunk', 'build-system': 'dummy', @@ -529,7 +529,7 @@ build-system: dummy ''') def test_saves_to_file(self): - morph = morphlib.morph3.Morphology({ + morph = morphlib.morphology.Morphology({ 'name': 'foo', 'kind': 'chunk', 'build-system': 'dummy', @@ -548,7 +548,7 @@ build-system: dummy ''') def test_validate_does_not_set_defaults(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'chunk', 'name': 'foo', }) @@ -556,7 +556,7 @@ build-system: dummy self.assertEqual(sorted(m.keys()), sorted(['kind', 'name'])) def test_sets_defaults_for_chunks(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'chunk', 'name': 'foo', }) @@ -594,7 +594,7 @@ build-system: dummy }) def test_unsets_defaults_for_chunks(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'chunk', 'name': 'foo', 'build-system': 'manual', @@ -608,7 +608,7 @@ build-system: dummy }) def test_sets_defaults_for_strata(self): - m = morphlib.morph3.Morphology({ + m = morphlib.morphology.Morphology({ 'kind': 'stratum', 'name': 'foo', 'chunks': [ @@ -661,14 +661,14 @@ build-system: dummy } test_dict_with_build_depends = dict(test_dict) test_dict_with_build_depends["build-depends"] = [] - m = morphlib.morph3.Morphology(test_dict_with_build_depends) + m = morphlib.morphology.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( + m = morphlib.morphology.Morphology( kind='system', name='foo', arch='testarch', @@ -696,7 +696,7 @@ build-system: dummy dict(m)) def test_unsets_defaults_for_system(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { 'description': '', 'kind': 'system', @@ -724,7 +724,7 @@ build-system: dummy }) def test_sets_defaults_for_cluster(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='foo', kind='cluster', systems=[ @@ -741,7 +741,7 @@ build-system: dummy 'deploy': {}}]) def test_unsets_defaults_for_cluster(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='foo', kind='cluster', description='', @@ -759,7 +759,7 @@ build-system: dummy {'morph': 'bar'}]) def test_sets_stratum_chunks_repo_from_name(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "name": "foo", "kind": "stratum", @@ -777,7 +777,7 @@ build-system: dummy self.assertEqual(m['chunks'][0]['repo'], 'le-chunk') def test_collapses_stratum_chunks_repo_from_name(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "name": "foo", "kind": "stratum", @@ -796,7 +796,7 @@ build-system: dummy self.assertTrue('repo' not in m['chunks'][0]) def test_convertes_max_jobs_to_an_integer(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { "name": "foo", "kind": "chunk", @@ -829,7 +829,7 @@ build-system: dummy def test_warns_when_systems_refer_to_strata_with_repo_or_ref(self): for obsolete_field in ('repo', 'ref'): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name="foo", kind="system", arch="testarch", @@ -852,7 +852,7 @@ build-system: dummy def test_warns_when_strata_refer_to_build_depends_with_repo_or_ref(self): for obsolete_field in ('repo', 'ref'): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( { 'name': 'foo', 'kind': 'stratum', @@ -885,7 +885,7 @@ build-system: dummy def test_unordered_asciibetically_after_ordered(self): # We only get morphologies with arbitrary keys in clusters - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name='foo', kind='cluster', systems=[ @@ -926,21 +926,21 @@ build-system: dummy self.assertEqual(s, self.loader.save_to_string(m)) def test_smoketest_multi_line_unicode(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name=u'foo', description=u'1 2 3\n4 5 6\n7 8 9\n', ) s = self.loader.save_to_string(m) def test_smoketest_multi_line_unicode_encoded(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( name=u'foo \u263A'.encode('utf-8'), description=u'1 \u263A\n2 \u263A\n3 \u263A\n'.encode('utf-8'), ) s = self.loader.save_to_string(m) def test_smoketest_binary_garbage(self): - m = morphlib.morph3.Morphology( + m = morphlib.morphology.Morphology( description='\x92', ) s = self.loader.save_to_string(m) diff --git a/morphlib/morphology.py b/morphlib/morphology.py new file mode 100644 index 00000000..314c315a --- /dev/null +++ b/morphlib/morphology.py @@ -0,0 +1,45 @@ +# Copyright (C) 2013-2014 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# =*= License: GPL-2 =*= + + +import UserDict + + +class Morphology(UserDict.IterableUserDict): + + '''A container for a morphology, plus its metadata. + + A morphology is, basically, a dict. This class acts as that dict, + plus stores additional metadata about the morphology, such as where + it came from, and the ref that was used for it. It also has a dirty + attribute, to indicate whether the morphology has had changes done + to it, but does not itself set that attribute: the caller has to + maintain the flag themselves. + + This class does NO validation of the data, nor does it parse the + morphology text, or produce a textual form of itself. For those + things, see MorphologyLoader. + + ''' + + def __init__(self, *args, **kwargs): + UserDict.IterableUserDict.__init__(self, *args, **kwargs) + self.repo_url = None + self.ref = None + self.filename = None + self.dirty = None + diff --git a/morphlib/morphology_tests.py b/morphlib/morphology_tests.py new file mode 100644 index 00000000..385f62ee --- /dev/null +++ b/morphlib/morphology_tests.py @@ -0,0 +1,48 @@ +# Copyright (C) 2013-2014 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# =*= License: GPL-2 =*= + + +import unittest + +import morphlib + + +class MorphologyTests(unittest.TestCase): + + def setUp(self): + self.morph = morphlib.morphology.Morphology() + + def test_has_repo_url_attribute(self): + self.assertEqual(self.morph.repo_url, None) + self.morph.repo_url = 'foo' + self.assertEqual(self.morph.repo_url, 'foo') + + def test_has_ref_attribute(self): + self.assertEqual(self.morph.ref, None) + self.morph.ref = 'foo' + self.assertEqual(self.morph.ref, 'foo') + + def test_has_filename_attribute(self): + self.assertEqual(self.morph.filename, None) + self.morph.filename = 'foo' + self.assertEqual(self.morph.filename, 'foo') + + def test_has_dirty_attribute(self): + self.assertEqual(self.morph.dirty, None) + self.morph.dirty = True + self.assertEqual(self.morph.dirty, True) + diff --git a/morphlib/morphset_tests.py b/morphlib/morphset_tests.py index af1333d8..81b5810f 100644 --- a/morphlib/morphset_tests.py +++ b/morphlib/morphset_tests.py @@ -26,7 +26,7 @@ class MorphologySetTests(unittest.TestCase): def setUp(self): self.morphs = morphlib.morphset.MorphologySet() - self.system = morphlib.morph3.Morphology({ + self.system = morphlib.morphology.Morphology({ 'kind': 'system', 'name': 'foo-system', 'strata': [ @@ -41,7 +41,7 @@ class MorphologySetTests(unittest.TestCase): self.system.ref = 'master' self.system.filename = 'foo-system.morph' - self.stratum = morphlib.morph3.Morphology({ + self.stratum = morphlib.morphology.Morphology({ 'kind': 'stratum', 'name': 'foo-stratum', 'chunks': [ @@ -111,7 +111,7 @@ class MorphologySetTests(unittest.TestCase): }) def test_changes_stratum_ref_in_build_depends(self): - other_stratum = morphlib.morph3.Morphology({ + other_stratum = morphlib.morphology.Morphology({ 'name': 'other-stratum', 'kind': 'stratum', 'chunks': [], -- cgit v1.2.1