Chromium Code Reviews| Index: expect_tests/test/pipeline_test.py |
| diff --git a/expect_tests/test/pipeline_test.py b/expect_tests/test/pipeline_test.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5e622f312b5c9f7a7572b2ae2c6b526bef3af07e |
| --- /dev/null |
| +++ b/expect_tests/test/pipeline_test.py |
| @@ -0,0 +1,186 @@ |
| +import os |
| +import unittest |
| + |
| +from expect_tests import pipeline |
| + |
| +SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) |
| + |
| + |
| +class ParsingAndConfigTest(unittest.TestCase): |
| + def test_get_config(self): |
| + """Testing that reading the config file works. Tests requires a specific |
| + content for data/.expect_tests.cfg""" |
| + path = os.path.join(SCRIPT_DIR, 'data') |
| + black_list = pipeline.get_config(path) |
| + self.assertEqual(black_list, |
| + set(['directory1', 'directory2', 'ignored'])) |
| + |
| + def test_parse_test_glob(self): |
| + self.assertEqual(pipeline.parse_test_glob('a/b/c'), |
| + (os.path.abspath('a/b/c'), '*')) |
| + self.assertEqual(pipeline.parse_test_glob('a/b/c:'), |
| + (os.path.abspath('a/b/c'), '*')) |
| + self.assertEqual(pipeline.parse_test_glob('a/b/c:Test'), |
| + (os.path.abspath('a/b/c'), 'Test')) |
| + self.assertEqual(pipeline.parse_test_glob('a/b/c:Test.Name'), |
| + (os.path.abspath('a/b/c'), 'Test.Name')) |
| + self.assertRaises(ValueError, pipeline.parse_test_glob, 'a:b:c',) |
| + self.assertRaises(ValueError, pipeline.parse_test_glob, 'a:b/c',) |
| + |
| + |
| +class PathManipulationTest(unittest.TestCase): |
| + """Tests for all path-manipulating functions. |
| + |
| + This set uses checked-out files in the present repository to avoid mocking |
| + the I/O functions. |
|
iannucci
2014/11/12 20:26:24
+1 :)
You could also have done a setUpClass sort
pgervais
2014/11/13 17:55:47
I replied to this elsewhere: the less I touch the
|
| + """ |
| + |
| + def test_get_python_root(self): |
| + """This function uses the directory structure under data/""" |
| + data_dir = os.path.join(SCRIPT_DIR, 'data') |
| + self.assertEqual(pipeline.get_python_root(data_dir), data_dir) |
| + self.assertEqual(pipeline.get_python_root( |
| + os.path.join(data_dir, 'package1')), data_dir) |
| + self.assertEqual(pipeline.get_python_root( |
| + os.path.join(data_dir, 'package1', 'subpackage1_1')), data_dir) |
| + self.assertRaises(ValueError, pipeline.get_python_root, |
| + '____non-existing-path____') |
|
iannucci
2014/11/12 20:26:24
this isn't meant to be a python identifier, is it?
pgervais
2014/11/13 17:55:47
It is meant to be a filename. Nothing is loaded by
|
| + |
| + def test_get_runtime_context(self): |
| + """Test the get_runtime_context function""" |
| + datadir = os.path.join(SCRIPT_DIR, 'data') |
| + |
| + # Single directory case |
| + test_globs = [datadir] |
| + contexts = pipeline.get_runtime_contexts(test_globs) |
| + self.assertEqual(len(contexts), 1) |
| + self.assertEqual(contexts[0].cwd, datadir) |
| + for testing_c in contexts[0].testing_contexts: |
| + self.assertNotEqual(testing_c.package_name, 'ignored') |
| + |
| + # Single package |
| + test_globs = [os.path.join(datadir, 'package1')] |
| + contexts = pipeline.get_runtime_contexts(test_globs) |
| + self.assertEqual(len(contexts), 1) |
| + self.assertEqual(contexts[0].cwd, datadir) |
| + testing_c = contexts[0].testing_contexts |
| + self.assertEqual(len(testing_c), 1) |
| + self.assertEqual(testing_c[0].package_name, 'package1') |
| + |
| + # Two packages in the same directory |
| + test_globs = [os.path.join(datadir, 'package1'), |
| + os.path.join(datadir, 'package2')] |
| + contexts = pipeline.get_runtime_contexts(test_globs) |
| + self.assertEqual(len(contexts), 1) |
| + self.assertEqual(contexts[0].cwd, datadir) |
| + testing_c = contexts[0].testing_contexts |
| + self.assertEqual(len(testing_c), 2) |
| + package_names = set() |
| + for testing_c in contexts[0].testing_contexts: |
| + package_names.add(testing_c.package_name) |
| + |
| + self.assertEqual(package_names, set(('package1', 'package2'))) |
| + |
| + # Packages inside directory |
| + test_globs = [datadir, os.path.join(datadir, 'package1')] |
| + contexts = pipeline.get_runtime_contexts(test_globs) |
| + self.assertEqual(len(contexts), 1) |
| + # 2 is the number of packages under datadir, not counting |
| + # the ignored ones. |
| + self.assertEqual(len(contexts[0].testing_contexts), 2) |
| + |
| + test_globs = [datadir, os.path.join(datadir, 'package1'), |
| + os.path.join(datadir, 'package1', 'subpackage1_1')] |
| + contexts = pipeline.get_runtime_contexts(test_globs) |
| + self.assertEqual(len(contexts), 1) |
| + self.assertEqual(len(contexts[0].testing_contexts), 2) |
| + |
| + |
| + def test_package_testing_context(self): |
| + """Test the PackageTestingContext class""" |
| + package_name = 'package1' |
| + package1 = os.path.join(SCRIPT_DIR, 'data', package_name) |
| + package2 = os.path.join(SCRIPT_DIR, 'data', 'package2') |
| + other_package1 = os.path.join(SCRIPT_DIR, 'data', 'other', package_name) |
| + |
| + # from_path |
| + context = pipeline.PackageTestingContext.from_path(package1) |
| + self.assertTrue(os.path.isabs(context.cwd)) |
| + self.assertTrue(len(context.package_name) > 0) |
| + self.assertEqual(len(context.filters), 1) |
| + self.assertEqual(context.filters[0][1], '*') |
| + |
| + context = pipeline.PackageTestingContext.from_path(package1, |
| + filters='*') |
| + self.assertTrue(os.path.isabs(context.cwd)) |
| + self.assertTrue(len(context.package_name) > 0) |
| + self.assertEqual(len(context.filters), 1) |
| + self.assertEqual(context.filters[0][1], '*') |
|
iannucci
2014/11/12 20:26:24
it wouldn't be possible to break this function up
pgervais
2014/11/13 17:55:47
Done.
|
| + |
| + context = pipeline.PackageTestingContext.from_path(package1, |
| + filters=('a*', 'b*')) |
| + self.assertTrue(os.path.isabs(context.cwd)) |
| + self.assertTrue(len(context.package_name) > 0) |
| + self.assertEqual(len(context.filters), 2) |
| + self.assertEqual(context.filters[0][1], 'a*') |
| + self.assertEqual(context.filters[1][1], 'b*') |
| + |
| + # from_context_list |
| + c1 = pipeline.PackageTestingContext.from_path(package1, filters='a') |
| + c2 = pipeline.PackageTestingContext.from_path(package1, filters=('b','c')) |
| + context = pipeline.PackageTestingContext.from_context_list((c1, c2)) |
| + self.assertEqual(len(context.filters), 3) |
| + self.assertEqual(set(filt[1] for filt in context.filters), |
| + set(('a', 'b', 'c'))) |
| + |
| + c1 = pipeline.PackageTestingContext.from_path(package1, filters='a') |
| + c2 = pipeline.PackageTestingContext.from_path(package2, filters=('b','c')) |
| + self.assertRaises(AssertionError, |
| + pipeline.PackageTestingContext.from_context_list, |
| + (c1, c2)) |
| + |
| + # Same package name, different paths. |
| + c1 = pipeline.PackageTestingContext.from_path(package1, filters='a') |
| + c2 = pipeline.PackageTestingContext.from_path(other_package1, |
| + filters=('b','c')) |
| + self.assertRaises(AssertionError, |
| + pipeline.PackageTestingContext.from_context_list, |
| + (c1, c2)) |
| + |
| + |
| + def test_processing_context(self): |
| + """Test the ProcessingContext class""" |
| + package_name = 'package1' |
| + package1 = os.path.join(SCRIPT_DIR, 'data', package_name) |
| + subpackage1 = os.path.join(SCRIPT_DIR, 'data', |
| + package_name, 'subpackage1_1') |
| + package2 = os.path.join(SCRIPT_DIR, 'data', 'package2') |
| + other_package1 = os.path.join(SCRIPT_DIR, 'data', 'other', package_name) |
| + |
| + c0 = pipeline.PackageTestingContext.from_path(package1) |
| + c1 = pipeline.PackageTestingContext.from_path(package1, filters='a') |
| + c2 = pipeline.PackageTestingContext.from_path(subpackage1, filters='d') |
| + c3 = pipeline.PackageTestingContext.from_path(package2, filters=('b','c')) |
| + c4 = pipeline.PackageTestingContext.from_path(other_package1) |
| + |
| + # A processing context is a cwd + testing contexts. |
| + # A testing context is cwd + one package name. |
| + context = pipeline.ProcessingContext((c1, c2)) |
| + self.assertEqual(len(context.testing_contexts), 1) |
| + self.assertEqual(set(filt[1] |
| + for filt in context.testing_contexts[0].filters), |
| + set(('a', 'd'))) |
| + |
| + context = pipeline.ProcessingContext((c0, c1, c2)) |
| + self.assertEqual(len(context.testing_contexts), 1) |
| + self.assertEqual(set(filt[1] |
| + for filt in context.testing_contexts[0].filters), |
| + set(('*', 'a', 'd'))) |
| + |
| + |
| + context = pipeline.ProcessingContext((c1, c2, c3)) |
| + self.assertEqual(len(context.testing_contexts), 2) |
| + |
| + # Fails because there are two different cwd. |
| + self.assertRaises(ValueError, pipeline.ProcessingContext, (c1, c4)) |
| + |