Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
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())
Exemplo n.º 4
0
 def setUp(self):
     self.log = Log('testme')
Exemplo n.º 5
0
 def succeeded(self):
     if self.delete and not self.has_error():
         os.remove(self.filename)
         return
     Log.succeeded(self)
Exemplo n.º 6
0
 def succeeded(self):
     if self.delete and not self.has_error():
         os.remove(self.filename)
         return
     Log.succeeded(self)
Exemplo n.º 7
0
 def add_log(self, job_id, name, attempt):
     log = Log(name)
     log.started()
     self.logs[job_id].append(log)
     self.started += 1
     return log
Exemplo n.º 8
0
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())
Exemplo n.º 9
0
 def setUp(self):
     self.log = Log('testme')