Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
| 4 # | |
| 5 # Use of this source code is governed by a BSD-style license | |
| 6 # that can be found in the LICENSE file in the root of the source | |
| 7 # tree. An additional intellectual property rights grant can be found | |
| 8 # in the file PATENTS. All contributing project authors may | |
| 9 # be found in the AUTHORS file in the root of the source tree. | |
| 10 | |
| 11 import logging | |
| 12 import os | |
| 13 import subprocess | |
| 14 import sys | |
| 15 | |
| 16 | |
| 17 def _RunCommand(command, cwd): | |
| 18 """Runs a command and returns the output from that command.""" | |
| 19 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | |
| 20 cwd=cwd) | |
| 21 stdout = p.stdout.read() | |
| 22 stderr = p.stderr.read() | |
| 23 p.wait() | |
| 24 p.stdout.close() | |
| 25 p.stderr.close() | |
| 26 return p.returncode, stdout, stderr | |
| 27 | |
|
kjellander_webrtc
2017/01/19 10:51:26
+1 blank line
| |
| 28 def _CheckEqual(actual, expected, message=''): | |
|
kjellander_webrtc
2017/01/19 10:51:26
Please use unittest module instead.
ehmaldonado_webrtc
2017/01/19 13:33:56
Done.
| |
| 29 message += '\n\n ACTUAL:\n{}\n EXPECTED:\n{}\n'.format(actual, expected) | |
| 30 if actual != expected: | |
| 31 logging.error(message) | |
| 32 sys.exit(1) | |
| 33 | |
| 34 def main(): | |
| 35 logging.basicConfig(format='ERROR:check_package_boundaries.py %(message)s') | |
| 36 os.chdir(os.path.dirname(os.path.abspath(__file__))) | |
| 37 | |
| 38 with open(os.path.join('testdata', 'expected_stderr')) as f: | |
| 39 expected_stderr = f.read() | |
| 40 | |
| 41 with open(os.path.join('testdata', 'expected_stdout')) as f: | |
| 42 expected_stdout = f.read() | |
| 43 | |
| 44 test_command = ['python', 'check_package_boundaries.py', 'testdata'] | |
| 45 return_code, stdout, stderr = _RunCommand(test_command, cwd=os.getcwd()) | |
| 46 | |
| 47 _CheckEqual(return_code, 1, 'Unexpected return code.') | |
| 48 _CheckEqual(stdout, expected_stdout, 'Unexpected output (stdout).') | |
| 49 _CheckEqual(stderr, expected_stderr, 'Unexpected output (stderr).') | |
| 50 | |
| 51 return 0 | |
| 52 | |
| 53 if __name__ == '__main__': | |
| 54 sys.exit(main()) | |
| OLD | NEW |