Output command line when packager tests fail

- Changed python packaging test to output the command line it ran for
  tests that failed.

Change-Id: I52c06bcec725c9dce7f845ab138cfab29b582201
This commit is contained in:
Rintaro Kuroiwa 2017-04-04 16:35:25 -07:00
parent f3e91301c2
commit c2e019ed31
2 changed files with 22 additions and 1 deletions

View File

@ -22,6 +22,9 @@ class PackagerApp(object):
if platform.system() == 'Windows':
packager_name += '.exe'
self.binary = os.path.join(test_env.SCRIPT_DIR, packager_name)
# Set this to empty for now in case GetCommandLine() is called before
# Package().
self.packaging_command_line = ''
assert os.path.exists(self.binary), ('Please run from output directory, '
'e.g. out/Debug/packager_test.py')
@ -39,4 +42,10 @@ class PackagerApp(object):
cmd = [self.binary]
cmd.extend(streams)
cmd.extend(flags)
# Put single-quotes around each entry so that things like '$' signs in
# segment templates won't be interpreted as shell variables.
self.packaging_command_line = ' '.join(["'%s'" % entry for entry in cmd])
assert 0 == subprocess.call(cmd)
def GetCommandLine(self):
return self.packaging_command_line

View File

@ -19,6 +19,14 @@ import unittest
import packager_app
import test_env
_TEST_FAILURE_COMMAND_LINE_MESSAGE = """
!!! To reproduce the failure, change the output files to an !!!
!!! existing directory, e.g. output artifacts to current !!!
!!! directory by removing /tmp/something/ in the following !!!
!!! command line. !!!
The test executed the following command line:
"""
class PackagerAppTest(unittest.TestCase):
@ -658,7 +666,11 @@ class PackagerAppTest(unittest.TestCase):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, error = p.communicate()
self.fail(output + error)
command_line = self.packager.GetCommandLine()
failure_message = (output + error + '\n' +
_TEST_FAILURE_COMMAND_LINE_MESSAGE +
command_line)
self.fail(failure_message)
# '*.media_info' outputs contain media file names, which is changing for
# every test run. These needs to be replaced for comparison.