From 0c4c27d282e381899fd9a375a66ebd17b4cf725e Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Mon, 30 Jun 2014 11:31:49 +0000 Subject: unittests: Test that paths in the morph field of chunks work This commit adds a test to check that having a filepath in the morph field of a chunk spec works as expected. It also fixes the tests to work with a separate morphology repository and source repository in Source objects. --- morphlib/artifact_tests.py | 3 +- morphlib/artifactresolver_tests.py | 105 ++++++++++++++++++++++++++-------- morphlib/cachekeycomputer_tests.py | 8 ++- morphlib/localartifactcache_tests.py | 3 +- morphlib/remoteartifactcache_tests.py | 3 +- morphlib/source_tests.py | 6 +- 6 files changed, 96 insertions(+), 32 deletions(-) diff --git a/morphlib/artifact_tests.py b/morphlib/artifact_tests.py index d4b15cba..9b796849 100644 --- a/morphlib/artifact_tests.py +++ b/morphlib/artifact_tests.py @@ -42,7 +42,8 @@ class ArtifactTests(unittest.TestCase): } ''') self.source = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'chunk.morph', 'repo', 'ref') self.artifact_name = 'chunk-runtime' self.artifact = morphlib.artifact.Artifact( self.source, self.artifact_name) diff --git a/morphlib/artifactresolver_tests.py b/morphlib/artifactresolver_tests.py index 6f62b4d1..e8f86f24 100644 --- a/morphlib/artifactresolver_tests.py +++ b/morphlib/artifactresolver_tests.py @@ -110,7 +110,8 @@ class ArtifactResolverTests(unittest.TestCase): morph = FakeChunkMorphology('chunk') source = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'chunk.morph', 'repo', 'ref') pool.add(source) artifacts = self.resolver.resolve_artifacts(pool) @@ -129,7 +130,8 @@ class ArtifactResolverTests(unittest.TestCase): morph = FakeChunkMorphology('chunk', ['chunk-foobar']) source = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'chunk.morph', 'repo', 'ref') pool.add(source) artifacts = self.resolver.resolve_artifacts(pool) @@ -147,7 +149,8 @@ class ArtifactResolverTests(unittest.TestCase): morph = FakeChunkMorphology('chunk', ['chunk-baz', 'chunk-qux']) source = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'chunk.morph', 'repo', 'ref') pool.add(source) artifacts = self.resolver.resolve_artifacts(pool) @@ -167,13 +170,51 @@ class ArtifactResolverTests(unittest.TestCase): morph = FakeChunkMorphology('chunk') chunk = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'chunk.morph', 'repo', 'ref') pool.add(chunk) morph = FakeStratumMorphology( 'stratum', chunks=[('chunk', 'chunk', 'repo', 'ref')]) stratum = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'stratum.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'stratum.morph', 'repo', 'ref') + pool.add(stratum) + + artifacts = self.resolver.resolve_artifacts(pool) + + self.assertEqual(len(artifacts), + sum(len(s.split_rules.artifacts) for s in pool)) + + stratum_artifacts = set(a for a in artifacts if a.source == stratum) + chunk_artifacts = set(a for a in artifacts if a.source == chunk) + + for stratum_artifact in stratum_artifacts: + self.assertTrue(stratum_artifact.name.startswith('stratum')) + self.assertEqual(stratum_artifact.dependents, []) + self.assertTrue(any(dep in chunk_artifacts + for dep in stratum_artifact.dependencies)) + + for chunk_artifact in chunk_artifacts: + self.assertTrue(chunk_artifact.name.startswith('chunk')) + self.assertEqual(chunk_artifact.dependencies, []) + self.assertTrue(any(dep in stratum_artifacts + for dep in chunk_artifact.dependents)) + + def test_resolve_stratum_and_chunk_with_chunk_path(self): + pool = morphlib.sourcepool.SourcePool() + + morph = FakeChunkMorphology('chunk') + chunk = morphlib.source.Source( + 'repo', 'ref', 'sha1', 'tree', morph, + 'chunk.morph', 'repo', 'ref') + pool.add(chunk) + + morph = FakeStratumMorphology( + 'stratum', chunks=[('chunk', 'chunk.morph', 'repo', 'ref')]) + stratum = morphlib.source.Source( + 'repo', 'ref', 'sha1', 'tree', morph, + 'stratum.morph', 'repo', 'ref') pool.add(stratum) artifacts = self.resolver.resolve_artifacts(pool) @@ -201,7 +242,8 @@ class ArtifactResolverTests(unittest.TestCase): morph = FakeChunkMorphology('chunk', ['chunk-foo', 'chunk-bar']) chunk = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'chunk.morph', 'repo', 'ref') pool.add(chunk) morph = FakeStratumMorphology( @@ -210,7 +252,8 @@ class ArtifactResolverTests(unittest.TestCase): ('chunk', 'chunk', 'repo', 'ref'), ]) stratum = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'stratum.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'stratum.morph', 'repo', 'ref') pool.add(stratum) artifacts = self.resolver.resolve_artifacts(pool) @@ -238,14 +281,16 @@ class ArtifactResolverTests(unittest.TestCase): morph = FakeChunkMorphology('chunk1') chunk1 = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'chunk1.morph', 'repo', 'ref') pool.add(chunk1) morph = FakeStratumMorphology( 'stratum1', chunks=[('chunk1', 'chunk1', 'repo', 'original/ref')]) stratum1 = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'stratum1.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'stratum1.morph', 'repo', 'ref') pool.add(stratum1) morph = morphlib.morph2.Morphology( @@ -269,12 +314,14 @@ class ArtifactResolverTests(unittest.TestCase): ''') morph.builds_artifacts = ['system-rootfs'] system = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'system.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'system.morph', 'repo', 'ref') pool.add(system) morph = FakeChunkMorphology('chunk2') chunk2 = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'chunk2.morph', 'repo', 'ref') pool.add(chunk2) morph = FakeStratumMorphology( @@ -282,7 +329,8 @@ class ArtifactResolverTests(unittest.TestCase): chunks=[('chunk2', 'chunk2', 'repo', 'original/ref')], build_depends=[('stratum1', 'repo', 'ref')]) stratum2 = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'stratum2.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'stratum2.morph', 'repo', 'ref') pool.add(stratum2) artifacts = self.resolver.resolve_artifacts(pool) @@ -369,22 +417,26 @@ class ArtifactResolverTests(unittest.TestCase): ''') morph.builds_artifacts = ['stratum'] stratum = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'stratum.morph', 'repo', 'ref') pool.add(stratum) morph = FakeChunkMorphology('chunk1') chunk1 = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'chunk1.morph', 'repo', 'ref') pool.add(chunk1) morph = FakeChunkMorphology('chunk2') chunk2 = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'chunk2.morph', 'repo', 'ref') pool.add(chunk2) morph = FakeChunkMorphology('chunk3') chunk3 = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk3.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'chunk3.morph', 'repo', 'ref') pool.add(chunk3) artifacts = self.resolver.resolve_artifacts(pool) @@ -425,7 +477,8 @@ class ArtifactResolverTests(unittest.TestCase): chunks=[], build_depends=[('stratum2', 'repo', 'original/ref')]) stratum1 = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum1.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'stratum1.morph', 'repo', 'ref') pool.add(stratum1) morph = FakeStratumMorphology( @@ -433,7 +486,8 @@ class ArtifactResolverTests(unittest.TestCase): chunks=[], build_depends=[('stratum1', 'repo', 'original/ref')]) stratum2 = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum2.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'stratum2.morph', 'repo', 'ref') pool.add(stratum2) self.assertRaises(morphlib.artifactresolver.MutualDependencyError, @@ -466,17 +520,20 @@ class ArtifactResolverTests(unittest.TestCase): ''') morph.builds_artifacts = ['stratum'] stratum = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'stratum.morph', 'repo', 'ref') pool.add(stratum) morph = FakeChunkMorphology('chunk1') chunk1 = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'chunk1.morph', 'repo', 'ref') pool.add(chunk1) morph = FakeChunkMorphology('chunk2') chunk2 = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'chunk2.morph', 'repo', 'ref') pool.add(chunk2) self.assertRaises(morphlib.artifactresolver.DependencyOrderError, @@ -502,12 +559,14 @@ class ArtifactResolverTests(unittest.TestCase): ''') morph.builds_artifacts = ['stratum'] stratum = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'stratum.morph', 'repo', 'ref') pool.add(stratum) morph = FakeChunkMorphology('chunk') chunk = morphlib.source.Source( - 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk.morph') + 'repo', 'original/ref', 'sha1', 'tree', morph, + 'chunk.morph', 'repo', 'ref') pool.add(chunk) self.assertRaises(morphlib.artifactresolver.DependencyFormatError, diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py index 9e18b19d..477c333a 100644 --- a/morphlib/cachekeycomputer_tests.py +++ b/morphlib/cachekeycomputer_tests.py @@ -98,7 +98,8 @@ class CacheKeyComputerTests(unittest.TestCase): }.iteritems(): source = morphlib.source.Source( 'repo', 'original/ref', 'sha', 'tree', - morphlib.morph2.Morphology(text), name) + morphlib.morph2.Morphology(text), name, + 'repo', 'original/ref') self.source_pool.add(source) # FIXME: This should use MorphologyFactory m = source.morphology @@ -183,7 +184,8 @@ class CacheKeyComputerTests(unittest.TestCase): morphology = old_artifact.source.morphology new_source = morphlib.source.Source('repo', 'original/ref', 'newsha', 'tree', morphology, - old_artifact.source.filename) + old_artifact.source.filename, + 'repo', 'original/ref') sp = morphlib.sourcepool.SourcePool() for source in self.source_pool: if source == old_artifact.source: @@ -204,7 +206,7 @@ class CacheKeyComputerTests(unittest.TestCase): def test_same_morphology_added_to_source_pool_only_appears_once(self): m = morphlib.morph2.Morphology('{"name": "chunk", "kind": "chunk"}') src = morphlib.source.Source('repo', 'original/ref', 'sha', 'tree', m, - 'chunk.morph') + 'repo', 'original/ref', 'chunk.morph') sp = morphlib.sourcepool.SourcePool() sp.add(src) sp.add(src) diff --git a/morphlib/localartifactcache_tests.py b/morphlib/localartifactcache_tests.py index f400a645..d02ba3db 100644 --- a/morphlib/localartifactcache_tests.py +++ b/morphlib/localartifactcache_tests.py @@ -46,7 +46,8 @@ class LocalArtifactCacheTests(unittest.TestCase): } ''') self.source = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'chunk.morph', 'repo', 'ref') self.runtime_artifact = morphlib.artifact.Artifact( self.source, 'chunk-runtime') self.runtime_artifact.cache_key = '0'*64 diff --git a/morphlib/remoteartifactcache_tests.py b/morphlib/remoteartifactcache_tests.py index d11bf264..ed97ad68 100644 --- a/morphlib/remoteartifactcache_tests.py +++ b/morphlib/remoteartifactcache_tests.py @@ -46,7 +46,8 @@ class RemoteArtifactCacheTests(unittest.TestCase): } ''') self.source = morphlib.source.Source( - 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph') + 'repo', 'ref', 'sha1', 'tree', morph, + 'chunk.morph', 'repo', 'ref') self.runtime_artifact = morphlib.artifact.Artifact( self.source, 'chunk-runtime') self.runtime_artifact.cache_key = 'CHUNK-RUNTIME' diff --git a/morphlib/source_tests.py b/morphlib/source_tests.py index 6643f0fc..c4d9cfac 100644 --- a/morphlib/source_tests.py +++ b/morphlib/source_tests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012 Codethink Limited +# Copyright (C) 2012-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 @@ -37,10 +37,10 @@ class SourceTests(unittest.TestCase): self.filename = 'foo.morph' self.source = morphlib.source.Source( self.repo_name, self.original_ref, self.sha1, self.tree, - self.morphology, self.filename) + self.morphology, self.filename, self.repo_name, self.original_ref) self.other = morphlib.source.Source( self.repo_name, self.original_ref, self.sha1, self.tree, - self.morphology, self.filename) + self.morphology, self.filename, self.repo_name, self.original_ref) def test_sets_repo_name(self): self.assertEqual(self.source.repo_name, self.repo_name) -- cgit v1.2.1