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

Unified Diff: recipe_engine/unittests/test_test.py

Issue 2844133004: [test] add tests for test subcommand parsing. (Closed)
Patch Set: rebarse 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_engine/unittests/test_test.py
diff --git a/recipe_engine/unittests/test_test.py b/recipe_engine/unittests/test_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..d5501ddb0c38b3caa8b6ba6fd35c14f458df0ec2
--- /dev/null
+++ b/recipe_engine/unittests/test_test.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# Copyright 2017 The LUCI Authors. All rights reserved.
+# Use of this source code is governed under the Apache License, Version 2.0
+# that can be found in the LICENSE file.
+
+import os
+import sys
+import tempfile
+import unittest
+
+from cStringIO import StringIO
+
+import test_env
+
+import argparse # this is vendored
+
+import mock
+
+from recipe_engine import test
+from recipe_engine import common_args
+
+
+class TestArgs(unittest.TestCase):
+ def setUp(self):
+ self.p = argparse.ArgumentParser()
+ self.followup = common_args.add_common_args(self.p)
+ subp = self.p.add_subparsers()
+ test.add_subparser(subp)
+
+ @mock.patch('argparse._sys.stderr', new_callable=StringIO)
+ def test_normalize_filter(self, stderr):
+ with self.assertRaises(SystemExit):
+ args = self.p.parse_args(['test', 'run', '--filter', ''])
+ args.postprocess_func(self.p, args)
+ self.assertIn('empty filters not allowed', stderr.getvalue())
+
+ stderr.reset()
+ args = self.p.parse_args(['test', 'run', '--filter', 'foo'])
+ args.postprocess_func(self.p, args)
+ self.assertEqual(args.filter, ['foo*.*'])
+
+ stderr.reset()
+ args = self.p.parse_args(['test', 'run', '--filter', 'foo.bar'])
+ args.postprocess_func(self.p, args)
+ self.assertEqual(args.filter, ['foo.bar'])
+
+ def test_automatic_bootstrap(self):
+ with tempfile.NamedTemporaryFile('w', delete=False) as tf:
+ tf.write("""{
+ "api_version": 2,
+ "project_id": "fake",
+ }""")
+
+ try:
+ args = self.p.parse_args(['--package', tf.name, 'test', 'run'])
+ self.assertIsNone(args.use_bootstrap)
+ self.followup(self.p, args)
+ args.postprocess_func(self.p, args)
+ self.assertTrue(args.use_bootstrap)
+ finally:
+ os.remove(tf.name)
+
+
+if __name__ == '__main__':
+ sys.exit(unittest.main())
+
« 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