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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « recipe_engine/test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2017 The LUCI Authors. All rights reserved. 2 # Copyright 2017 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 import json 6 import json
7 import os 7 import os
8 import shutil 8 import shutil
9 import subprocess 9 import subprocess
10 import sys 10 import sys
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 ' api.post_process(post_process.MustRun, "bar")' 442 ' api.post_process(post_process.MustRun, "bar")'
443 ] 443 ]
444 rw.add_expectation('basic') 444 rw.add_expectation('basic')
445 rw.write() 445 rw.write()
446 with self.assertRaises(subprocess.CalledProcessError) as cm: 446 with self.assertRaises(subprocess.CalledProcessError) as cm:
447 self._run_recipes('test', 'run', '--train') 447 self._run_recipes('test', 'run', '--train')
448 self.assertNotIn('FATAL: Insufficient coverage', cm.exception.output) 448 self.assertNotIn('FATAL: Insufficient coverage', cm.exception.output)
449 self.assertIn('CHECK(FAIL)', cm.exception.output) 449 self.assertIn('CHECK(FAIL)', cm.exception.output)
450 self.assertIn('foo.basic failed', cm.exception.output) 450 self.assertIn('foo.basic failed', cm.exception.output)
451 451
452 def test_unused_expectation_file_test(self):
453 rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
454 rw.RunStepsLines = ['pass']
455 rw.add_expectation('basic')
456 rw.add_expectation('unused')
457 rw.write()
458 expectation_file = os.path.join(rw.expect_dir, 'unused.json')
459 self.assertTrue(os.path.exists(expectation_file))
460 with self.assertRaises(subprocess.CalledProcessError) as cm:
461 self._run_recipes('test', 'run')
462 self.assertIn(
463 'FATAL: unused expectations found:\n%s' % expectation_file,
464 cm.exception.output)
465 self.assertTrue(os.path.exists(expectation_file))
466
467 def test_unused_expectation_file_train(self):
468 rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
469 rw.RunStepsLines = ['pass']
470 rw.add_expectation('basic')
471 rw.add_expectation('unused')
472 rw.write()
473 expectation_file = os.path.join(rw.expect_dir, 'unused.json')
474 self.assertTrue(os.path.exists(expectation_file))
475 self._run_recipes('test', 'run', '--train')
476 self.assertFalse(os.path.exists(expectation_file))
477
478 def test_drop_expectation_test(self):
479 rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
480 rw.RunStepsLines = ['pass']
481 rw.GenTestsLines = [
482 'yield api.test("basic") + \\',
483 ' api.post_process(post_process.DropExpectation)'
484 ]
485 rw.write()
486 expectation_file = os.path.join(rw.expect_dir, 'basic.json')
487 self.assertFalse(os.path.exists(expectation_file))
488 self._run_recipes('test', 'run')
489 self.assertFalse(os.path.exists(expectation_file))
490
491 def test_drop_expectation_train(self):
492 rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
493 rw.RunStepsLines = ['pass']
494 rw.GenTestsLines = [
495 'yield api.test("basic") + \\',
496 ' api.post_process(post_process.DropExpectation)'
497 ]
498 rw.write()
499 expectation_file = os.path.join(rw.expect_dir, 'basic.json')
500 self.assertFalse(os.path.exists(expectation_file))
501 self._run_recipes('test', 'run', '--train')
502 self.assertFalse(os.path.exists(expectation_file))
503
504 def test_drop_expectation_test_unused(self):
505 rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
506 rw.RunStepsLines = ['pass']
507 rw.GenTestsLines = [
508 'yield api.test("basic") + \\',
509 ' api.post_process(post_process.DropExpectation)'
510 ]
511 rw.add_expectation('basic')
512 rw.write()
513 expectation_file = os.path.join(rw.expect_dir, 'basic.json')
514 self.assertTrue(os.path.exists(expectation_file))
515 with self.assertRaises(subprocess.CalledProcessError) as cm:
516 self._run_recipes('test', 'run')
517 self.assertIn(
518 'FATAL: unused expectations found:\n%s\n%s' % (
519 rw.expect_dir, expectation_file),
520 cm.exception.output)
521 self.assertTrue(os.path.exists(expectation_file))
522
523 def test_drop_expectation_train_unused(self):
524 rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
525 rw.RunStepsLines = ['pass']
526 rw.GenTestsLines = [
527 'yield api.test("basic") + \\',
528 ' api.post_process(post_process.DropExpectation)'
529 ]
530 rw.add_expectation('basic')
531 rw.write()
532 expectation_file = os.path.join(rw.expect_dir, 'basic.json')
533 self.assertTrue(os.path.exists(expectation_file))
534 self._run_recipes('test', 'run', '--train')
535 self.assertFalse(os.path.exists(expectation_file))
536 self.assertFalse(os.path.exists(rw.expect_dir))
537
538 def test_unused_expectation_preserves_owners_test(self):
539 rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
540 rw.RunStepsLines = ['pass']
541 rw.add_expectation('basic')
542 rw.write()
543 owners_file = os.path.join(rw.expect_dir, 'OWNERS')
544 with open(owners_file, 'w') as f:
545 pass
546 self.assertTrue(os.path.exists(owners_file))
547 self._run_recipes('test', 'run')
548 self.assertTrue(os.path.exists(owners_file))
549
550 def test_unused_expectation_preserves_owners_train(self):
551 rw = RecipeWriter(os.path.join(self._root_dir, 'recipes'), 'foo')
552 rw.RunStepsLines = ['pass']
553 rw.add_expectation('basic')
554 rw.write()
555 owners_file = os.path.join(rw.expect_dir, 'OWNERS')
556 with open(owners_file, 'w') as f:
557 pass
558 self.assertTrue(os.path.exists(owners_file))
559 self._run_recipes('test', 'run', '--train')
560 self.assertTrue(os.path.exists(owners_file))
561
452 562
453 if __name__ == '__main__': 563 if __name__ == '__main__':
454 sys.exit(unittest.main()) 564 sys.exit(unittest.main())
OLDNEW
« 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