diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2015-01-26 11:20:00 -0800 |
---|---|---|
committer | Dylan Baker <baker.dylan.c@gmail.com> | 2015-03-09 10:23:39 -0700 |
commit | f0c8ef51fb68f4e31b6ad82490d20b1a41ffeff6 (patch) | |
tree | c3b98dfa36d8203439acf9d820226ed96dd29148 | |
parent | 6aa103a54014ff13961d3dc40d6ddb58388668e2 (diff) |
igt.py: Use subprocess.check_output instead of subprocess.Popen
This is somewhat simpler way to handle this, since check_output monitors
only stdout, and hides stderr, and it gives us a lovely exception if the
returncode isn't 0, which allows us to completely bypass the error
checking code if there is no error.
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
Reviewed-by: Thomas Wood <thomas.wood@intel.com>
-rw-r--r-- | tests/igt.py | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/tests/igt.py b/tests/igt.py index d7704060a..dd7a38a4a 100644 --- a/tests/igt.py +++ b/tests/igt.py @@ -135,27 +135,24 @@ def list_tests(listname): def add_subtest_cases(test): """Get subtest instances.""" - proc = subprocess.Popen( - [os.path.join(IGT_TEST_ROOT, test), '--list-subtests'], - stdout=subprocess.PIPE, - env=os.environ.copy(), - universal_newlines=True) - out, _ = proc.communicate() - - # a return code of 79 indicates there are no subtests - if proc.returncode == 79: - profile.test_list[grouptools.join('igt', test)] = IGTTest(test) - return + try: + out = subprocess.check_output( + [os.path.join(IGT_TEST_ROOT, test), '--list-subtests'], + env=os.environ.copy(), + universal_newlines=True) + except subprocess.CalledProcessError as e: + # a return code of 79 indicates there are no subtests + if e.returncode == 79: + profile.test_list[grouptools.join('igt', test)] = IGTTest(test) + elif e.returncode != 0: + print("Error: Could not list subtests for " + test) + else: + raise - if proc.returncode != 0: - print("Error: Could not list subtests for " + test) + # If we reach here there are no subtests. return - subtests = out.split("\n") - - for subtest in subtests: - if subtest == "": - continue + for subtest in (s for s in out.splitlines() if s): profile.test_list[grouptools.join('igt', test, subtest)] = \ IGTTest(test, ['--run-subtest', subtest]) |