# Path: apiary/tools/timestamp.py
# class TimeStamp(object):
# 
#     def __init__(self, s=0, us=0):
#         self.seconds = s
#         self.micros = int(us)
# 
#         if type(s) is str:
#             parts = s.split('.')  # pylint: disable-msg=E1101
#             n = len(parts)
#             self.seconds = 0
#             if n >= 1:
#                 self.seconds = int(parts[0])
#             if n >= 2:
#                 us = int((parts[1] + "0000000")[0:7]) / 10.0
#                 self.micros = int(round(us))
# 
#         self._normalize()
# 
#     def __str__(self):
#         return "%d.%06d" % (self.seconds, self.micros)
# 
#     def __repr__(self):
#         return "TimeStamp(%d,%d)" % (self.seconds, self.micros)
# 
#     def __hash__(self):
#         return hash(self.seconds) ^ hash(self.micros)
# 
#     def __cmp__(self, other):
#         r = cmp(self.seconds, other.seconds)
#         if r == 0:
#             r = cmp(self.micros, other.micros)
#         return r
# 
#     def __add__(self, other):
#         s = self.seconds + other.seconds
#         us = self.micros + other.micros
#         if (us >= 1000000):
#             us -= 1000000
#             s += 1
#         return TimeStamp(s, us)
# 
#     def __sub__(self, other):
#         s = self.seconds - other.seconds
#         us = self.micros - other.micros
#         if (us < 0):
#             us += 1000000
#             s -= 1
#         return TimeStamp(s, us)
# 
#     def __mul__(self, number):
#         seconds = self.seconds * float(number)
#         micros = self.micros * float(number)
# 
#         return TimeStamp(seconds, micros)
# 
#     def __float__(self):
#         return self.seconds + self.micros / 1.0e6
# 
#     def _normalize(self):
#         if type(self.seconds) is float:
#             (frac_part, int_part) = math.modf(self.seconds)
#             self.seconds = int(int_part)
#             self.micros += int(round(frac_part * 1.0e6))
# 
#         while self.micros > 1000000:
#             self.micros -= 1000000
#             self.seconds += 1
# 
#         while self.micros < -1000000:
#             self.micros += 1000000
#             self.seconds -= 1


from StringIO import StringIO
from apiary.mysql.sqllog import *
from apiary.tools.timestamp import TimeStamp
import unittest
        self.assertEqual(e.time, TimeStamp(10001.703))
        self.assertEqual(e.id, FakeJob)
        self.assertEqual(e.state, 'Quit')
    
    def testTimeTo(self):
        seq = Sequence()
        e1 = Event(10001.700, FakeJob, TestSource, 'QueryStart', 'SELECT')
        e2 = Event(10001.717, FakeJob, TestSource, 'Quit', 'Quit')
        
        self.assert_(seq.timeto(e1) is None)
        
        seq.note(e1)
        self.assertEqual(seq.timeto(e1), TimeStamp(0))
        self.assertEqual(seq.timeto(e2), TimeStamp(0.017))
        


class SimpleCoalesce(CoalesceSequences):
    def __init__(self):
        CoalesceSequences.__init__(self)
        self.sequences = []
        
    def fullSequence(self, e):
        self.sequences.append(e)
        
class TestCoalesce(unittest.TestCase):

    def assertEvent(self, e, time, id, state, body=None):
        self.assertEqual(e.source, TestSource)
        if time is not None:

# Path: apiary/tools/timestamp.py
# class TimeStamp(object):
# 
#     def __init__(self, s=0, us=0):
#         self.seconds = s
#         self.micros = int(us)
# 
#         if type(s) is str:
#             parts = s.split('.')  # pylint: disable-msg=E1101
#             n = len(parts)
#             self.seconds = 0
#             if n >= 1:
#                 self.seconds = int(parts[0])
#             if n >= 2:
#                 us = int((parts[1] + "0000000")[0:7]) / 10.0
#                 self.micros = int(round(us))
# 
#         self._normalize()
# 
#     def __str__(self):
#         return "%d.%06d" % (self.seconds, self.micros)
# 
#     def __repr__(self):
#         return "TimeStamp(%d,%d)" % (self.seconds, self.micros)
# 
#     def __hash__(self):
#         return hash(self.seconds) ^ hash(self.micros)
# 
#     def __cmp__(self, other):
#         r = cmp(self.seconds, other.seconds)
#         if r == 0:
#             r = cmp(self.micros, other.micros)
#         return r
# 
#     def __add__(self, other):
#         s = self.seconds + other.seconds
#         us = self.micros + other.micros
#         if (us >= 1000000):
#             us -= 1000000
#             s += 1
#         return TimeStamp(s, us)
# 
#     def __sub__(self, other):
#         s = self.seconds - other.seconds
#         us = self.micros - other.micros
#         if (us < 0):
#             us += 1000000
#             s -= 1
#         return TimeStamp(s, us)
# 
#     def __mul__(self, number):
#         seconds = self.seconds * float(number)
#         micros = self.micros * float(number)
# 
#         return TimeStamp(seconds, micros)
# 
#     def __float__(self):
#         return self.seconds + self.micros / 1.0e6
# 
#     def _normalize(self):
#         if type(self.seconds) is float:
#             (frac_part, int_part) = math.modf(self.seconds)
#             self.seconds = int(int_part)
#             self.micros += int(round(frac_part * 1.0e6))
# 
#         while self.micros > 1000000:
#             self.micros -= 1000000
#             self.seconds += 1
# 
#         while self.micros < -1000000:
#             self.micros += 1000000
#             self.seconds -= 1


# Path: historical/test_apiary/sqllog.py
from StringIO import StringIO
from apiary.mysql.sqllog import *
from apiary.tools.timestamp import TimeStamp
import unittest

        self.assertEqual(e.time, TimeStamp(10001.703))
        self.assertEqual(e.id, FakeJob)
        self.assertEqual(e.state, 'Quit')
    
    def testTimeTo(self):
        seq = Sequence()
        e1 = Event(10001.700, FakeJob, TestSource, 'QueryStart', 'SELECT')
        e2 = Event(10001.717, FakeJob, TestSource, 'Quit', 'Quit')
        
        self.assert_(seq.timeto(e1) is None)
        
        seq.note(e1)
        self.assertEqual(seq.timeto(e1), TimeStamp(0))
        self.assertEqual(seq.timeto(e2), TimeStamp(0.017))
        


class SimpleCoalesce(CoalesceSequences):
    def __init__(self):
        CoalesceSequences.__init__(self)
        self.sequences = []
        
    def fullSequence(self, e):
        self.sequences.append(e)
        
class TestCoalesce(unittest.TestCase):

    def assertEvent(self, e, time, id, state, body=None):
        self.assertEqual(e.source, TestSource)
        if time is not None:

            if not isinstance(time, TimeStamp):