Пример #1
0
 def test__run__run_log_output__success(self):
     with InTemporaryDirectory():
         result = run_and_log_output(['echo', 'hello'], 'echo.log')
         self.assertTrue(os.path.exists('echo.log'))
         with open('echo.log') as fh:
             log_output = fh.read()
         self.assertEqual(log_output, 'hello\n')
    def test__run__run_log_output__fail(self):
        testscript_content = """import sys
print('hello')
sys.exit(1)
"""
        with InTemporaryDirectory():
            with open('testscript.py', 'w') as fh:
                fh.write(testscript_content)
            with self.assertRaises(subprocess.CalledProcessError):
                result = run_and_log_output([sys.executable, 'testscript.py'], 'test.log')
            self.assertTrue(os.path.exists('test.log'))
            with open('test.log') as fh:
                test_output = fh.read()
            self.assertEqual(test_output, 'hello\n')