From 960c84e111111d0b203d6aa16f23552cc9978c99 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 10 Sep 2014 10:59:59 +0000 Subject: Turn Morphology.needs_artifact_metadata_cached into a property This means we can remove some complication from the MorphologyFactory class. --- morphlib/morphology.py | 3 +++ morphlib/morphologyfactory.py | 28 +--------------------------- morphlib/morphologyfactory_tests.py | 13 ------------- 3 files changed, 4 insertions(+), 40 deletions(-) diff --git a/morphlib/morphology.py b/morphlib/morphology.py index 314c315a..01f332c6 100644 --- a/morphlib/morphology.py +++ b/morphlib/morphology.py @@ -43,3 +43,6 @@ class Morphology(UserDict.IterableUserDict): self.filename = None self.dirty = None + @property + def needs_artifact_metadata_cached(self): # pragma: no cover + return self.get('kind') == 'stratum' diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index a576835e..b0a0528d 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -50,7 +50,7 @@ class MorphologyFactory(object): if self._app is not None: self._app.status(*args, **kwargs) - def _load_morphology(self, reponame, sha1, filename): + def get_morphology(self, reponame, sha1, filename): morph_name = os.path.splitext(os.path.basename(filename))[0] loader = morphlib.morphloader.MorphologyLoader() if self._lrc.has_repo(reponame): @@ -88,29 +88,3 @@ class MorphologyFactory(object): loader.set_commands(morph) loader.set_defaults(morph) return morph - - def get_morphology(self, reponame, sha1, filename): - morphology = self._load_morphology(reponame, sha1, filename) - - method_name = '_check_and_tweak_%s' % morphology['kind'] - if hasattr(self, method_name): - method = getattr(self, method_name) - method(morphology, reponame, sha1, filename) - - return morphology - - def _check_and_tweak_system(self, morphology, reponame, sha1, filename): - '''Check and tweak a system morphology.''' - - name = morphology['name'] - morphology.needs_artifact_metadata_cached = False - - def _check_and_tweak_stratum(self, morphology, reponame, sha1, filename): - '''Check and tweak a stratum morphology.''' - - morphology.needs_artifact_metadata_cached = True - - def _check_and_tweak_chunk(self, morphology, reponame, sha1, filename): - '''Check and tweak a chunk morphology.''' - - morphology.needs_artifact_metadata_cached = False diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py index 5692c5f0..52d5f598 100644 --- a/morphlib/morphologyfactory_tests.py +++ b/morphlib/morphologyfactory_tests.py @@ -248,19 +248,6 @@ class MorphologyFactoryTests(unittest.TestCase): self.assertRaises(NotcachedError, self.lmf.get_morphology, 'reponame', 'sha1', 'unreached.morph') - def test_does_not_set_needs_artifact_metadata_cached_for_chunk(self): - morph = self.mf.get_morphology('reponame', 'sha1', 'chunk.morph') - self.assertEqual(morph.needs_artifact_metadata_cached, False) - - def test_sets_artifact_metadata_cached_for_stratum(self): - morph = self.mf.get_morphology('reponame', 'sha1', 'stratum.morph') - self.assertEqual(morph.needs_artifact_metadata_cached, True) - - def test_does_not_set_artifact_metadata_cached_for_system(self): - morph = self.mf.get_morphology('reponame', 'sha1', 'system.morph') - self.assertEqual(morph.needs_artifact_metadata_cached, False) - - def test_arch_is_validated(self): self.lr.arch = 'unknown' self.assertRaises(morphlib.Error, self.mf.get_morphology, -- cgit v1.2.1