diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 3002447e4..a3aad5061 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -51,6 +51,10 @@ def CommonChecks(input_api, output_api): def RunGitClTests(input_api, output_api, verbose): """Run all the shells scripts in the directory test. """ + if input_api.platform == 'win32': + # Skip for now as long as the test scripts are bash scripts. + return [] + # First loads a local Rietveld instance. import sys old_sys_path = sys.path diff --git a/git_cl.py b/git_cl.py index d24bf7348..f9a008c88 100755 --- a/git_cl.py +++ b/git_cl.py @@ -20,7 +20,7 @@ import urlparse import urllib2 try: - import readline # pylint: disable=W0611 + import readline # pylint: disable=F0401,W0611 except ImportError: pass diff --git a/scm.py b/scm.py index 67dd747d4..31b18f677 100644 --- a/scm.py +++ b/scm.py @@ -74,14 +74,16 @@ def determine_scm(root): """ if os.path.isdir(os.path.join(root, '.svn')): return 'svn' - elif os.path.isdir(os.path.join(root, '.svn')): + elif os.path.isdir(os.path.join(root, '.git')): return 'git' else: - if (0 == subprocess.call( + try: + subprocess2.check_output( ['git', 'rev-parse', '--show-cdup'], - stdout=subprocess.PIPE, cwd=root)): + stdout=subprocess2.VOID, + cwd=root) return 'git' - else: + except (OSError, subprocess2.CalledProcessError): return None diff --git a/subprocess2.py b/subprocess2.py index acba499ae..77fda58d2 100644 --- a/subprocess2.py +++ b/subprocess2.py @@ -51,7 +51,7 @@ def kill_pid(pid): """Kills a process by its process id.""" try: # Unable to import 'module' - # pylint: disable=F0401 + # pylint: disable=E1101,F0401 import signal return os.kill(pid, signal.SIGKILL) except ImportError: @@ -105,6 +105,8 @@ def get_english_env(env): Returns None if it is unnecessary. """ + if sys.platform == 'win32': + return None env = env or os.environ # Test if it is necessary at all. diff --git a/tests/fake_repos.py b/tests/fake_repos.py index 54ab15425..2151703dd 100755 --- a/tests/fake_repos.py +++ b/tests/fake_repos.py @@ -310,8 +310,7 @@ class FakeReposBase(object): return True try: subprocess2.check_call(['svnadmin', 'create', self.svn_repo]) - except subprocess2.CalledProcessError, e: - logging.debug('Failed with : %s' % e) + except (OSError, subprocess2.CalledProcessError): return False write(join(self.svn_repo, 'conf', 'svnserve.conf'), '[general]\n' @@ -352,9 +351,11 @@ class FakeReposBase(object): self.set_up() if self.gitdaemon: return True - if sys.platform == 'win32': - return False assert self.git_pid_file == None + try: + subprocess2.check_output(['git', '--version']) + except (OSError, subprocess2.CalledProcessError): + return False for repo in ['repo_%d' % r for r in range(1, self.NB_GIT_REPOS + 1)]: subprocess2.check_call(['git', 'init', '-q', join(self.git_root, repo)]) self.git_hashes[repo] = [None] diff --git a/tests/fix_encoding_test.py b/tests/fix_encoding_test.py index d4f49f4d1..c8bfbc29d 100755 --- a/tests/fix_encoding_test.py +++ b/tests/fix_encoding_test.py @@ -41,12 +41,13 @@ class FixEncodingTest(unittest.TestCase): def test_win_console(self): if sys.platform != 'win32': return - # This should fail if redirected. Can be checked with: - # python fix_encoding_test.py > a + # This should fail if not redirected, e.g. run directly instead of through + # the presubmit check. Can be checked with: + # python tests\fix_encoding_test.py self.assertEquals( - sys.stdout.__class__, fix_encoding.WinUnicodeConsoleOutput) + sys.stdout.__class__, fix_encoding.WinUnicodeOutput) self.assertEquals( - sys.stderr.__class__, fix_encoding.WinUnicodeConsoleOutput) + sys.stderr.__class__, fix_encoding.WinUnicodeOutput) self.assertEquals(sys.stdout.encoding, sys.getdefaultencoding()) self.assertEquals(sys.stderr.encoding, sys.getdefaultencoding()) diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index c18013e4d..acd0ab566 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -127,7 +127,14 @@ class GClientSmokeBase(FakeReposTestBase): verb = items[i] path = self.root_dir self.checkString(results[i][0][0], verb, (i, results[i][0][0], verb)) - self.checkString(results[i][0][2], path, (i, results[i][0][2], path)) + if sys.platform == 'win32': + # Make path lower case since casing can change randomly. + self.checkString( + results[i][0][2].lower(), + path.lower(), + (i, results[i][0][2].lower(), path.lower())) + else: + self.checkString(results[i][0][2], path, (i, results[i][0][2], path)) self.assertEquals(len(results), len(items), (stdout, items, len(results))) return results diff --git a/tests/local_rietveld.py b/tests/local_rietveld.py index a40271eda..49d1536f5 100755 --- a/tests/local_rietveld.py +++ b/tests/local_rietveld.py @@ -71,15 +71,15 @@ class LocalRietveld(object): subprocess2.check_call( ['svn', 'co', '-q', 'http://rietveld.googlecode.com/svn/trunk@681', self.rietveld]) - except subprocess2.CalledProcessError: - raise Failure('Failed to checkout rietveld') + except (OSError, subprocess2.CalledProcessError), e: + raise Failure('Failed to checkout rietveld\n%s' % e) else: print('Syncing rietveld...') try: subprocess2.check_call( ['svn', 'up', '-q', '-r', '681'], cwd=self.rietveld) - except subprocess2.CalledProcessError: - raise Failure('Failed to checkout rietveld') + except (OSError, subprocess2.CalledProcessError), e: + raise Failure('Failed to sync rietveld\n%s' % e) def start_server(self, verbose=False): self.install_prerequisites() @@ -89,6 +89,7 @@ class LocalRietveld(object): else: pipe = subprocess2.VOID cmd = [ + sys.executable, self.dev_app, '--skip_sdk_update_check', '.', diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 8b6a68c9e..f11fe22c4 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -2006,8 +2006,11 @@ mac|success|blew input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) input_api.subprocess.check_call( ['allo'], cwd=self.fake_root_dir) + cmd = ['bar.py'] + if input_api.platform == 'win32': + cmd.insert(0, input_api.python_executable) input_api.subprocess.check_call( - ['bar.py'], cwd=self.fake_root_dir).AndRaise( + cmd, cwd=self.fake_root_dir).AndRaise( input_api.subprocess.CalledProcessError()) self.mox.ReplayAll() @@ -2031,7 +2034,8 @@ mac|success|blew input_api.os_listdir(path).AndReturn(['.', '..', 'a', 'b', 'c']) input_api.os_path.isfile = lambda x: not x.endswith('.') input_api.subprocess.check_call( - ['random_directory/b'], cwd=self.fake_root_dir) + [presubmit.os.path.join('random_directory', 'b')], + cwd=self.fake_root_dir) self.mox.ReplayAll() results = presubmit_canned_checks.RunUnitTestsInDirectory( @@ -2042,7 +2046,8 @@ mac|success|blew blacklist=['a'], verbose=True) self.assertEqual(results, []) - self.checkstdout('Running random_directory/b\n') + self.checkstdout( + 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) if __name__ == '__main__': diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index bd2e1485f..1c214267c 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -261,22 +261,27 @@ class RealSvnTest(fake_repos.FakeReposTestBase): # Tests that work with a checkout. def setUp(self): super(RealSvnTest, self).setUp() - self.FAKE_REPOS.set_up_svn() - self.svn_root = scm.os.path.join(self.root_dir, 'base') - scm.SVN.Capture( - ['checkout', self.svn_base + 'trunk/third_party', 'base'], - cwd=self.root_dir) - self.tree = self.mangle_svn_tree(('trunk/third_party@-1', ''),) + self.enabled = self.FAKE_REPOS.set_up_svn() + if self.enabled: + self.svn_root = scm.os.path.join(self.root_dir, 'base') + scm.SVN.Capture( + ['checkout', self.svn_base + 'trunk/third_party', 'base'], + cwd=self.root_dir) + self.tree = self.mangle_svn_tree(('trunk/third_party@-1', ''),) def _capture(self, cmd, **kwargs): kwargs.setdefault('cwd', self.svn_root) return scm.SVN.Capture(cmd, **kwargs) def testCheckout(self): + if not self.enabled: + return # Checkout and verify the tree. self.assertTree(self.tree, self.svn_root) def testRevert(self): + if not self.enabled: + return # Mess around and make sure revert works for all corner cases. # - svn add a file # - svn add a file and delete it diff --git a/tests/subprocess2_test.py b/tests/subprocess2_test.py index 376a40fb6..dfc91f607 100755 --- a/tests/subprocess2_test.py +++ b/tests/subprocess2_test.py @@ -28,7 +28,7 @@ class Subprocess2Test(unittest.TestCase): def setUp(self): self.exe_path = __file__ - self.exe = [self.exe_path, '--child'] + self.exe = [sys.executable, self.exe_path, '--child'] self.saved = {} for module, names in self.TO_SAVE.iteritems(): self.saved[module] = dict( @@ -101,14 +101,20 @@ class Subprocess2Test(unittest.TestCase): results = self._fake_subprocess_Popen() proc = subprocess2.Popen(['foo'], a=True) self.assertEquals(-8, proc.returncode) - env = os.environ.copy() - env['LANG'] = 'en_US.UTF-8' expected = { 'args': ['foo'], 'a': True, 'shell': bool(sys.platform=='win32'), - 'env': env, } + if sys.platform != 'win32': + env = os.environ.copy() + is_english = lambda name: env.get(name, 'en').startswith('en') + if not is_english('LANG'): + env['LANG'] = 'en_US.UTF-8' + expected['env'] = env + if not is_english('LANGUAGE'): + env['LANGUAGE'] = 'en_US.UTF-8' + expected['env'] = env self.assertEquals(expected, results) def test_check_output_defaults(self): @@ -140,12 +146,14 @@ class Subprocess2Test(unittest.TestCase): self.assertEquals(None, out) out = subprocess2.check_output( self.exe + ['--stdout', '--stderr'], + universal_newlines=True, stderr=subprocess2.VOID) self.assertEquals('A\nBB\nCCC\n', out) def test_check_output_throw(self): try: - subprocess2.check_output(self.exe + ['--fail', '--stderr']) + subprocess2.check_output( + self.exe + ['--fail', '--stderr'], universal_newlines=True) self.fail() except subprocess2.CalledProcessError, e: self.assertEquals('a\nbb\nccc\n', e.stdout)