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

Side by Side Diff: shell/main_unittest.py

Issue 6626039: Revert "Plumb in crprocess instead of RunCommand to allow quiet operation." (Closed) Base URL: http://git.chromium.org/git/chromite.git@master
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « shell/main.py ('k') | shell/subcmd.py » ('j') | 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/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Unit tests for main.py.""" 7 """Unit tests for main.py."""
8 8
9 import doctest 9 import doctest
10 import os 10 import os
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 class TestFindCommand(unittest.TestCase): 44 class TestFindCommand(unittest.TestCase):
45 """Test main._FindCommand.""" 45 """Test main._FindCommand."""
46 # TODO(dianders): Add a test where I override main._COMMAND_HANDLERS 46 # TODO(dianders): Add a test where I override main._COMMAND_HANDLERS
47 # and main._COMMAND_STRS so that I can test more of _FindCommand(). 47 # and main._COMMAND_STRS so that I can test more of _FindCommand().
48 48
49 def setUp(self): 49 def setUp(self):
50 """Test initialization.""" 50 """Test initialization."""
51 # Create our mox and stub out function calls used by _FindCommand()... 51 # Create our mox and stub out function calls used by _FindCommand()...
52 self.mox = mox.Mox() 52 self.mox = mox.Mox()
53 self.mox.StubOutWithMock(cros_lib, 'Die') 53 self.mox.StubOutWithMock(cros_lib, 'Die')
54 self.mox.StubOutWithMock(cros_lib, 'Info')
54 self.mox.StubOutWithMock(text_menu, 'TextMenu') 55 self.mox.StubOutWithMock(text_menu, 'TextMenu')
55 56
56 def tearDown(self): 57 def tearDown(self):
57 """Test cleanup.""" 58 """Test cleanup."""
58 # Unset stubs... 59 # Unset stubs...
59 self.mox.UnsetStubs() 60 self.mox.UnsetStubs()
60 61
61 def testInvalidCommand(self): 62 def testInvalidCommand(self):
62 """Test that _FindCommand('implode') causes cros_lib.Die().""" 63 """Test that _FindCommand('implode') causes cros_lib.Die()."""
63 # Should be a call to cros_lib.Die. We'll have it fake a _DeathException... 64 # Should be a call to cros_lib.Die. We'll have it fake a _DeathException...
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 def testShCommand(self): 142 def testShCommand(self):
142 """Test that _FindCommand('sh') returns 'shell'. 143 """Test that _FindCommand('sh') returns 'shell'.
143 144
144 This serves two purposes: 145 This serves two purposes:
145 1. Test the 'prefix' feature of _FindCommand 146 1. Test the 'prefix' feature of _FindCommand
146 2. Validate that nobody has introduced another command that starts with 147 2. Validate that nobody has introduced another command that starts with
147 'sh', since it's expected that many people will use this to invoke the 148 'sh', since it's expected that many people will use this to invoke the
148 shell. 149 shell.
149 """ 150 """
150 # _FindCommand should give us a message that it has interpreted sh as shell. 151 # _FindCommand should give us a message that it has interpreted sh as shell.
152 cros_lib.Info(mox.IsA(basestring))
151 153
152 # Run the command and verify proper mocks were called... 154 # Run the command and verify proper mocks were called...
153 self.mox.ReplayAll() 155 self.mox.ReplayAll()
154 cmd_str = main._FindCommand('sh') 156 cmd_str = main._FindCommand('sh')
155 self.mox.VerifyAll() 157 self.mox.VerifyAll()
156 158
157 self.assertEqual(cmd_str, 'shell', 159 self.assertEqual(cmd_str, 'shell',
158 '_FindCommand("sh") should return "shell" back.') 160 '_FindCommand("sh") should return "shell" back.')
159 161
160 162
161 class TestFindSpec(unittest.TestCase): 163 class TestFindSpec(unittest.TestCase):
162 """Test utils.FindSpec.""" 164 """Test utils.FindSpec."""
163 165
164 def setUp(self): 166 def setUp(self):
165 """Test initialization.""" 167 """Test initialization."""
166 # Create our mox and stub out function calls used by _FindSpec()... 168 # Create our mox and stub out function calls used by _FindSpec()...
167 self.mox = mox.Mox() 169 self.mox = mox.Mox()
168 self.mox.StubOutWithMock(os, 'listdir') 170 self.mox.StubOutWithMock(os, 'listdir')
169 self.mox.StubOutWithMock(os.path, 'isfile') 171 self.mox.StubOutWithMock(os.path, 'isfile')
170 self.mox.StubOutWithMock(cros_lib, 'Die') 172 self.mox.StubOutWithMock(cros_lib, 'Die')
173 self.mox.StubOutWithMock(cros_lib, 'Info')
171 self.mox.StubOutWithMock(text_menu, 'TextMenu') 174 self.mox.StubOutWithMock(text_menu, 'TextMenu')
172 175
173 def tearDown(self): 176 def tearDown(self):
174 """Test cleanup.""" 177 """Test cleanup."""
175 # Unset stubs... 178 # Unset stubs...
176 self.mox.UnsetStubs() 179 self.mox.UnsetStubs()
177 180
178 def testInvalidSpec(self): 181 def testInvalidSpec(self):
179 """Test that _FindSpec('bogusSpec') causes cros_lib.Die().""" 182 """Test that _FindSpec('bogusSpec') causes cros_lib.Die()."""
180 # Pass this spec name... 183 # Pass this spec name...
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 self.mox.VerifyAll() 399 self.mox.VerifyAll()
397 400
398 self.assertTrue(re.search('^/.*%s$' % expected_result, spec_path), 401 self.assertTrue(re.search('^/.*%s$' % expected_result, spec_path),
399 '_FindSpec("%s") incorrectly returned "%s".' % 402 '_FindSpec("%s") incorrectly returned "%s".' %
400 (spec_name, spec_path)) 403 (spec_name, spec_path))
401 404
402 405
403 if __name__ == '__main__': 406 if __name__ == '__main__':
404 doctest.testmod(main) 407 doctest.testmod(main)
405 unittest.main() 408 unittest.main()
OLDNEW
« no previous file with comments | « shell/main.py ('k') | shell/subcmd.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698