Chromium Code Reviews| Index: tools-webrtc/check_package_boundaries_test.py |
| diff --git a/tools-webrtc/check_package_boundaries_test.py b/tools-webrtc/check_package_boundaries_test.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..13c6232c24783759894e58b3f6e6720f884ea3cf |
| --- /dev/null |
| +++ b/tools-webrtc/check_package_boundaries_test.py |
| @@ -0,0 +1,54 @@ |
| +#!/usr/bin/env python |
| + |
| +# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| +# |
| +# Use of this source code is governed by a BSD-style license |
| +# that can be found in the LICENSE file in the root of the source |
| +# tree. An additional intellectual property rights grant can be found |
| +# in the file PATENTS. All contributing project authors may |
| +# be found in the AUTHORS file in the root of the source tree. |
| + |
| +import logging |
| +import os |
| +import subprocess |
| +import sys |
| + |
| + |
| +def _RunCommand(command, cwd): |
| + """Runs a command and returns the output from that command.""" |
| + p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| + cwd=cwd) |
| + stdout = p.stdout.read() |
| + stderr = p.stderr.read() |
| + p.wait() |
| + p.stdout.close() |
| + p.stderr.close() |
| + return p.returncode, stdout, stderr |
| + |
|
kjellander_webrtc
2017/01/19 10:51:26
+1 blank line
|
| +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.
|
| + message += '\n\n ACTUAL:\n{}\n EXPECTED:\n{}\n'.format(actual, expected) |
| + if actual != expected: |
| + logging.error(message) |
| + sys.exit(1) |
| + |
| +def main(): |
| + logging.basicConfig(format='ERROR:check_package_boundaries.py %(message)s') |
| + os.chdir(os.path.dirname(os.path.abspath(__file__))) |
| + |
| + with open(os.path.join('testdata', 'expected_stderr')) as f: |
| + expected_stderr = f.read() |
| + |
| + with open(os.path.join('testdata', 'expected_stdout')) as f: |
| + expected_stdout = f.read() |
| + |
| + test_command = ['python', 'check_package_boundaries.py', 'testdata'] |
| + return_code, stdout, stderr = _RunCommand(test_command, cwd=os.getcwd()) |
| + |
| + _CheckEqual(return_code, 1, 'Unexpected return code.') |
| + _CheckEqual(stdout, expected_stdout, 'Unexpected output (stdout).') |
| + _CheckEqual(stderr, expected_stderr, 'Unexpected output (stderr).') |
| + |
| + return 0 |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |