diff options
-rw-r--r-- | morphlib/bins_tests.py | 75 | ||||
-rw-r--r-- | morphlib/blobs_tests.py | 82 | ||||
-rw-r--r-- | morphlib/sourcemanager_tests.py | 12 | ||||
-rw-r--r-- | morphlib/stopwatch_tests.py | 18 |
4 files changed, 95 insertions, 92 deletions
diff --git a/morphlib/bins_tests.py b/morphlib/bins_tests.py index 8a54033b..73daff50 100644 --- a/morphlib/bins_tests.py +++ b/morphlib/bins_tests.py @@ -22,38 +22,40 @@ import unittest import morphlib -def recursive_lstat(root): - '''Return a list of (pathname, stat result) pairs for everything in root. - - Pathnames are relative to root. Directories are recursed into. - The stat result is selective, not all fields are used. - - ''' - - def remove_root(pathname): - assert pathname.startswith(root) - if pathname == root: - return '.' - else: - return pathname[len(root)+1:] - - def lstat(filename): - st = os.lstat(filename) - return (st.st_mode, st.st_size, int(st.st_mtime)) +class BinsTest(unittest.TestCase): - result = [] - - for dirname, subdirs, basenames in os.walk(root): - result.append((remove_root(dirname), lstat(dirname))) - for basename in sorted(basenames): - filename = os.path.join(dirname, basename) - result.append((remove_root(filename), lstat(filename))) - subdirs.sort() + def recursive_lstat(self, root): + '''Return a list of (pathname, stat) pairs for everything in root. + + Pathnames are relative to root. Directories are recursed into. + The stat result is selective, not all fields are used. + + ''' + + def remove_root(pathname): + self.assertTrue(pathname.startswith(root)) + if pathname == root: + return '.' + else: + return pathname[len(root)+1:] + + def lstat(filename): + st = os.lstat(filename) + return (st.st_mode, st.st_size, int(st.st_mtime)) - return result + result = [] + + for dirname, subdirs, basenames in os.walk(root): + result.append((remove_root(dirname), lstat(dirname))) + for basename in sorted(basenames): + filename = os.path.join(dirname, basename) + result.append((remove_root(filename), lstat(filename))) + subdirs.sort() + + return result -class ChunkTests(unittest.TestCase): +class ChunkTests(BinsTest): def setUp(self): self.ex = morphlib.execute.Execute('.', lambda s: None) @@ -84,16 +86,17 @@ class ChunkTests(unittest.TestCase): self.ex) empty = os.path.join(self.tempdir, 'empty') os.mkdir(empty) - self.assertEqual([x for x,y in recursive_lstat(self.instdir)], ['.']) + self.assertEqual([x for x,y in self.recursive_lstat(self.instdir)], + ['.']) def test_creates_and_unpacks_chunk_exactly(self): self.populate_instdir() - orig_files = recursive_lstat(self.instdir) + orig_files = self.recursive_lstat(self.instdir) morphlib.bins.create_chunk(self.instdir, self.chunk_file, ['.'], self.ex) os.mkdir(self.unpacked) morphlib.bins.unpack_binary(self.chunk_file, self.unpacked, self.ex) - self.assertEqual(orig_files, recursive_lstat(self.unpacked)) + self.assertEqual(orig_files, self.recursive_lstat(self.unpacked)) def test_uses_only_matching_names(self): self.populate_instdir() @@ -101,12 +104,12 @@ class ChunkTests(unittest.TestCase): self.ex) os.mkdir(self.unpacked) morphlib.bins.unpack_binary(self.chunk_file, self.unpacked, self.ex) - self.assertEqual([x for x,y in recursive_lstat(self.unpacked)], + self.assertEqual([x for x,y in self.recursive_lstat(self.unpacked)], ['.', 'bin', 'bin/foo']) - self.assertEqual([x for x,y in recursive_lstat(self.instdir)], + self.assertEqual([x for x,y in self.recursive_lstat(self.instdir)], ['.', 'lib', 'lib/libfoo.so']) -class StratumTests(unittest.TestCase): +class StratumTests(BinsTest): def setUp(self): self.ex = morphlib.execute.Execute('.', lambda s: None) @@ -127,6 +130,6 @@ class StratumTests(unittest.TestCase): morphlib.bins.create_stratum(self.instdir, self.stratum_file, self.ex) os.mkdir(self.unpacked) morphlib.bins.unpack_binary(self.stratum_file, self.unpacked, self.ex) - self.assertEqual(recursive_lstat(self.instdir), - recursive_lstat(self.unpacked)) + self.assertEqual(self.recursive_lstat(self.instdir), + self.recursive_lstat(self.unpacked)) diff --git a/morphlib/blobs_tests.py b/morphlib/blobs_tests.py index ffa707e6..75d58d46 100644 --- a/morphlib/blobs_tests.py +++ b/morphlib/blobs_tests.py @@ -26,71 +26,71 @@ class BlobsTests(unittest.TestCase): blob2 = morphlib.blobs.Blob(None) blob3 = morphlib.blobs.Blob(None) - assert(len(blob1.parents) == 0) + self.assertEqual(len(blob1.parents), 0) blob1.add_parent(blob2) - assert(blob2 in blob1.parents) - assert(blob3 not in blob1.parents) - assert(len(blob1.parents) == 1) + self.assertIn(blob2, blob1.parents) + self.assertNotIn(blob3, blob1.parents) + self.assertEqual(len(blob1.parents), 1) blob1.add_parent(blob3) - assert(blob2 in blob1.parents) - assert(blob3 in blob1.parents) - assert(len(blob1.parents) == 2) + self.assertIn(blob2, blob1.parents) + self.assertIn(blob3, blob1.parents) + self.assertEqual(len(blob1.parents), 2) blob1.remove_parent(blob2) - assert(blob2 not in blob1.parents) - assert(blob3 in blob1.parents) - assert(len(blob1.parents) == 1) + self.assertNotIn(blob2, blob1.parents) + self.assertIn(blob3, blob1.parents) + self.assertEqual(len(blob1.parents), 1) blob1.remove_parent(blob3) - assert(blob2 not in blob1.parents) - assert(blob3 not in blob1.parents) - assert(len(blob1.parents) == 0) + self.assertNotIn(blob2, blob1.parents) + self.assertNotIn(blob3, blob1.parents) + self.assertEqual(len(blob1.parents), 0) def test_blob_add_remove_dependency(self): blob1 = morphlib.blobs.Blob(None) blob2 = morphlib.blobs.Blob(None) - assert(len(blob1.dependencies) == 0) - assert(len(blob2.dependencies) == 0) + self.assertEqual(len(blob1.dependencies), 0) + self.assertEqual(len(blob2.dependencies), 0) blob1.add_dependency(blob2) - assert(blob2 in blob1.dependencies) - assert(blob1 in blob2.dependents) + self.assertIn(blob2, blob1.dependencies) + self.assertIn(blob1, blob2.dependents) - assert(blob1.depends_on(blob2)) + self.assertTrue(blob1.depends_on(blob2)) blob2.add_dependency(blob1) - assert(blob2 in blob1.dependencies) - assert(blob1 in blob2.dependents) - assert(blob1 in blob2.dependencies) - assert(blob2 in blob1.dependents) + self.assertIn(blob2, blob1.dependencies) + self.assertIn(blob1, blob2.dependents) + self.assertIn(blob1, blob2.dependencies) + self.assertIn(blob2, blob1.dependents) - assert(blob1.depends_on(blob2)) - assert(blob2.depends_on(blob1)) + self.assertTrue(blob1.depends_on(blob2)) + self.assertTrue(blob2.depends_on(blob1)) blob1.remove_dependency(blob2) - assert(blob2 not in blob1.dependencies) - assert(blob1 not in blob2.dependents) - assert(blob1 in blob2.dependencies) - assert(blob2 in blob1.dependents) + self.assertNotIn(blob2, blob1.dependencies) + self.assertNotIn(blob1, blob2.dependents) + self.assertIn(blob1, blob2.dependencies) + self.assertIn(blob2, blob1.dependents) - assert(not blob1.depends_on(blob2)) - assert(blob2.depends_on(blob1)) + self.assertFalse(blob1.depends_on(blob2)) + self.assertTrue(blob2.depends_on(blob1)) blob2.remove_dependency(blob1) - assert(blob2 not in blob1.dependencies) - assert(blob1 not in blob2.dependents) - assert(blob1 not in blob2.dependencies) - assert(blob2 not in blob1.dependents) + self.assertNotIn(blob2, blob1.dependencies) + self.assertNotIn(blob1, blob2.dependents) + self.assertNotIn(blob1, blob2.dependencies) + self.assertNotIn(blob2, blob1.dependents) - assert(not blob1.depends_on(blob2)) - assert(not blob2.depends_on(blob1)) + self.assertFalse(blob1.depends_on(blob2)) + self.assertFalse(blob2.depends_on(blob1)) def test_chunks(self): settings = { 'git-base-url': '' } @@ -99,16 +99,16 @@ class BlobsTests(unittest.TestCase): stratum_morph = loader.load('repo', 'ref', 'foo.morph') stratum = morphlib.blobs.Stratum(stratum_morph) - assert(len(stratum.chunks) == 1) - assert('foo' in stratum.chunks) + self.assertEquals(len(stratum.chunks), 1) + self.assertIn('foo', stratum.chunks) self.assertEqual(['.'], stratum.chunks['foo']) chunk_morph = loader.load('repo', 'ref', 'bar.morph') chunk = morphlib.blobs.Chunk(chunk_morph) - assert(len(chunk.chunks) == 2) - assert('include' in chunk.chunks) + self.assertEqual(len(chunk.chunks), 2) + self.assertIn('include', chunk.chunks) self.assertEqual(chunk.chunks['include'], ['include/']) - assert('src' in chunk.chunks) + self.assertIn('src', chunk.chunks) self.assertEqual(chunk.chunks['src'], ['src/']) def get_morph_text(self, repo, ref, filename): diff --git a/morphlib/sourcemanager_tests.py b/morphlib/sourcemanager_tests.py index f769e60e..507ecf72 100644 --- a/morphlib/sourcemanager_tests.py +++ b/morphlib/sourcemanager_tests.py @@ -43,7 +43,7 @@ class SourceManagerTests(unittest.TestCase): s = morphlib.sourcemanager.SourceManager(tempdir, DummyApp()) t = s.get_treeish(os.getcwd(), '41ee528492db9bd41604311b100da5a871098b3a') - assert(t.sha1 == '41ee528492db9bd41604311b100da5a871098b3a') + self.assertEquals(t.sha1, '41ee528492db9bd41604311b100da5a871098b3a') shutil.rmtree(tempdir) @@ -53,12 +53,12 @@ class SourceManagerTests(unittest.TestCase): s = morphlib.sourcemanager.SourceManager(tempdir, DummyApp()) t = s.get_treeish(os.getcwd(), '41ee528492db9bd41604311b100da5a871098b3a') - assert(t.sha1 == '41ee528492db9bd41604311b100da5a871098b3a') + self.assertEquals(t.sha1, '41ee528492db9bd41604311b100da5a871098b3a') s = morphlib.sourcemanager.SourceManager(tempdir, DummyApp()) t = s.get_treeish(os.getcwd(), '41ee528492db9bd41604311b100da5a871098b3a') - assert(t.sha1 == '41ee528492db9bd41604311b100da5a871098b3a') + self.assertEquals(t.sha1, '41ee528492db9bd41604311b100da5a871098b3a') shutil.rmtree(tempdir) @@ -67,7 +67,7 @@ class SourceManagerTests(unittest.TestCase): s = morphlib.sourcemanager.SourceManager(tempdir, DummyApp()) t = s.get_treeish(os.getcwd(), 'master') - assert(t.ref == 'refs/heads/master') + self.assertEquals(t.ref, 'refs/heads/master') shutil.rmtree(tempdir) @@ -92,7 +92,7 @@ class SourceManagerTests(unittest.TestCase): t = s.get_treeish(os.getcwd(), '41ee528492db9bd41604311b100da5a871098b3a') - assert(t.sha1 == '41ee528492db9bd41604311b100da5a871098b3a') + self.assertEquals(t.sha1, '41ee528492db9bd41604311b100da5a871098b3a') shutil.rmtree(tempdir) @@ -124,6 +124,6 @@ class SourceManagerTests(unittest.TestCase): s = morphlib.sourcemanager.SourceManager(tempdir, app) t = s.get_treeish(os.getcwd(), '41ee528492db9bd41604311b100da5a871098b3a') - assert(t.sha1 == '41ee528492db9bd41604311b100da5a871098b3a') + self.assertEquals(t.sha1, '41ee528492db9bd41604311b100da5a871098b3a') shutil.rmtree(tempdir) diff --git a/morphlib/stopwatch_tests.py b/morphlib/stopwatch_tests.py index d4f1e3dd..58a18a36 100644 --- a/morphlib/stopwatch_tests.py +++ b/morphlib/stopwatch_tests.py @@ -30,23 +30,23 @@ class StopwatchTests(unittest.TestCase): def test_tick(self): self.stopwatch.tick('tick', 'a') - assert self.stopwatch.times('tick') - assert self.stopwatch.time('tick', 'a') - assert 'a' in self.stopwatch.times('tick') + self.assertTrue(self.stopwatch.times('tick')) + self.assertTrue(self.stopwatch.time('tick', 'a')) + self.assertIn('a', self.stopwatch.times('tick')) self.assertEqual(self.stopwatch.time('tick', 'a'), self.stopwatch.times('tick')['a']) now = datetime.datetime.now() - assert self.stopwatch.time('tick', 'a') < now + self.assertTrue(self.stopwatch.time('tick', 'a') < now) def test_start_stop(self): self.stopwatch.start('start-stop') - assert self.stopwatch.times('start-stop') - assert self.stopwatch.start_time('start-stop') + self.assertTrue(self.stopwatch.times('start-stop')) + self.assertTrue(self.stopwatch.start_time('start-stop')) self.stopwatch.stop('start-stop') - assert self.stopwatch.times('start-stop') - assert self.stopwatch.stop_time('start-stop') + self.assertTrue(self.stopwatch.times('start-stop')) + self.assertTrue(self.stopwatch.stop_time('start-stop')) start = self.stopwatch.start_time('start-stop') stop = self.stopwatch.stop_time('start-stop') @@ -55,7 +55,7 @@ class StopwatchTests(unittest.TestCase): watch_delta = self.stopwatch.start_stop_delta('start-stop') self.assertEqual(our_delta, watch_delta) - assert self.stopwatch.start_stop_seconds('start-stop') > 0 + self.assertTrue(self.stopwatch.start_stop_seconds('start-stop') > 0) def test_with(self): with self.stopwatch('foo'): |