def test_forAllTime(): ts = Timeseries() assert len(ts) == 0 ts[None] = 1 assert len(ts) == 1 assert ts[None] == 1 assert ts[-1] == 1 assert ts[0] == 1 assert ts[1] == 1 ts[None] = 2 assert ts[None] == 2 assert ts[-1] == 2 assert ts[0] == 2 assert ts[1] == 2 with AssertRaises(ObjectForAllTimeError): ts[1] = 3 with AssertRaises(ObjectForAllTimeError): del ts[1] del ts[None] assert len(ts) == 0 ts[None] = 1 assert len(ts) == 1 ts.removeAll() assert len(ts) == 0 ts[1] = 1 with AssertRaises(ObjectForAllTimeError): ts[None] = 2
def test_sliceAccess(): ts = Timeseries() ts.addAll([1, 3, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16]) # test expected slice exceptions with AssertRaises(TimestampError): ts[0.5:1] # t1 before first timestamp with AssertRaises(TimestampError): ts[0.5:] # t1 before first timestamp with AssertRaises(TimestampError): ts[:0.5] # t2 before first timestamp with AssertRaises(NotImplementedError): ts[slice(None, None, 1)] # stride not handled (yet?) with AssertRaises(AssertionError): ts[-1:] # negative t1 without t2 with AssertRaises(AssertionError): ts[:-1] # t2 before first timestamp with AssertRaises(AssertionError): ts[4:-3] # negative t2 # no ellipsis because python doesn't allow them in slice notation assert ts[4:3] == ([3, 7, 8], [12, 13, 14]), ts[4:3] assert ts[4:100] == ([3, 7, 8, 9, 10], [12, 13, 14, 15, 16]), ts[4:100] assert ts[9.5:1] == ([9], [15]), ts[9.5:1] assert ts[9.5:2] == ([9, 10], [15, 16]), ts[9.5:2] assert ts[9.5:] == ([9, 10], [15, 16]), ts[9.5:] assert ts[-100:4] == ([1, 3], [11, 12]), ts[-100:4] assert ts[-1:7.5] == ([7], [13]) assert ts[-2:7.5] == ([3, 7], [12, 13]) assert ts[-1:20] == ([10], [16]) assert ts[:20] == ([1, 3, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16]) assert ts[:] == ([1, 3, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16]) # test expected tuple exceptions with AssertRaises(AssertionError): ts[-1,] with AssertRaises(AssertionError): ts[None, 10] with AssertRaises(AssertionError): ts[1, None] with AssertRaises(AssertionError): ts[None, None] with AssertRaises(AssertionError): ts[-1, 1] with AssertRaises(AssertionError): ts[1, -1] with AssertRaises(AssertionError): ts[5, 1] with AssertRaises(TimestampError): ts[0.5, 1] assert ts[1, 2] == ([1], [11]), ts[1, 2] assert ts[1, 8.5] == ([1, 3, 7, 8], [11, 12, 13, 14]), ts[1, 8.5] assert ts[1, 20] == ([1, 3, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16]), ts[1, 20] assert ts[10, 20] == ([10], [16]), ts[10, 20] assert ts[20, 20] == ([10], [16]), ts[20, 20] assert ts[9.5, ...] == ([9, 10], [15, 16]), ts[9.5, ...] assert ts[..., 20] == ([1, 3, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16]), ts[..., 20] assert ts[..., ...] == ([1, 3, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16]), ts[..., 20] """