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

Unified Diff: shell/main_unittest.py

Issue 6720024: Plumb in subcommand options (Closed) Base URL: ssh://gitrw.chromium.org:9222/chromite.git@master
Patch Set: Moved docstring into docstring :-) Created 9 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 | « shell/main.py ('k') | shell/subcmds/build_cmd.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: shell/main_unittest.py
diff --git a/shell/main_unittest.py b/shell/main_unittest.py
index bb510f3388cbdbf0c5cb19f778efb7875fa57cae..e18a9c8f2ec6f140c09268aa050391716aba56cc 100644
--- a/shell/main_unittest.py
+++ b/shell/main_unittest.py
@@ -7,6 +7,7 @@
"""Unit tests for main.py."""
import doctest
+import optparse
import os
import re
import unittest
@@ -399,6 +400,67 @@ class TestFindSpec(unittest.TestCase):
'_FindSpec("%s") incorrectly returned "%s".' %
(spec_name, spec_path))
+class TestParseArguments(unittest.TestCase):
+ """Test utils.FindSpec."""
+
+ def setUp(self):
+ """Test initialization."""
+ self.parser = optparse.OptionParser()
+
+ # Verbose defaults to full for now, just to keep people acclimatized to
+ # vast amounts of comforting output.
+ self.parser.add_option('-v', dest='verbose', default=3, type='int',
+ help='Control verbosity: 0=silent, 1=progress, 3=full')
+ self.parser.add_option('-q', action='store_const', dest='verbose', const=0,
+ help='Be quieter (sets verbosity to 1)')
+
+ def testEmpty(self):
+ options, cmd, sub = main._ParseArguments(self.parser,
+ [])
+ self.assertEqual(options.verbose, 3)
+ self.assertEqual(cmd, '')
+ self.assertEqual(sub, [])
+
+ def testBadOption(self):
+ self.assertRaises(SystemExit, main._ParseArguments, self.parser,
+ ['chromite', '--bad'])
+ self.assertRaises(SystemExit, main._ParseArguments, self.parser,
+ ['chromite', '--bad', 'build'])
+
+ def testSubcmd(self):
+ options, cmd, sub = main._ParseArguments(self.parser,
+ ['chromite', 'build'])
+ self.assertEqual(options.verbose, 3)
+ self.assertEqual(cmd, 'build')
+ self.assertEqual(sub, [])
+
+ def testSubcmdQuiet(self):
+ options, cmd, sub = main._ParseArguments(self.parser,
+ ['chromite', '-q', 'build'])
+ self.assertEqual(options.verbose, 0)
+ self.assertEqual(cmd, 'build')
+ self.assertEqual(sub, [])
+
+ def testSubcmdVerbose2(self):
+ options, cmd, sub = main._ParseArguments(self.parser,
+ ['chromite', '-v2', 'build'])
+ self.assertEqual(options.verbose, 2)
+ self.assertEqual(cmd, 'build')
+ self.assertEqual(sub, [])
+
+ def testSubcmdVerbose4(self):
+ options, cmd, sub = main._ParseArguments(self.parser,
+ ['chromite', '-v', '4', 'build'])
+ self.assertEqual(options.verbose, 4)
+ self.assertEqual(cmd, 'build')
+ self.assertEqual(sub, [])
+
+ def testSubcmdArgs(self):
+ options, cmd, sub = main._ParseArguments(self.parser,
+ ['chromite', '-v', '4', 'build', 'seaboard', '--clean'])
+ self.assertEqual(options.verbose, 4)
+ self.assertEqual(cmd, 'build')
+ self.assertEqual(sub, ['seaboard', '--clean'])
if __name__ == '__main__':
doctest.testmod(main)
« no previous file with comments | « shell/main.py ('k') | shell/subcmds/build_cmd.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698