| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import subprocess | 5 import subprocess |
| 6 | 6 |
| 7 from testing_utils import testing |
| 8 |
| 7 import script_util | 9 import script_util |
| 8 from testing_utils import testing | |
| 9 | 10 |
| 10 | 11 |
| 11 class ScriptUtilTest(testing.AppengineTestCase): | 12 class ScriptUtilTest(testing.AppengineTestCase): |
| 12 | 13 |
| 13 # TODO(katesonia): Figure out a good way to work around cache. | 14 # TODO(katesonia): Figure out a good way to work around cache. |
| 14 def testGetLocalGitCommandOutput(self): | 15 def testGetLocalGitCommandOutput(self): |
| 15 class _MockProcess(object): | 16 class _MockProcess(object): |
| 16 def __init__(self, command, *_): | 17 def __init__(self, command, *_): |
| 17 self.command = command | 18 self.command = command |
| 18 | 19 |
| 19 def communicate(self, *_): | 20 def communicate(self, *_): |
| 20 return self.command, 'error' | 21 return self.command, 'error' |
| 21 | 22 |
| 22 @property | 23 @property |
| 23 def returncode(self): | 24 def returncode(self): |
| 24 return 1 if self.command == 'dummy' else 0 | 25 return 1 if self.command == 'dummy' else 0 |
| 25 | 26 |
| 26 self.mock(subprocess, 'Popen', lambda command, **_: _MockProcess(command)) | 27 self.mock(subprocess, 'Popen', lambda command, **_: _MockProcess(command)) |
| 27 output = script_util.GetCommandOutput('command') | 28 output = script_util.GetCommandOutput('command') |
| 28 self.assertEqual(output, 'command') | 29 self.assertEqual(output, 'command') |
| 29 | 30 |
| 30 output = script_util.GetCommandOutput('dummy') | 31 self.assertRaisesRegexp(Exception, 'Error running command dummy: error', |
| 31 self.assertEqual(output, None) | 32 script_util.GetCommandOutput, 'dummy') |
| OLD | NEW |