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

Unified Diff: recipe_engine/unittests/autoroll_test.py

Issue 2841373002: [autoroll] add tests for autoroll subcommand parsing. (Closed)
Patch Set: close file 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/autoroll.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_engine/unittests/autoroll_test.py
diff --git a/recipe_engine/unittests/autoroll_test.py b/recipe_engine/unittests/autoroll_test.py
index 49efa8bb389a1a9a822396ca4d4141b8972e3390..831f5b81c4172c9d73c0f383b18a13869580e319 100755
--- a/recipe_engine/unittests/autoroll_test.py
+++ b/recipe_engine/unittests/autoroll_test.py
@@ -3,12 +3,20 @@
# 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 autoroll
+from recipe_engine import common_args
def process_rejected(rejected_candidates):
return [c.to_dict() for c in rejected_candidates]
@@ -42,5 +50,37 @@ class TestProcess(unittest.TestCase):
]))
+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()
+ autoroll.add_subparser(subp)
+
+ fd, self.tmpfile = tempfile.mkstemp()
+ os.close(fd)
+
+ def tearDown(self):
+ os.remove(self.tmpfile)
+
+ @mock.patch('argparse._sys.stderr', new_callable=StringIO)
+ def test_no_fetch(self, stderr):
+ with self.assertRaises(SystemExit):
+ args = self.p.parse_args(['--no-fetch', 'autoroll'])
+ args.postprocess_func(self.p, args)
+ self.assertIn('--no-fetch does not make sense', stderr.getvalue())
+
+ @mock.patch('argparse._sys.stderr', new_callable=StringIO)
+ def test_json_flags(self, stderr):
+ with self.assertRaises(SystemExit):
+ args = self.p.parse_args(['autoroll', '--verbose-json'])
+ args.postprocess_func(self.p, args)
+ self.assertIn('without --output-json', stderr.getvalue())
+
+ args = self.p.parse_args([
+ 'autoroll', '--verbose-json', '--output-json', self.tmpfile])
+ args.postprocess_func(self.p, args)
+
+
if __name__ == '__main__':
sys.exit(unittest.main())
« no previous file with comments | « recipe_engine/autoroll.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698