Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: expect_tests/test/pipeline_test.py

Issue 709853003: New expect_tests UI (Closed) Base URL: https://chromium.googlesource.com/infra/testing/expect_tests@shebang
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 import os
2 import unittest
3
4 from expect_tests import pipeline
5
6 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
7
8
9 class ParsingAndConfigTest(unittest.TestCase):
10 def test_get_config(self):
11 """Testing that reading the config file works. Tests requires a specific
12 content for data/.expect_tests.cfg"""
13 path = os.path.join(SCRIPT_DIR, 'data')
14 black_list = pipeline.get_config(path)
15 self.assertEqual(black_list,
16 set(['directory1', 'directory2', 'ignored']))
17
18 def test_parse_test_glob(self):
19 self.assertEqual(pipeline.parse_test_glob('a/b/c'),
20 (os.path.abspath('a/b/c'), '*'))
21 self.assertEqual(pipeline.parse_test_glob('a/b/c:'),
22 (os.path.abspath('a/b/c'), '*'))
23 self.assertEqual(pipeline.parse_test_glob('a/b/c:Test'),
24 (os.path.abspath('a/b/c'), 'Test'))
25 self.assertEqual(pipeline.parse_test_glob('a/b/c:Test.Name'),
26 (os.path.abspath('a/b/c'), 'Test.Name'))
27 self.assertRaises(ValueError, pipeline.parse_test_glob, 'a:b:c',)
28 self.assertRaises(ValueError, pipeline.parse_test_glob, 'a:b/c',)
29
30
31 class PathManipulationTest(unittest.TestCase):
32 """Tests for all path-manipulating functions.
33
34 This set uses checked-out files in the present repository to avoid mocking
35 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
36 """
37
38 def test_get_python_root(self):
39 """This function uses the directory structure under data/"""
40 data_dir = os.path.join(SCRIPT_DIR, 'data')
41 self.assertEqual(pipeline.get_python_root(data_dir), data_dir)
42 self.assertEqual(pipeline.get_python_root(
43 os.path.join(data_dir, 'package1')), data_dir)
44 self.assertEqual(pipeline.get_python_root(
45 os.path.join(data_dir, 'package1', 'subpackage1_1')), data_dir)
46 self.assertRaises(ValueError, pipeline.get_python_root,
47 '____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
48
49 def test_get_runtime_context(self):
50 """Test the get_runtime_context function"""
51 datadir = os.path.join(SCRIPT_DIR, 'data')
52
53 # Single directory case
54 test_globs = [datadir]
55 contexts = pipeline.get_runtime_contexts(test_globs)
56 self.assertEqual(len(contexts), 1)
57 self.assertEqual(contexts[0].cwd, datadir)
58 for testing_c in contexts[0].testing_contexts:
59 self.assertNotEqual(testing_c.package_name, 'ignored')
60
61 # Single package
62 test_globs = [os.path.join(datadir, 'package1')]
63 contexts = pipeline.get_runtime_contexts(test_globs)
64 self.assertEqual(len(contexts), 1)
65 self.assertEqual(contexts[0].cwd, datadir)
66 testing_c = contexts[0].testing_contexts
67 self.assertEqual(len(testing_c), 1)
68 self.assertEqual(testing_c[0].package_name, 'package1')
69
70 # Two packages in the same directory
71 test_globs = [os.path.join(datadir, 'package1'),
72 os.path.join(datadir, 'package2')]
73 contexts = pipeline.get_runtime_contexts(test_globs)
74 self.assertEqual(len(contexts), 1)
75 self.assertEqual(contexts[0].cwd, datadir)
76 testing_c = contexts[0].testing_contexts
77 self.assertEqual(len(testing_c), 2)
78 package_names = set()
79 for testing_c in contexts[0].testing_contexts:
80 package_names.add(testing_c.package_name)
81
82 self.assertEqual(package_names, set(('package1', 'package2')))
83
84 # Packages inside directory
85 test_globs = [datadir, os.path.join(datadir, 'package1')]
86 contexts = pipeline.get_runtime_contexts(test_globs)
87 self.assertEqual(len(contexts), 1)
88 # 2 is the number of packages under datadir, not counting
89 # the ignored ones.
90 self.assertEqual(len(contexts[0].testing_contexts), 2)
91
92 test_globs = [datadir, os.path.join(datadir, 'package1'),
93 os.path.join(datadir, 'package1', 'subpackage1_1')]
94 contexts = pipeline.get_runtime_contexts(test_globs)
95 self.assertEqual(len(contexts), 1)
96 self.assertEqual(len(contexts[0].testing_contexts), 2)
97
98
99 def test_package_testing_context(self):
100 """Test the PackageTestingContext class"""
101 package_name = 'package1'
102 package1 = os.path.join(SCRIPT_DIR, 'data', package_name)
103 package2 = os.path.join(SCRIPT_DIR, 'data', 'package2')
104 other_package1 = os.path.join(SCRIPT_DIR, 'data', 'other', package_name)
105
106 # from_path
107 context = pipeline.PackageTestingContext.from_path(package1)
108 self.assertTrue(os.path.isabs(context.cwd))
109 self.assertTrue(len(context.package_name) > 0)
110 self.assertEqual(len(context.filters), 1)
111 self.assertEqual(context.filters[0][1], '*')
112
113 context = pipeline.PackageTestingContext.from_path(package1,
114 filters='*')
115 self.assertTrue(os.path.isabs(context.cwd))
116 self.assertTrue(len(context.package_name) > 0)
117 self.assertEqual(len(context.filters), 1)
118 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.
119
120 context = pipeline.PackageTestingContext.from_path(package1,
121 filters=('a*', 'b*'))
122 self.assertTrue(os.path.isabs(context.cwd))
123 self.assertTrue(len(context.package_name) > 0)
124 self.assertEqual(len(context.filters), 2)
125 self.assertEqual(context.filters[0][1], 'a*')
126 self.assertEqual(context.filters[1][1], 'b*')
127
128 # from_context_list
129 c1 = pipeline.PackageTestingContext.from_path(package1, filters='a')
130 c2 = pipeline.PackageTestingContext.from_path(package1, filters=('b','c'))
131 context = pipeline.PackageTestingContext.from_context_list((c1, c2))
132 self.assertEqual(len(context.filters), 3)
133 self.assertEqual(set(filt[1] for filt in context.filters),
134 set(('a', 'b', 'c')))
135
136 c1 = pipeline.PackageTestingContext.from_path(package1, filters='a')
137 c2 = pipeline.PackageTestingContext.from_path(package2, filters=('b','c'))
138 self.assertRaises(AssertionError,
139 pipeline.PackageTestingContext.from_context_list,
140 (c1, c2))
141
142 # Same package name, different paths.
143 c1 = pipeline.PackageTestingContext.from_path(package1, filters='a')
144 c2 = pipeline.PackageTestingContext.from_path(other_package1,
145 filters=('b','c'))
146 self.assertRaises(AssertionError,
147 pipeline.PackageTestingContext.from_context_list,
148 (c1, c2))
149
150
151 def test_processing_context(self):
152 """Test the ProcessingContext class"""
153 package_name = 'package1'
154 package1 = os.path.join(SCRIPT_DIR, 'data', package_name)
155 subpackage1 = os.path.join(SCRIPT_DIR, 'data',
156 package_name, 'subpackage1_1')
157 package2 = os.path.join(SCRIPT_DIR, 'data', 'package2')
158 other_package1 = os.path.join(SCRIPT_DIR, 'data', 'other', package_name)
159
160 c0 = pipeline.PackageTestingContext.from_path(package1)
161 c1 = pipeline.PackageTestingContext.from_path(package1, filters='a')
162 c2 = pipeline.PackageTestingContext.from_path(subpackage1, filters='d')
163 c3 = pipeline.PackageTestingContext.from_path(package2, filters=('b','c'))
164 c4 = pipeline.PackageTestingContext.from_path(other_package1)
165
166 # A processing context is a cwd + testing contexts.
167 # A testing context is cwd + one package name.
168 context = pipeline.ProcessingContext((c1, c2))
169 self.assertEqual(len(context.testing_contexts), 1)
170 self.assertEqual(set(filt[1]
171 for filt in context.testing_contexts[0].filters),
172 set(('a', 'd')))
173
174 context = pipeline.ProcessingContext((c0, c1, c2))
175 self.assertEqual(len(context.testing_contexts), 1)
176 self.assertEqual(set(filt[1]
177 for filt in context.testing_contexts[0].filters),
178 set(('*', 'a', 'd')))
179
180
181 context = pipeline.ProcessingContext((c1, c2, c3))
182 self.assertEqual(len(context.testing_contexts), 2)
183
184 # Fails because there are two different cwd.
185 self.assertRaises(ValueError, pipeline.ProcessingContext, (c1, c4))
186
OLDNEW
« expect_tests/pipeline.py ('K') | « expect_tests/test/data/package2/__init__.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698