summaryrefslogtreecommitdiff
path: root/morphlib/cachekeycomputer_tests.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-04-12 15:12:15 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2012-04-12 17:36:27 +0100
commit82e9a58b550731e5a5d367bb2b67c104f1b04ef2 (patch)
treebcd013a84e9237e7500941b4e91e6d81e62659a5 /morphlib/cachekeycomputer_tests.py
parent280af95cacefc17a569312c6157ce2baccf68ac8 (diff)
downloadmorph-82e9a58b550731e5a5d367bb2b67c104f1b04ef2.tar.gz
cachekeycomputer tests: clean up different_key
Rather than poking the internals of both the build_environment and cachekeycomputer classes to change the environment, make a new build environment and cache key computer with a different environment
Diffstat (limited to 'morphlib/cachekeycomputer_tests.py')
-rw-r--r--morphlib/cachekeycomputer_tests.py40
1 files changed, 24 insertions, 16 deletions
diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py
index 4973a948..fb49ee5f 100644
--- a/morphlib/cachekeycomputer_tests.py
+++ b/morphlib/cachekeycomputer_tests.py
@@ -30,15 +30,6 @@ class DummyBuildEnvironment:
class CacheKeyComputerTests(unittest.TestCase):
def setUp(self):
- self.build_env = DummyBuildEnvironment({
- "USER": "foouser",
- "USERNAME": "foouser",
- "LOGNAME": "foouser",
- "TOOLCHAIN_TARGET": "dummy-baserock-linux-gnu",
- "PREFIX": "/baserock",
- "BOOTSTRAP": "false",
- "CFLAGS": "-O4"})
- self.ckc = morphlib.cachekeycomputer.CacheKeyComputer(self.build_env)
pool = morphlib.sourcepool.SourcePool()
self.sources = {}
for name, text in {
@@ -62,12 +53,16 @@ class CacheKeyComputerTests(unittest.TestCase):
morphlib.morph2.Morphology(text), name)
pool.add(source)
self.sources[name] = source
-
morphlib.buildgraph.BuildGraph().compute_build_order(pool)
-
- def _valid_sha256(self, s):
- validchars = '0123456789abcdef'
- return len(s) == 64 and all(c in validchars for c in s)
+ self.build_env = DummyBuildEnvironment({
+ "USER": "foouser",
+ "USERNAME": "foouser",
+ "LOGNAME": "foouser",
+ "TOOLCHAIN_TARGET": "dummy-baserock-linux-gnu",
+ "PREFIX": "/baserock",
+ "BOOTSTRAP": "false",
+ "CFLAGS": "-O4"})
+ self.ckc = morphlib.cachekeycomputer.CacheKeyComputer(self.build_env)
def test_get_cache_key_hashes_all_types(self):
runcount = {'thing': 0, 'dict': 0, 'list': 0, 'tuple': 0}
@@ -86,12 +81,25 @@ class CacheKeyComputerTests(unittest.TestCase):
self.assertNotEqual(runcount['list'], 0)
self.assertNotEqual(runcount['tuple'], 0)
+ def _valid_sha256(self, s):
+ validchars = '0123456789abcdef'
+ return len(s) == 64 and all(c in validchars for c in s)
+
def test_get_cache_key_returns_sha256(self):
self.assertTrue(self._valid_sha256(
self.ckc.get_cache_key(self.sources['stratum.morph'])))
def test_different_env_gives_different_key(self):
oldsha = self.ckc.get_cache_key(self.sources['stratum.morph'])
- self.ckc._env['CFLAGS'] = "-Os"
+ build_env = DummyBuildEnvironment({
+ "USER": "foouser",
+ "USERNAME": "foouser",
+ "LOGNAME": "foouser",
+ "TOOLCHAIN_TARGET": "dummy-baserock-linux-gnu",
+ "PREFIX": "/baserock",
+ "BOOTSTRAP": "false",
+ "CFLAGS": "-Os"})
+ ckc = morphlib.cachekeycomputer.CacheKeyComputer(build_env)
+
self.assertNotEqual(oldsha,
- self.ckc.get_cache_key(self.sources['stratum.morph']))
+ ckc.get_cache_key(self.sources['stratum.morph']))