def testInitTermRead(self): self.assertRaises(win32trace.error, win32trace.read) win32trace.InitRead() result = win32trace.read() self.assertEquals(result, '') win32trace.TermRead() self.assertRaises(win32trace.error, win32trace.read) win32trace.InitRead() self.assertRaises(win32trace.error, win32trace.InitRead) win32trace.InitWrite() self.assertRaises(win32trace.error, win32trace.InitWrite) win32trace.TermWrite() win32trace.TermRead()
def CollectorThread(stopEvent, file): win32trace.InitRead() handle = win32trace.GetHandle() # Run this thread at a lower priority to the main message-loop (and printing output) # thread can keep up import win32process win32process.SetThreadPriority( win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_BELOW_NORMAL ) try: while 1: rc = win32event.WaitForMultipleObjects( (handle, stopEvent), 0, win32event.INFINITE ) if rc == win32event.WAIT_OBJECT_0: # About the only char we can't live with is \0! file.write(win32trace.read().replace("\0", "<null>")) else: # Stop event break finally: win32trace.TermRead() print("Thread dieing")
def tearDown(self): try: win32trace.TermRead() except win32trace.error: pass try: win32trace.TermWrite() except win32trace.error: pass
def CheckNoOtherReaders(): win32trace.write("Hi") time.sleep(0.05) if win32trace.read() != "Hi": # Reset everything so following tests still fail with this error!S win32trace.TermRead() win32trace.TermWrite() raise RuntimeError, "An existing win32trace reader appears to be " \ "running - please stop this process and try again"
def testInitTermRead(self): with pytest.raises(win32trace.error): win32trace.read() win32trace.InitRead() result = win32trace.read() assert result == '' win32trace.TermRead() with pytest.raises(win32trace.error): win32trace.read() win32trace.InitRead() with pytest.raises(win32trace.error): win32trace.InitRead() win32trace.InitWrite() with pytest.raises(win32trace.error): win32trace.InitWrite() win32trace.TermWrite() win32trace.TermRead()
def testInit(self): win32trace.TermRead() win32trace.TermWrite() traceObject = win32trace.GetTracer() self.assertRaises(win32trace.error, traceObject.read) self.assertRaises(win32trace.error, traceObject.write, '') win32trace.InitRead() win32trace.InitWrite() self.assertEquals('', traceObject.read()) traceObject.write('Syver')
def testTermSematics(self): win32trace.InitWrite() win32trace.write('Ta da') # if we both Write and Read are terminated at the same time, # we lose the data as the win32 object is closed. Note that # if another writer is running, we do *not* lose the data - so # test for either the correct data or an empty string win32trace.TermWrite() win32trace.InitRead() self.failUnless(win32trace.read() in ['Ta da', '']) win32trace.TermRead() # we keep the data because we init read before terminating write win32trace.InitWrite() win32trace.write('Ta da') win32trace.InitRead() win32trace.TermWrite() self.assertEquals('Ta da', win32trace.read()) win32trace.TermRead()
def testInit(self): win32trace.TermRead() win32trace.TermWrite() traceObject = win32trace.GetTracer() with pytest.raises(win32trace.error): traceObject.read() with pytest.raises(win32trace.error): traceObject.write('') win32trace.InitRead() win32trace.InitWrite() assert '' == traceObject.read() traceObject.write('Syver')
def tearDown(self): win32trace.TermWrite() win32trace.TermRead()
def setUp(self): # clear old data win32trace.InitRead() win32trace.read() win32trace.TermRead()
assert each.verifyWritten() assert self.areBucketsFull() def _RunAsTestProcess(): # Run as an external process by the main tests. WriterThread.BucketCount = int(sys.argv[2]) threadCount = int(sys.argv[3]) threads = [WriterThread() for each in range(threadCount)] win32trace.InitWrite() for thread in threads: thread.start() for thread in threads: thread.join() for thread in threads: if not thread.verifyWritten(): sys.exit(-1) if __name__ == '__main__': if sys.argv[1:2]==["/run_test_process"]: _RunAsTestProcess() sys.exit(0) # If some other win32traceutil reader is running, these tests fail # badly (as the other reader sometimes sees the output!) win32trace.InitRead() win32trace.InitWrite() CheckNoOtherReaders() # reset state so test env is back to normal win32trace.TermRead() win32trace.TermWrite() unittest.main()