Пример #1
0
def SetupForPrint():
    win32trace.InitWrite()
    try:  # Under certain servers, sys.stdout may be invalid.
        print("Redirecting output to win32trace remote collector")
    except:
        pass
    win32trace.setprint()  # this works in an rexec environment.
Пример #2
0
 def setUp(self):
     win32trace.InitRead()
     # If any other writers are running (even if not actively writing),
     # terminating the module will *not* close the handle, meaning old data
     # will remain. This can cause other tests to fail.
     win32trace.read()
     win32trace.InitWrite()
Пример #3
0
 def testInitTermWrite(self):
     with pytest.raises(win32trace.error):
         win32trace.write('Hei')
     win32trace.InitWrite()
     win32trace.write('Johan Galtung')
     win32trace.TermWrite()
     with pytest.raises(win32trace.error):
         win32trace.write('Hei')
Пример #4
0
    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()
Пример #5
0
 def setUp(self):
     WriterThread.BucketCount = self.BucketCount        
     win32trace.InitRead()
     win32trace.read() # clear any old data.
     win32trace.InitWrite()
     CheckNoOtherReaders()
     self.threads = [WriterThread() for each in range(self.FullBucket)]
     self.buckets = range(self.BucketCount)
     for each in self.buckets:
         self.buckets[each] = 0
Пример #6
0
 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')
Пример #7
0
    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()
Пример #8
0
 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')
Пример #9
0
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)
Пример #10
0
    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()
Пример #11
0
 def testInitTermWrite(self):
     self.assertRaises(win32trace.error, win32trace.write, 'Hei')
     win32trace.InitWrite()
     win32trace.write('Johan Galtung')
     win32trace.TermWrite()
     self.assertRaises(win32trace.error, win32trace.write, 'Hei')
Пример #12
0
 def setUp(self):
     win32trace.InitRead()
     win32trace.read() # clear any old data
     win32trace.InitWrite()
Пример #13
0
            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()
Пример #14
0
 def testInitTermWrite(self):
     self.assertRaises(win32trace.error, win32trace.write, "Hei")
     win32trace.InitWrite()
     win32trace.write("Johan Galtung")
     win32trace.TermWrite()
     self.assertRaises(win32trace.error, win32trace.write, "Hei")