OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Smoke tests for gclient.py. | 6 """Smoke tests for gclient.py. |
7 | 7 |
8 Shell out 'gclient' and run basic conformance tests. | 8 Shell out 'gclient' and run basic conformance tests. |
9 | 9 |
10 This test assumes GClientSmokeBase.URL_BASE is valid. | 10 This test assumes GClientSmokeBase.URL_BASE is valid. |
11 """ | 11 """ |
12 | 12 |
13 # pylint: disable=E1103,W0403 | |
14 | |
15 import logging | 13 import logging |
16 import os | 14 import os |
17 import re | 15 import re |
18 import subprocess | 16 import subprocess |
19 import sys | 17 import sys |
20 import unittest | 18 import unittest |
21 | 19 |
22 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | 20 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
23 sys.path.insert(0, os.path.dirname(ROOT_DIR)) | 21 sys.path.insert(0, ROOT_DIR) |
24 from tests.fake_repos import join, write, FakeReposTestBase | 22 |
| 23 from fake_repos import join, write, FakeReposTestBase |
| 24 |
25 import subprocess2 | 25 import subprocess2 |
26 | 26 |
27 GCLIENT_PATH = os.path.join(os.path.dirname(ROOT_DIR), 'gclient') | 27 GCLIENT_PATH = os.path.join(ROOT_DIR, 'gclient') |
28 COVERAGE = False | 28 COVERAGE = False |
29 | 29 |
30 | 30 |
31 class GClientSmokeBase(FakeReposTestBase): | 31 class GClientSmokeBase(FakeReposTestBase): |
32 def setUp(self): | 32 def setUp(self): |
33 super(GClientSmokeBase, self).setUp() | 33 super(GClientSmokeBase, self).setUp() |
34 # Make sure it doesn't try to auto update when testing! | 34 # Make sure it doesn't try to auto update when testing! |
35 self.env = os.environ.copy() | 35 self.env = os.environ.copy() |
36 self.env['DEPOT_TOOLS_UPDATE'] = '0' | 36 self.env['DEPOT_TOOLS_UPDATE'] = '0' |
37 | 37 |
38 def gclient(self, cmd, cwd=None): | 38 def gclient(self, cmd, cwd=None): |
39 if not cwd: | 39 if not cwd: |
40 cwd = self.root_dir | 40 cwd = self.root_dir |
41 if COVERAGE: | 41 if COVERAGE: |
42 # Don't use the wrapper script. | 42 # Don't use the wrapper script. |
43 cmd_base = ['coverage', 'run', '-a', GCLIENT_PATH + '.py'] | 43 cmd_base = ['coverage', 'run', '-a', GCLIENT_PATH + '.py'] |
44 else: | 44 else: |
45 cmd_base = [GCLIENT_PATH] | 45 cmd_base = [GCLIENT_PATH] |
46 cmd = cmd_base + cmd | 46 cmd = cmd_base + cmd |
47 process = subprocess.Popen(cmd, cwd=cwd, env=self.env, | 47 process = subprocess.Popen(cmd, cwd=cwd, env=self.env, |
48 stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 48 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
49 shell=sys.platform.startswith('win')) | 49 shell=sys.platform.startswith('win')) |
50 (stdout, stderr) = process.communicate() | 50 (stdout, stderr) = process.communicate() |
51 logging.debug("XXX: %s\n%s\nXXX" % (' '.join(cmd), stdout)) | 51 logging.debug("XXX: %s\n%s\nXXX" % (' '.join(cmd), stdout)) |
52 logging.debug("YYY: %s\n%s\nYYY" % (' '.join(cmd), stderr)) | 52 logging.debug("YYY: %s\n%s\nYYY" % (' '.join(cmd), stderr)) |
| 53 # pylint: disable=E1103 |
53 return (stdout.replace('\r\n', '\n'), stderr.replace('\r\n', '\n'), | 54 return (stdout.replace('\r\n', '\n'), stderr.replace('\r\n', '\n'), |
54 process.returncode) | 55 process.returncode) |
55 | 56 |
56 def untangle(self, stdout): | 57 def untangle(self, stdout): |
57 tasks = {} | 58 tasks = {} |
58 remaining = [] | 59 remaining = [] |
59 for line in stdout.splitlines(False): | 60 for line in stdout.splitlines(False): |
60 m = re.match(r'^(\d)+>(.*)$', line) | 61 m = re.match(r'^(\d)+>(.*)$', line) |
61 if not m: | 62 if not m: |
62 remaining.append(line) | 63 remaining.append(line) |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 | 1281 |
1281 if '-c' in sys.argv: | 1282 if '-c' in sys.argv: |
1282 COVERAGE = True | 1283 COVERAGE = True |
1283 sys.argv.remove('-c') | 1284 sys.argv.remove('-c') |
1284 if os.path.exists('.coverage'): | 1285 if os.path.exists('.coverage'): |
1285 os.remove('.coverage') | 1286 os.remove('.coverage') |
1286 os.environ['COVERAGE_FILE'] = os.path.join( | 1287 os.environ['COVERAGE_FILE'] = os.path.join( |
1287 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), | 1288 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), |
1288 '.coverage') | 1289 '.coverage') |
1289 unittest.main() | 1290 unittest.main() |
OLD | NEW |