fun_log.close() # Open it again to ensure the original gets renamed. fun_log = console._open_logfile(path) fun_log.write("it's better than bad, it's good!\n") fun_log.close() log_file_list = os.listdir(self.tempdir) self.assertEqual(2, len(log_file_list)) for name in log_file_list: self.assertTrue(name.startswith('its-log-log.'), 'unexpected name %s' % name) self.assertTrue(name.endswith('.gz'), 'unexpected name %s' % name) def test_logfile_close_signal_handler(self): self.god.stub_function(os, 'exit') os.exit.expect_call(1) logfile = StringIO.StringIO() console._set_logfile_close_signal_handler(logfile) try: self.assertFalse(logfile.closed) os.kill(os.getpid(), signal.SIGTERM) finally: console._unset_signal_handler() self.god.check_playback() self.assertTrue(logfile.closed) if __name__ == '__main__': unittest.main()
#class MyError(error.TestError): # pass #real_error = MyError("this is the real error message") #unhandled_error = error.UnhandledTestError(real_error) # set up the recording testname = "test" outputdir = os.path.join(self.job.resultdir, testname) self.job.pkgmgr.get_package_name.expect_call( testname, 'test').and_return(("", testname)) os.path.exists.expect_call(outputdir).and_return(False) timeout = 60 optional_fields = {} optional_fields['timeout'] = timeout self.job.record.expect_call("START", testname, testname, optional_fields=optional_fields) self.job._runtest.expect_call(testname, "", timeout, (), {}) self.job.record.expect_call("GOOD", testname, testname, "completed successfully") self.job.record.expect_call("END GOOD", testname, testname) self.job.harness.run_test_complete.expect_call() utils.drop_caches.expect_call() # run and check self.job.run_test(testname, timeout=timeout) self.god.check_playback() if __name__ == "__main__": unittest.main()