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

Unified Diff: unittests/test_test.py

Issue 2850543002: Fix recipes.py test train when on-disk expectation files are invalid (Closed)
Patch Set: Created 3 years, 8 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 9ef908f2cbc8e600a7c9041f5df46e74446cda12..ab5216aae57d45a5c32264b5479f944402d65897 100755
--- a/unittests/test_test.py
+++ b/unittests/test_test.py
@@ -745,6 +745,46 @@ class TestTest(unittest.TestCase):
expect_contents)
self.assertEqual(self.json_generator.get(), self.json_contents)
+ def test_train_invaid_json(self):
+ # 1. Initial state: recipe expectations are passing.
+ rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
+ rw.RunStepsLines = ['pass']
+ rw.add_expectation('basic')
+ rw.write()
+ self._run_recipes('test', 'run', '--json', self.json_path)
+ self.assertEqual(self.json_generator.get(), self.json_contents)
+
+ # 2. Change the expectation and verify tests would fail.
+ expect_path = os.path.join(rw.expect_dir, 'basic.json')
+ with open(expect_path, 'w') as f:
+ f.write('\n'.join([
+ 'not valid JSON',
+ '<<<<<',
+ 'merge conflict',
+ '>>>>>',
+ ]))
+ with self.assertRaises(subprocess.CalledProcessError) as cm:
+ self._run_recipes('test', 'run', '--json', self.json_path)
+ self.assertIn('foo.basic failed', cm.exception.output)
+ self.assertEqual(
+ self.json_generator
+ .internal_failure('foo.basic')
+ .invalid()
+ .unused_expectation('recipes/foo.expected')
+ .unused_expectation('recipes/foo.expected/basic.json')
+ .coverage_failure('recipes/foo.py', [6])
+ .get(),
+ self.json_contents)
+
+ # 3. Make sure training the recipe succeeds and produces correct results.
+ self._run_recipes('test', 'train', '--json', self.json_path)
+ with open(expect_path) as f:
+ expect_contents = json.load(f)
+ self.assertEqual(
+ [{u'status_code': 0, u'recipe_result': None, u'name': u'$result'}],
+ expect_contents)
+ self.assertEqual(self.json_generator.get(), self.json_contents)
+
def test_train_checks_coverage(self):
rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
rw.RunStepsLines = ['if False:', ' pass']
« 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