diff --git a/gcl.py b/gcl.py index 8c89a7a04..6726d028b 100755 --- a/gcl.py +++ b/gcl.py @@ -191,8 +191,8 @@ def GetCodeReviewSetting(key): raise gclient_utils.Error( '%s is invalid, please fix. It\'s content:\n\n%s' % (CODEREVIEW_SETTINGS_FILE, settings_file)) - k, v = line.split(': ', 1) - CODEREVIEW_SETTINGS[k] = v + k, v = line.split(':', 1) + CODEREVIEW_SETTINGS[k.strip()] = v.strip() CODEREVIEW_SETTINGS.setdefault('__just_initialized', None) return CODEREVIEW_SETTINGS.get(key, "") diff --git a/tests/gcl_unittest.py b/tests/gcl_unittest.py index e93924690..c160aa178 100755 --- a/tests/gcl_unittest.py +++ b/tests/gcl_unittest.py @@ -28,6 +28,9 @@ class GclTestsBase(SuperMoxTestBase): class GclUnittest(GclTestsBase): """General gcl.py tests.""" + def tearDown(self): + gcl.CODEREVIEW_SETTINGS = {} + def testMembersChanged(self): self.mox.ReplayAll() members = [ @@ -73,6 +76,39 @@ class GclUnittest(GclTestsBase): # TODO(maruel): TEST ME pass + def testDefaultSettings(self): + self.assertEquals({}, gcl.CODEREVIEW_SETTINGS) + + def testGetCodeReviewSettingOk(self): + self.mox.StubOutWithMock(gcl, 'GetCachedFile') + gcl.GetCachedFile(gcl.CODEREVIEW_SETTINGS_FILE).AndReturn( + 'foo:bar\n' + '# comment\n' + ' c : d \n\r' + 'e: f') + self.mox.ReplayAll() + self.assertEquals('bar', gcl.GetCodeReviewSetting('foo')) + self.assertEquals('d', gcl.GetCodeReviewSetting('c')) + self.assertEquals('f', gcl.GetCodeReviewSetting('e')) + self.assertEquals('', gcl.GetCodeReviewSetting('other')) + self.assertEquals( + {'foo': 'bar', 'c': 'd', 'e': 'f', '__just_initialized': None}, + gcl.CODEREVIEW_SETTINGS) + + def testGetCodeReviewSettingFail(self): + self.mox.StubOutWithMock(gcl, 'GetCachedFile') + gcl.GetCachedFile(gcl.CODEREVIEW_SETTINGS_FILE).AndReturn( + 'aaa\n' + ' c : d \n\r' + 'e: f') + self.mox.ReplayAll() + try: + gcl.GetCodeReviewSetting('c') + self.fail() + except gcl.gclient_utils.Error: + pass + self.assertEquals({}, gcl.CODEREVIEW_SETTINGS) + def testGetRepositoryRootNone(self): gcl.os.getcwd().AndReturn(self.fake_root_dir) gcl.SVN.GetCheckoutRoot(self.fake_root_dir).AndReturn(None) diff --git a/tests/gclient_utils_test.py b/tests/gclient_utils_test.py index 01b222107..2779f8160 100755 --- a/tests/gclient_utils_test.py +++ b/tests/gclient_utils_test.py @@ -78,30 +78,30 @@ class CheckCallTestCase(GclientUtilBase): class SubprocessCallAndFilterTestCase(GclientUtilBase): - def testSubprocessCallAndFilter(self): - command = ['boo', 'foo', 'bar'] + class ProcessIdMock(object): + def __init__(self, test_string): + self.stdout = StringIO.StringIO(test_string) + def wait(self): + pass + + def _inner(self, command, test_string): in_directory = 'bleh' - fail_status = None - pattern = 'a(.*)b' - test_string = 'ahah\naccb\nallo\naddb\n' env = gclient_utils.os.environ.copy() env['LANGUAGE'] = 'en' - class Mock(object): - stdout = StringIO.StringIO(test_string) - def wait(self): - pass - kid = Mock() print("\n________ running 'boo foo bar' in 'bleh'") for i in test_string: gclient_utils.sys.stdout.write(i) gclient_utils.subprocess.Popen( - command, bufsize=0, cwd=in_directory, + command, + cwd=in_directory, shell=(gclient_utils.sys.platform == 'win32'), env=env, stdout=gclient_utils.subprocess.PIPE, - stderr=gclient_utils.subprocess.STDOUT).AndReturn(kid) + stderr=gclient_utils.subprocess.STDOUT, + bufsize=0).AndReturn(self.ProcessIdMock(test_string)) + self.mox.ReplayAll() - compiled_pattern = gclient_utils.re.compile(pattern) + compiled_pattern = gclient_utils.re.compile(r'a(.*)b') line_list = [] capture_list = [] def FilterLines(line): @@ -110,12 +110,21 @@ class SubprocessCallAndFilterTestCase(GclientUtilBase): if match: capture_list.append(match.group(1)) gclient_utils.SubprocessCallAndFilter( - command, in_directory, - True, True, - fail_status, FilterLines) + command, in_directory, True, True, None, FilterLines) self.assertEquals(line_list, ['ahah', 'accb', 'allo', 'addb']) self.assertEquals(capture_list, ['cc', 'dd']) + def testSubprocessCallAndFilter(self): + command = ['boo', 'foo', 'bar'] + test_string = 'ahah\naccb\nallo\naddb\n' + self._inner(command, test_string) + + def testNoLF(self): + # Exactly as testSubprocessCallAndFilter without trailing \n + command = ['boo', 'foo', 'bar'] + test_string = 'ahah\naccb\nallo\naddb' + self._inner(command, test_string) + class SplitUrlRevisionTestCase(GclientUtilBase): def testSSHUrl(self):