def test_record_adds_data(): trace = Trace() assert trace.as_tuple() == () trace.record(t=1, v=10) assert trace.as_tuple() == ((1, 10), ) trace.record(t=2, v=13) assert trace.as_tuple() == ( (1, 10), (2, 13), )
def test_trace_creation_with_2x2_data_without_mode_is_the_same_as_samples(): data = ((1, 2), (10, 20)) # t=1, v=10; t=2, v=20 trace_default = Trace(data) trace_samples = Trace(data, mode='samples') assert trace_default.as_tuple() == trace_samples.as_tuple()
def test_trace_creation_with_single_item(data): trace = Trace(data) assert not trace.empty assert len(trace) == 1 assert trace.as_tuple() == ((1, 10), )
def test_trace_creation_with_2x2_data_using_mode_argument(mode, expected): trace = Trace(((1, 2), (10, 20)), mode=mode) assert trace.as_tuple() == expected
def test_trace_creation_with_valid_data_given_in_pairs(): data = [(1, 5), (2, 8), (3, 40), (9, 34)] trace = Trace(data) assert not trace.empty assert len(trace) == 4 assert trace.as_tuple() == tuple(data)
def test_as_tuple_with_illegal_mode_raises_error(): trace = Trace([[0, 0], [1, 5]]) with pytest.raises(ValueError) as excinfo: trace.as_tuple('wrong mode') assert 'invalid mode' in str(excinfo.value).lower()
def test_as_tuple(data, mode, expected): trace = Trace(data) if expected is None: expected = data assert trace.as_tuple(mode=mode) == expected
def test_trace_creation_with_valid_values_and_timestamps(): trace = Trace([[1, 2, 3], [10, 11, 9]]) assert not trace.empty assert len(trace) == 3 assert trace.as_tuple() == ((1, 10), (2, 11), (3, 9))
def test_trace_is_initially_empty(): trace = Trace() assert trace.empty assert len(trace) == 0 assert trace.as_tuple() == ()