def test_merge(self): e_si = si.Event() # event test events = [ db.Event(e_si, 3, "a"), db.Event(e_si, 5, "b"), db.Event.make_empty(e_si), db.Event(e_si, 12, "c") ] result = db.combine(*events) self.assertEqual(result[0], "a") self.assertEqual(result[1], "b") self.assertEqual(result[2], "c") self.assertTrue(np.array_equal(result.TS, np.asarray([3, 5, 12]))) self.assertEqual(result.SI, e_si) # event empty test empty_events = [db.Event.make_empty(e_si), db.Event.make_empty(e_si)] empty_events_result = db.combine(*empty_events) self.assertEqual(empty_events_result, db.Event.make_empty(e_si)) # event empty test 1 empty_event = [db.Event.make_empty(e_si)] empty_event_result = db.combine(*empty_event) self.assertEqual(empty_event_result, db.Event.make_empty(e_si))
def test_equality(self): e_si = si.Event() # wrong event message test self.assertNotEqual(db.Event(e_si, 1, "a"), db.Event(e_si, 2, "WRONG")) # wrong event timestamp test self.assertNotEqual(db.Event(e_si, 7, "a"), db.Event(e_si, 77, "a"))
def test_multiple_sources(self): si1 = si.Event(id=1) si2 = si.Event(id=2) streams = [si1, si2] src_blocks = [db.Event(si1, 1, 1), db.Event(si2, 2, 2)] si_exp = si.Event() expected = [db.Event(si_exp, 1, 1), db.Event(si_exp, 2, 2)] self.check_processor(streams, src_blocks, {'out_0': expected}, DummyTransformation)
def test_db_comparisons(self): si1 = si.Event(id=1) si2 = si.Event(id=2) si3 = si.Event(id=1) db1 = db.Event(si1, 11, 'A') db2 = db.Event(si2, 11, 'A') db3 = db.Event(si3, 11, 'A') db4 = db.Event(si1, 11, 'B') db5 = db.Event(si1, 12, 'A') self.assertNotEqual(db1, db2) self.assertEqual(db1, db3) self.assertNotEqual(db1, db4) self.assertNotEqual(db1, db5) self.assertTrue(db1.is_similar(db2)) self.assertTrue(db1.is_similar(db3)) self.assertFalse(db1.is_similar(db4)) self.assertFalse(db1.is_similar(db5))
def test_events(self): e_si = si.Event() blocks = [] self.check(e_si, blocks) blocks = [ db.Event(e_si, 10, 'one'), db.Event(e_si, 40, 'two'), db.Event(e_si, 80, 'three'), db.Event(e_si, 110, True), db.Event(e_si, 120, 123), db.Event(e_si, 121, ['foo', 'bar']), db.Event(e_si, 122, (1, 2)), db.Event(e_si, 125, {'a': 'b'}), ] self.check(e_si, blocks)
def on_stop(): print("Stops") test_report.append(('onStop')) ch_si = si.Channels(3, 21, 1, "channels") ev_si = si.Event(2, "event") expected_report = [ ("onPrepare", ([si.Channels(3, 21.0, 1, "channels"), si.Event(2, "event")], "")), ("onStart"), ("onDataBlock", db.Channels(ch_si, 946729805250000000, [ [0.29475517441090415, -0.29475517441090415, 0.29475517441090415], [0.56332005806362195, -0.56332005806362195, 0.56332005806362195], [0.7818314824680298, -0.7818314824680298, 0.7818314824680298], [0.93087374864420414, -0.93087374864420414, 0.93087374864420414], [0.99720379718118013, -0.99720379718118013, 0.99720379718118013], [0.97492791218182362, -0.97492791218182362, 0.97492791218182362], [0.86602540378443871, -0.86602540378443871, 0.86602540378443871], [0.68017273777091969, -0.68017273777091969, 0.68017273777091969], [0.43388373911755823, -0.43388373911755823, 0.43388373911755823], [0.14904226617617472, -0.14904226617617472, 0.14904226617617472], [-0.14904226617617447, 0.14904226617617447, -0.14904226617617447], [-0.43388373911755801, 0.43388373911755801, -0.43388373911755801], [-0.68017273777091947, 0.68017273777091947, -0.68017273777091947], [-0.86602540378443837, 0.86602540378443837, -0.86602540378443837], [-0.97492791218182362, 0.97492791218182362, -0.97492791218182362], [-0.99720379718118024, 0.99720379718118024, -0.99720379718118024], [-0.93087374864420447, 0.93087374864420447, -0.93087374864420447], [-0.78183148246802991, 0.78183148246802991, -0.78183148246802991], [-0.56332005806362195, 0.56332005806362195, -0.56332005806362195], [-0.29475517441090471, 0.29475517441090471, -0.29475517441090471], [ -2.4492935982947064e-16, 2.4492935982947064e-16, -2.4492935982947064e-16 ], [0.29475517441090426, -0.29475517441090426, 0.29475517441090426], [0.56332005806362229, -0.56332005806362229, 0.56332005806362229], [0.78183148246802958, -0.78183148246802958, 0.78183148246802958], [0.93087374864420425, -0.93087374864420425, 0.93087374864420425], [0.99720379718118013, -0.99720379718118013, 0.99720379718118013], [0.97492791218182373, -0.97492791218182373, 0.97492791218182373], [0.86602540378443915, -0.86602540378443915, 0.86602540378443915], [0.68017273777091924, -0.68017273777091924, 0.68017273777091924], [0.43388373911755845, -0.43388373911755845, 0.43388373911755845], [0.14904226617617364, -0.14904226617617364, 0.14904226617617364], [-0.14904226617617292, 0.14904226617617292, -0.14904226617617292], [-0.43388373911755779, 0.43388373911755779, -0.43388373911755779], [-0.68017273777091869, 0.68017273777091869, -0.68017273777091869], [-0.86602540378443871, 0.86602540378443871, -0.86602540378443871], [-0.97492791218182351, 0.97492791218182351, -0.97492791218182351], [-0.99720379718118024, 0.99720379718118024, -0.99720379718118024], [-0.93087374864420425, 0.93087374864420425, -0.93087374864420425], [-0.78183148246803014, 0.78183148246803014, -0.78183148246803014], [-0.56332005806362295, 0.56332005806362295, -0.56332005806362295], [-0.29475517441090582, 0.29475517441090582, -0.29475517441090582], [ -4.8985871965894128e-16, 4.8985871965894128e-16, -4.8985871965894128e-16 ], [0.29475517441090315, -0.29475517441090315, 0.29475517441090315], [0.56332005806362206, -0.56332005806362206, 0.56332005806362206], [0.78183148246802947, -0.78183148246802947, 0.78183148246802947], [0.93087374864420447, -0.93087374864420447, 0.93087374864420447], [0.99720379718118013, -0.99720379718118013, 0.99720379718118013], [0.97492791218182373, -0.97492791218182373, 0.97492791218182373], [0.86602540378443837, -0.86602540378443837, 0.86602540378443837], [0.68017273777091936, -0.68017273777091936, 0.68017273777091936], [0.43388373911756023, -0.43388373911756023, 0.43388373911756023], [0.14904226617617389, -0.14904226617617389, 0.14904226617617389], [-0.14904226617617267, 0.14904226617617267, -0.14904226617617267], [-0.43388373911755757, 0.43388373911755757, -0.43388373911755757], [-0.6801727377709198, 0.6801727377709198, -0.6801727377709198], [-0.86602540378443771, 0.86602540378443771, -0.86602540378443771], [-0.97492791218182351, 0.97492791218182351, -0.97492791218182351], [-0.99720379718118013, 0.99720379718118013, -0.99720379718118013], [-0.93087374864420491, 0.93087374864420491, -0.93087374864420491], [-0.78183148246803025, 0.78183148246803025, -0.78183148246803025], [-0.56332005806362462, 0.56332005806362462, -0.56332005806362462], [-0.29475517441090265, 0.29475517441090265, -0.29475517441090265], [ -7.3478807948841188e-16, 7.3478807948841188e-16, -7.3478807948841188e-16 ] ])), ("onDataBlock", db.Event(ev_si, 946729905250000000, "test")), ("onStop") ] if expected_report != test_report: print("failed") print(test_report.__repr__()) print("but") print(expected_report.__repr__()) # raise Exception("Test didn't pass") print("passed")
def online(self, input): return db.combine( db.make_empty(self._si), *[ db.Event(self._si, block.TS[0:1], self._transform(block)) for block in input ])
def online(self, a, b): if len(a) > 0: return db.Event(self._si, a.TS, a[0]) if len(b) > 0: return db.Event(self._si, b.TS, b[0]) return db.make_empty(self._si)