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

Side by Side Diff: recipe_engine/unittests/test_test.py

Issue 2844133004: [test] add tests for test subcommand parsing. (Closed)
Patch Set: rebarse Created 3 years, 7 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 | « no previous file | 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
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2017 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file.
5
6 import os
7 import sys
8 import tempfile
9 import unittest
10
11 from cStringIO import StringIO
12
13 import test_env
14
15 import argparse # this is vendored
16
17 import mock
18
19 from recipe_engine import test
20 from recipe_engine import common_args
21
22
23 class TestArgs(unittest.TestCase):
24 def setUp(self):
25 self.p = argparse.ArgumentParser()
26 self.followup = common_args.add_common_args(self.p)
27 subp = self.p.add_subparsers()
28 test.add_subparser(subp)
29
30 @mock.patch('argparse._sys.stderr', new_callable=StringIO)
31 def test_normalize_filter(self, stderr):
32 with self.assertRaises(SystemExit):
33 args = self.p.parse_args(['test', 'run', '--filter', ''])
34 args.postprocess_func(self.p, args)
35 self.assertIn('empty filters not allowed', stderr.getvalue())
36
37 stderr.reset()
38 args = self.p.parse_args(['test', 'run', '--filter', 'foo'])
39 args.postprocess_func(self.p, args)
40 self.assertEqual(args.filter, ['foo*.*'])
41
42 stderr.reset()
43 args = self.p.parse_args(['test', 'run', '--filter', 'foo.bar'])
44 args.postprocess_func(self.p, args)
45 self.assertEqual(args.filter, ['foo.bar'])
46
47 def test_automatic_bootstrap(self):
48 with tempfile.NamedTemporaryFile('w', delete=False) as tf:
49 tf.write("""{
50 "api_version": 2,
51 "project_id": "fake",
52 }""")
53
54 try:
55 args = self.p.parse_args(['--package', tf.name, 'test', 'run'])
56 self.assertIsNone(args.use_bootstrap)
57 self.followup(self.p, args)
58 args.postprocess_func(self.p, args)
59 self.assertTrue(args.use_bootstrap)
60 finally:
61 os.remove(tf.name)
62
63
64 if __name__ == '__main__':
65 sys.exit(unittest.main())
66
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698