def _is_found(line: str, rows: list): """ Return: True, if *line* found at start of *rows[0]* False otherwise """ if not isinstance(rows, list): raise TypeError(rows) for row in rows: r = Row(row) if r.startswith(line): return True return False
def test_eq_compares_name_and_data_attributes(self): class MockRow: name = "abcd" data = ["1", "2"] r = MockRow assert Row(["abcd", "1", "2"]).__eq__(r)
def startswith(row, text): return Row(row).startswith(text)
def test_on_letters_inside_word_finds_nothing(self): # will not find anything, becase 'bc' is in the middle of string assert Row(["1. abcd"]).get_varname({"bc": "ZZZ"}) is False
def test_finds_one_varname(self): assert Row(["1. abcd"]).get_varname({"ab": "ZZZ"}) == "ZZZ"
def test_mathches_vs_startswith(self): row = Row(["many words in my head", "", "", ""]) # any matching word is ok for Row.matches() # Row.startswith() only tests beginning of *Row.name* assert row.matches("words") is True assert row.startswith("words") is False
def test_startswith_returns_bool(self): assert self.row1.startswith("Объем ВВП") is True assert self.row2.startswith("Объем ВВП") is False assert self.row1.startswith("ВВП") is False assert Row(["1.1 Объем ВВП"]).startswith("Объем ВВП") is False
def setup_method(self): self.row1 = Row(["Объем ВВП", "", "", "", ""]) self.row2 = Row(["1991 1)", "4823", "901", "1102", "1373", "1447"]) self.row3 = Row(["abcd", "1", "2"])
def test_get_unit_uses_first_entry_in_unit_mapper_oredered_dict(self): unit_mapper = odict([("% change", "rog"), ("%", "pct")]) assert Row(["1. abcd, % change"]).get_unit(unit_mapper) == "rog" assert Row(["1. abcd, % change"]).get_unit(unit_mapper) != "pct"
def test_finds_one_unit(self): unit_mapper = {"%": "pct"} assert Row(["Rate, %"]).get_unit(unit_mapper) == "pct"
def test_on_similar_mapper_keys_finds_too_many_and_raises_error(self): # finds too many entries, raises error with pytest.raises(ValueError): varname_mapper_dict = {"abc": "ZZZ", "1. ab": "YYY"} assert Row(["1. abcd"]).get_varname(varname_mapper_dict)