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 os | |
12 import subprocess | |
13 import unittest | |
14 | |
15 | |
16 MSG_FORMAT = 'ERROR:check_package_boundaries.py: Unexpected %s.' | |
17 | |
18 | |
19 def _RunCommand(command, cwd): | |
20 """Runs a command and returns the output from that command.""" | |
21 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | |
22 cwd=cwd) | |
23 stdout = p.stdout.read() | |
24 stderr = p.stderr.read() | |
25 p.wait() | |
26 p.stdout.close() | |
27 p.stderr.close() | |
28 return p.returncode, stdout, stderr | |
29 | |
30 | |
31 class UnitTest(unittest.TestCase): | |
32 def test_check_package_boundaries(self): | |
33 os.chdir(os.path.dirname(os.path.abspath(__file__))) | |
kjellander_webrtc
2017/01/24 09:33:19
It's generally bad practice to use os.chdir in scr
| |
34 with open(os.path.join('testdata', 'expected_stderr')) as f: | |
35 expected_stderr = f.read() | |
36 with open(os.path.join('testdata', 'expected_stdout')) as f: | |
37 expected_stdout = f.read() | |
38 | |
39 test_command = ['python', 'check_package_boundaries.py', 'testdata'] | |
kjellander_webrtc
2017/01/24 09:33:19
Please refactor the check_package_boundaries modul
| |
40 return_code, stdout, stderr = _RunCommand(test_command, cwd=os.getcwd()) | |
41 | |
42 self.assertEqual(return_code, 1) | |
43 self.assertMultiLineEqual(expected_stdout, stdout) | |
44 self.assertMultiLineEqual(expected_stderr, stderr) | |
45 | |
46 | |
47 if __name__ == '__main__': | |
48 unittest.main() | |
OLD | NEW |