summaryrefslogtreecommitdiff
path: root/morphlib/cachekeycomputer_tests.py
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-04-18 16:49:24 +0100
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-04-18 16:49:24 +0100
commit105c0dbbd14626a832ebc036c02bc0c9c60e43bc (patch)
tree9e9398e9e4d4bc8da54a63094142f941b881419e /morphlib/cachekeycomputer_tests.py
parent605e21914f8c9536ff42ca31043b26200dab85e2 (diff)
downloadmorph-105c0dbbd14626a832ebc036c02bc0c9c60e43bc.tar.gz
Remove BuildGraph, compute cache keys based on Artifacts.
With this commit, the ArtifactResolver no longer computes the cache keys when creating Artifact objects. This will have to happen as a post-resolving step (e.g. prior to building or checking whether a local or remote artifact cache has any of the resolved artifacts). The CacheKeyComputer now takes an Artifact object and computes the cache keys using its dependencies. BuildGraph is no longer needed for the CacheKeyComputer unit tests.
Diffstat (limited to 'morphlib/cachekeycomputer_tests.py')
-rw-r--r--morphlib/cachekeycomputer_tests.py35
1 files changed, 24 insertions, 11 deletions
diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py
index 923cc9f9..51616a12 100644
--- a/morphlib/cachekeycomputer_tests.py
+++ b/morphlib/cachekeycomputer_tests.py
@@ -18,6 +18,7 @@ import unittest
import morphlib
+
class DummyBuildEnvironment:
'''Fake build environment class that doesn't need
settings to pick the environment, it just gets passed
@@ -27,11 +28,11 @@ class DummyBuildEnvironment:
self.arch = morphlib.util.arch() if arch == None else arch
self.env = env
+
class CacheKeyComputerTests(unittest.TestCase):
def setUp(self):
- pool = morphlib.sourcepool.SourcePool()
- self.sources = {}
+ self.source_pool = morphlib.sourcepool.SourcePool()
for name, text in {
'chunk.morph': '''{
"name": "chunk",
@@ -83,9 +84,7 @@ class CacheKeyComputerTests(unittest.TestCase):
}.iteritems():
source = morphlib.source.Source('repo', 'original/ref', 'sha',
morphlib.morph2.Morphology(text), name)
- pool.add(source)
- self.sources[name] = source
- morphlib.buildgraph.BuildGraph().compute_build_order(pool)
+ self.source_pool.add(source)
self.build_env = DummyBuildEnvironment({
"USER": "foouser",
"USERNAME": "foouser",
@@ -94,8 +93,17 @@ class CacheKeyComputerTests(unittest.TestCase):
"PREFIX": "/baserock",
"BOOTSTRAP": "false",
"CFLAGS": "-O4"})
+ self.artifact_resolver = morphlib.artifactresolver.ArtifactResolver()
+ self.artifacts = self.artifact_resolver.resolve_artifacts(
+ self.source_pool)
self.ckc = morphlib.cachekeycomputer.CacheKeyComputer(self.build_env)
+ def _find_artifact(self, name):
+ for artifact in self.artifacts:
+ if artifact.name == name:
+ return artifact
+ raise
+
def test_compute_key_hashes_all_types(self):
runcount = {'thing': 0, 'dict': 0, 'list': 0, 'tuple': 0}
def inccount(func, name):
@@ -103,11 +111,15 @@ class CacheKeyComputerTests(unittest.TestCase):
runcount[name] = runcount[name] + 1
func(sha, item)
return f
+
self.ckc._hash_thing = inccount(self.ckc._hash_thing, 'thing')
self.ckc._hash_dict = inccount(self.ckc._hash_dict, 'dict')
self.ckc._hash_list = inccount(self.ckc._hash_list, 'list')
self.ckc._hash_tuple = inccount(self.ckc._hash_tuple, 'tuple')
- self.ckc.compute_key(self.sources['stratum.morph'])
+
+ artifact = self._find_artifact('system')
+ self.ckc.compute_key(artifact)
+
self.assertNotEqual(runcount['thing'], 0)
self.assertNotEqual(runcount['dict'], 0)
self.assertNotEqual(runcount['list'], 0)
@@ -115,14 +127,16 @@ class CacheKeyComputerTests(unittest.TestCase):
def _valid_sha256(self, s):
validchars = '0123456789abcdef'
- return len(s) == 64 and all(c in validchars for c in s)
+ return len(s) == 64 and all([c in validchars for c in s])
def test_compute_key_returns_sha256(self):
+ artifact = self._find_artifact('system')
self.assertTrue(self._valid_sha256(
- self.ckc.compute_key(self.sources['system.morph'])))
+ self.ckc.compute_key(artifact)))
def test_different_env_gives_different_key(self):
- oldsha = self.ckc.compute_key(self.sources['system.morph'])
+ artifact = self._find_artifact('system')
+ oldsha = self.ckc.compute_key(artifact)
build_env = DummyBuildEnvironment({
"USER": "foouser",
"USERNAME": "foouser",
@@ -133,5 +147,4 @@ class CacheKeyComputerTests(unittest.TestCase):
"CFLAGS": "-Os"})
ckc = morphlib.cachekeycomputer.CacheKeyComputer(build_env)
- self.assertNotEqual(oldsha,
- ckc.compute_key(self.sources['system.morph']))
+ self.assertNotEqual(oldsha, ckc.compute_key(artifact))