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

Unified Diff: unittests/test_test.py

Issue 2758923002: Handle unused recipe expectations in new 'test' command (Closed)
Patch Set: fixes Created 3 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « recipe_engine/test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: unittests/test_test.py
diff --git a/unittests/test_test.py b/unittests/test_test.py
index 11bf5d276b9ffd37c716c9fb53c014a172574a02..30e416e4cde79cadb4d35f0da4ddc275273a2af0 100755
--- a/unittests/test_test.py
+++ b/unittests/test_test.py
@@ -449,6 +449,116 @@ class TestTest(unittest.TestCase):
self.assertIn('CHECK(FAIL)', cm.exception.output)
self.assertIn('foo.basic failed', cm.exception.output)
+ def test_unused_expectation_file_test(self):
+ rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
+ rw.RunStepsLines = ['pass']
+ rw.add_expectation('basic')
+ rw.add_expectation('unused')
+ rw.write()
+ expectation_file = os.path.join(rw.expect_dir, 'unused.json')
+ self.assertTrue(os.path.exists(expectation_file))
+ with self.assertRaises(subprocess.CalledProcessError) as cm:
+ self._run_recipes('test', 'run')
+ self.assertIn(
+ 'FATAL: unused expectations found:\n%s' % expectation_file,
+ cm.exception.output)
+ self.assertTrue(os.path.exists(expectation_file))
+
+ def test_unused_expectation_file_train(self):
+ rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
+ rw.RunStepsLines = ['pass']
+ rw.add_expectation('basic')
+ rw.add_expectation('unused')
+ rw.write()
+ expectation_file = os.path.join(rw.expect_dir, 'unused.json')
+ self.assertTrue(os.path.exists(expectation_file))
+ self._run_recipes('test', 'run', '--train')
+ self.assertFalse(os.path.exists(expectation_file))
+
+ def test_drop_expectation_test(self):
+ rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
+ rw.RunStepsLines = ['pass']
+ rw.GenTestsLines = [
+ 'yield api.test("basic") + \\',
+ ' api.post_process(post_process.DropExpectation)'
+ ]
+ rw.write()
+ expectation_file = os.path.join(rw.expect_dir, 'basic.json')
+ self.assertFalse(os.path.exists(expectation_file))
+ self._run_recipes('test', 'run')
+ self.assertFalse(os.path.exists(expectation_file))
+
+ def test_drop_expectation_train(self):
+ rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
+ rw.RunStepsLines = ['pass']
+ rw.GenTestsLines = [
+ 'yield api.test("basic") + \\',
+ ' api.post_process(post_process.DropExpectation)'
+ ]
+ rw.write()
+ expectation_file = os.path.join(rw.expect_dir, 'basic.json')
+ self.assertFalse(os.path.exists(expectation_file))
+ self._run_recipes('test', 'run', '--train')
+ self.assertFalse(os.path.exists(expectation_file))
+
+ def test_drop_expectation_test_unused(self):
+ rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
+ rw.RunStepsLines = ['pass']
+ rw.GenTestsLines = [
+ 'yield api.test("basic") + \\',
+ ' api.post_process(post_process.DropExpectation)'
+ ]
+ rw.add_expectation('basic')
+ rw.write()
+ expectation_file = os.path.join(rw.expect_dir, 'basic.json')
+ self.assertTrue(os.path.exists(expectation_file))
+ with self.assertRaises(subprocess.CalledProcessError) as cm:
+ self._run_recipes('test', 'run')
+ self.assertIn(
+ 'FATAL: unused expectations found:\n%s\n%s' % (
+ rw.expect_dir, expectation_file),
+ cm.exception.output)
+ self.assertTrue(os.path.exists(expectation_file))
+
+ def test_drop_expectation_train_unused(self):
+ rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
+ rw.RunStepsLines = ['pass']
+ rw.GenTestsLines = [
+ 'yield api.test("basic") + \\',
+ ' api.post_process(post_process.DropExpectation)'
+ ]
+ rw.add_expectation('basic')
+ rw.write()
+ expectation_file = os.path.join(rw.expect_dir, 'basic.json')
+ self.assertTrue(os.path.exists(expectation_file))
+ self._run_recipes('test', 'run', '--train')
+ self.assertFalse(os.path.exists(expectation_file))
+ self.assertFalse(os.path.exists(rw.expect_dir))
+
+ def test_unused_expectation_preserves_owners_test(self):
+ rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
+ rw.RunStepsLines = ['pass']
+ rw.add_expectation('basic')
+ rw.write()
+ owners_file = os.path.join(rw.expect_dir, 'OWNERS')
+ with open(owners_file, 'w') as f:
+ pass
+ self.assertTrue(os.path.exists(owners_file))
+ self._run_recipes('test', 'run')
+ self.assertTrue(os.path.exists(owners_file))
+
+ def test_unused_expectation_preserves_owners_train(self):
+ rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
+ rw.RunStepsLines = ['pass']
+ rw.add_expectation('basic')
+ rw.write()
+ owners_file = os.path.join(rw.expect_dir, 'OWNERS')
+ with open(owners_file, 'w') as f:
+ pass
+ self.assertTrue(os.path.exists(owners_file))
+ self._run_recipes('test', 'run', '--train')
+ self.assertTrue(os.path.exists(owners_file))
+
if __name__ == '__main__':
sys.exit(unittest.main())
« no previous file with comments | « recipe_engine/test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698