コード例 #1
0
 def testFlushUnbuffered(self) -> None:
     try:
         et = EventTracer(self.tmpfile)
         et.flush(self.tmpfile)
         self.assertTrue(False)
     except Exception:
         self.assertTrue(True)
コード例 #2
0
    def testEndOutstanding(self) -> None:
        et = EventTracer()
        et.clear()
        # clearing an un-used thread shouldn't crash

        et.begin("a")
        et.begin("b")
        et.begin("c")
        self.assertEqual(3, len(et.buffer))

        et.clear()
        self.assertEqual(6, len(et.buffer))

        et.flush(self.tmpfile)
        self.assertEqual(0, len(et.buffer))
コード例 #3
0
    def testFlushingWrites(self) -> None:
        # Write two streams and make sure there's only one beginning
        et1 = EventTracer()
        et2 = EventTracer()
        et1.complete(nanotime(), 1, "flushed 1")
        et2.complete(nanotime(), 1, "flushed 2")
        et1.flush(self.tmpfile)
        et2.flush(self.tmpfile)

        # finished_data = data, minus trailing comma, plus closing brace
        with open(self.tmpfile) as fp:
            data = fp.read()
        finished_data = data[:-2] + "\n]"

        buffer = json.loads(finished_data)
        self.assertEqual(2, len(buffer))