def test_invalid_utf8(self): # create the log file watcher first rp = self.makeRP() test_filename = 'test_runprocess_test_invalid_utf8.log' try: lf = runprocess.LogFileWatcher(rp, 'test', test_filename, follow=False, poll=False) # now write to the log file INVALID_UTF8 = b'before\xffafter' with open(test_filename, 'wb') as f: f.write(INVALID_UTF8) # the watcher picks up the changed log lf.poll() # flush she buffer rp._sendBuffers() # the log file content was captured and the invalid byte replaced with \ufffd (the # replacement character, often a black diamond with a white question mark) REPLACED = u'before\ufffdafter' self.assertEqual(rp.builder.updates, [{'log': ('test', REPLACED)}]) finally: lf.stop() os.remove(f.name)
def test_statFile_exists(self): rp = self.makeRP() open('statfile.log', 'w').write('hi') lf = runprocess.LogFileWatcher(rp, 'test', 'statfile.log', False) st = lf.statFile() self.assertEqual(st and st[2], 2, "statfile.log exists and size is correct") os.remove('statfile.log')
def test_statFile_missing(self): rp = self.makeRP() test_filename = 'test_runprocess_test_statFile_missing.log' if os.path.exists(test_filename): os.remove(test_filename) lf = runprocess.LogFileWatcher(rp, 'test', test_filename, False) self.assertFalse(lf.statFile(), "{} doesn't exist".format(test_filename))
def test_statFile_exists(self): rp = self.makeRP() test_filename = 'test_runprocess_test_statFile_exists.log' try: with open(test_filename, 'w') as f: f.write('hi') lf = runprocess.LogFileWatcher(rp, 'test', test_filename, False) st = lf.statFile() self.assertEqual(st and st[2], 2, "statfile.log exists and size is correct") finally: os.remove(test_filename)
def test_statFile_missing(self): rp = self.makeRP() if os.path.exists('statfile.log'): os.remove('statfile.log') lf = runprocess.LogFileWatcher(rp, 'test', 'statfile.log', False) self.assertFalse(lf.statFile(), "statfile.log doesn't exist")