def test_parse_marble_multiple_digits(self): string = "-ab-cde--" " 012345678901234567890" results = parse(string) expected = [ mess_on_next(1.0, "ab"), mess_on_next(4.0, "cde"), ] assert results == expected
def test_parse_marble_multiple_digits_int(self): string = "-1-22-333-" " 012345678901234567890" results = parse(string) expected = [ mess_on_next(1.0, 1), mess_on_next(3.0, 22), mess_on_next(6.0, 333), ] assert results == expected
def test_parse_marble_multiple_digits_float(self): string = "-1.0--2.345--6.7e8-" " 012345678901234567890" results = parse(string) expected = [ mess_on_next(1.0, float("1.0")), mess_on_next(6.0, float("2.345")), mess_on_next(13.0, float("6.7e8")), ] assert results == expected
def test_parse_marble_completed(self): string = "-ab-c--|" " 012345678901234567890" results = parse(string) expected = [ mess_on_next(1.0, "ab"), mess_on_next(4.0, "c"), mess_on_completed(7.0), ] assert results == expected
def test_parse_marble_timedelta(self): string = "a--b---c" " 012345678901234567890" ts = 0.1 results = parse(string, timespan=datetime.timedelta(seconds=ts)) expected = [ mess_on_next(0 * ts, "a"), mess_on_next(3 * ts, "b"), mess_on_next(7 * ts, "c"), ] assert results == expected
def test_parse_marble_with_space(self): string = " -a b- c- de |" " 01 23 45 67 8901234567890" results = parse(string) expected = [ mess_on_next(1.0, "ab"), mess_on_next(4.0, "c"), mess_on_next(6.0, "de"), mess_on_completed(8.0), ] assert results == expected
def test_parse_marble_time_shift(self): string = "-ab----c-d-|" " 012345678901234567890" offset = 10.0 results = parse(string, time_shift=offset) expected = [ mess_on_next(1.0 + offset, "ab"), mess_on_next(7.0 + offset, "c"), mess_on_next(9.0 + offset, "d"), mess_on_completed(11.0 + offset), ] assert results == expected
def test_parse_marble_with_error(self): string = "-a-b-c--#--" " 012345678901234567890" ex = Exception("ex") results = parse(string, error=ex) expected = [ mess_on_next(1.0, "a"), mess_on_next(3.0, "b"), mess_on_next(5.0, "c"), mess_on_error(8.0, ex), ] assert results == expected
def test_expected( string: str, lookup: Optional[Dict[Union[str, float], Any]] = None, error: Optional[Exception] = None, ) -> List[Recorded[Any]]: messages = parse( string, timespan=timespan, time_shift=subscribed, lookup=lookup, error=error, ) return messages_to_records(messages)
def test_parse_marble_with_group(self): string = "-x(ab,12,1.5)-c--(de)-|" " 012345678901234567890123" " 0 1 2 " results = parse(string) expected = [ mess_on_next(1.0, "x"), mess_on_next(2.0, "ab"), mess_on_next(2.0, 12), mess_on_next(2.0, float("1.5")), mess_on_next(14.0, "c"), mess_on_next(17.0, "de"), mess_on_completed(22.0), ] assert results == expected
def test_parse_marble_lookup(self): string = "-ab-c-12-3-|" " 012345678901234567890" lookup = { "ab": "aabb", "c": "cc", 12: "1122", 3: 33, } results = parse(string, lookup=lookup) expected = [ mess_on_next(1.0, "aabb"), mess_on_next(4.0, "cc"), mess_on_next(6.0, "1122"), mess_on_next(9.0, 33), mess_on_completed(11.0), ] assert results == expected
def test_parse_just_on_error(self): string = "#" results = parse(string) expected = [mess_on_error(0.0, Exception("error"))] assert results == expected
def test_parse_marble_raise_with_elements_after_completed(self): string = "-a-b-c--|-1-" " 012345678901234567890" with self.assertRaises(ValueError): parse(string, raise_stopped=True)
def test_parse_marble_raise_with_elements_after_error_group(self): string = "-a-b-c--(#,1)-" " 012345678901234567890" with self.assertRaises(ValueError): parse(string, raise_stopped=True)
def test_parse_just_on_next(self): string = "a" results = parse(string) expected = [mess_on_next(0.0, "a")] assert results == expected
def test_parse_just_on_completed(self): string = "|" results = parse(string) expected = [mess_on_completed(0.0)] assert results == expected
def test_parse_just_on_error_specified(self): string = "#" ex = Exception("Foo") results = parse(string, error=ex) expected = [mess_on_error(0.0, ex)] assert results == expected