def __init__(self, name, filename, mode = 'a', delete = False): Log.__init__(self, name) self.filename = filename self.errorname = filename + '.error' self.mode = mode self.delete = delete self.do_log = True dirname = os.path.dirname(filename) if dirname: try: os.mkdir(dirname) except OSError as e: if e.errno != errno.EEXIST: raise
def __init__(self, name, filename, mode='a', delete=False): Log.__init__(self, name) self.filename = filename self.errorname = filename + '.error' self.mode = mode self.delete = delete self.do_log = True dirname = os.path.dirname(filename) if dirname: try: os.mkdir(dirname) except OSError, e: if e.errno != errno.EEXIST: raise
class LogTest(unittest.TestCase): CORRELATE = Log def setUp(self): self.log = Log('testme') def testConstructor(self): self.assertEqual('', str(self.log)) def testGetError(self): self.assertEqual(self.log.get_error(), None) self.log.started() self.assertEqual(self.log.get_error(), None) try: raise FakeError() except FakeError: self.log.aborted(sys.exc_info()) self.assertTrue('FakeError' in self.log.get_error()) def testGetName(self): self.assertEqual(self.log.get_name(), 'testme') self.log.started() self.assertEqual(self.log.get_name(), 'testme') def testWrite(self): self.assertEqual('', str(self.log)) self.log.write('test', 'me', 'please') self.assertEqual(str(self.log), 'test me please') def testStarted(self): self.assertEqual('', str(self.log)) self.log.started() self.assertEqual(self.log.did_end, False) self.assertEqual('', str(self.log)) def testAborted(self): self.testStarted() before = str(self.log) try: raise FakeError() except FakeError: self.log.aborted(sys.exc_info()) self.assertTrue(str(self.log).startswith(before)) self.assertTrue('FakeError' in str(self.log), str(self.log)) def testSucceeded(self): self.testStarted() self.assertFalse(self.log.has_ended()) self.log.succeeded() self.assertEqual(str(self.log), '') self.assertTrue(self.log.has_ended()) self.assertFalse(self.log.has_error()) def testHasError(self): self.assertFalse(self.log.has_error()) self.testAborted() self.assertTrue(self.log.has_error()) def testHasEnded(self): self.assertFalse(self.log.has_ended()) self.testSucceeded() self.assertTrue(self.log.has_ended())
def setUp(self): self.log = Log('testme')
def succeeded(self): if self.delete and not self.has_error(): os.remove(self.filename) return Log.succeeded(self)
def add_log(self, job_id, name, attempt): log = Log(name) log.started() self.logs[job_id].append(log) self.started += 1 return log
class LogTest(unittest.TestCase): CORRELATE = Log def setUp(self): self.log = Log('testme') def testConstructor(self): self.assertEqual('', str(self.log)) def testGetError(self): self.assertEqual(self.log.get_error(), None) self.log.started() self.assertEqual(self.log.get_error(), None) try: raise FakeError() except FakeError: self.log.aborted(sys.exc_info()) self.assert_('FakeError' in self.log.get_error()) def testGetName(self): self.assertEqual(self.log.get_name(), 'testme') self.log.started() self.assertEqual(self.log.get_name(), 'testme') def testWrite(self): self.assertEqual('', str(self.log)) self.log.write('test', 'me', 'please') self.assertEqual(str(self.log), 'test me please') def testStarted(self): self.assertEqual('', str(self.log)) self.log.started() self.assertEqual(self.log.did_end, False) self.assertEqual('', str(self.log)) def testAborted(self): self.testStarted() before = str(self.log) try: raise FakeError() except FakeError: self.log.aborted(sys.exc_info()) self.assert_(str(self.log).startswith(before)) self.assert_('FakeError' in str(self.log), str(self.log)) def testSucceeded(self): self.testStarted() self.failIf(self.log.has_ended()) self.log.succeeded() self.assertEqual(str(self.log), '') self.assert_(self.log.has_ended()) self.failIf(self.log.has_error()) def testHasError(self): self.failIf(self.log.has_error()) self.testAborted() self.assert_(self.log.has_error()) def testHasEnded(self): self.failIf(self.log.has_ended()) self.testSucceeded() self.assert_(self.log.has_ended())