Exemple #1
0
    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)
Exemple #2
0
 def test_mock_rows(self):
     assert list(mock_rows()) == [
         Row(['Объем ВВП', '', '', '', '']),
         Row(['млрд.рублей', '', '', '', '']),
         Row(['1991', '4823', '901', '1102', '1373', '1447']),
         Row(['Индекс ВВП, в % к прошлому периоду/ GDP index, percent']),
         Row(['1999', '106,4', '98,1', '103,1', '111,4', '112,0']),
         Row(['Индекс промышленного производства']),
         Row(['в % к соответствующему периоду предыдущего года']),
         Row(['1991', '102,7', '101,1', '102,2', '103,3', '104,4'])
     ]
Exemple #3
0
    def test_init(self):
        # ID: Test verifies that [r for r in rows] is equivalent to list(rows)
        # regardless if rows is generator or an iterable (e.g. a list)
        # This allows to make robust experiments to RowStack.__init__() method.
        def gen():
            yield Row(["dot oo...eh", "1", "2"])
            yield Row(["wed more text", "1", "2"])
            yield Row(["zed some text"])

        a_generator = gen()
        a_list = [
            Row(["dot oo...eh", "1", "2"]),
            Row(["wed more text", "1", "2"]),
            Row(["zed some text"]),
        ]

        from_generator = RowStack(a_generator)
        from_list = RowStack(a_list)

        assert from_generator.rows == from_list.rows
Exemple #4
0
def mock_rows():
    yield Row(["apt extra text", "1", "2"])
    yield Row(["bat aa...ah", "1", "2"])
    yield Row(["can extra text", "1", "2"])
    yield Row(["dot oo...eh", "1", "2"])
    yield Row(["wed more text", "1", "2"])
    yield Row(["zed some text"])
Exemple #5
0
def test_to_rows():
    csvfile = io.StringIO(full_string)
    rows = list(to_rows(csvfile))
    assert rows[0] == Row(["Объем ВВП"])
    assert rows[1] == Row(["1999", "4823"])
    assert rows[2] == Row(["2000", "7306"])
Exemple #6
0
 def test_pop_segment_and_remaining_rows_behaviour(self, rowstack):
     b = rowstack.pop("apt", "wed")
     assert len(b) == 4
     c = rowstack.remaining_rows()
     assert c[0] == Row(["wed more text", "1", "2"])
     assert c[1] == Row(["zed some text"])
Exemple #7
0
 def test_pop(self, rowstack):
     a = rowstack.pop("bat", "dot")
     assert a == [
         Row(["bat aa...ah", "1", "2"]),
         Row(["can extra text", "1", "2"])
     ]
Exemple #8
0
 def gen():
     yield Row(["dot oo...eh", "1", "2"])
     yield Row(["wed more text", "1", "2"])
     yield Row(["zed some text"])
Exemple #9
0
 def test_finds_one_unit(self):
     unit_mapper = {"%": "pct"}
     assert Row(["Rate, %"]).get_unit(unit_mapper) == "pct"
Exemple #10
0
 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)
Exemple #11
0
 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
Exemple #12
0
 def test_finds_one_varname(self):
     assert Row(["1. abcd"]).get_varname({"ab": "ZZZ"}) == "ZZZ"
Exemple #13
0
 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
Exemple #14
0
 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
Exemple #15
0
 def setup_method(self):
     self.row1 = Row(["Объем ВВП", "", "", "", ""])
     self.row2 = Row(["1991 1)", "4823", "901", "1102", "1373", "1447"])
     self.row3 = Row(["abcd", "1", "2"])
Exemple #16
0
 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"
from csv2df.reader import Row
from csv2df.parser import Table

labels = {0: 'GDP_bln_rub',
          1: 'GDP_rog',
          2: 'INDPRO_yoy'}

parsed_varnames = {0: 'GDP',
                   1: 'GDP',
                   2: 'INDPRO'}

parsed_units = {0: 'bln_rub',
                1: 'rog',
                2: 'yoy'}

headers = {0: [Row(['Объем ВВП', '', '', '', '']),
               Row(['млрд.рублей', '', '', '', ''])],
           1: [Row(['Индекс ВВП, в % к прошлому периоду/ GDP index, percent'])],
           2: [Row(['Индекс промышленного производства']),
               Row(['в % к соответствующему периоду предыдущего года'])]
           }

data_items = {0: [Row(["1991", "4823", "901", "1102", "1373", "1447"])],
              1: [Row(['1991', '106,4', '98,1', '103,1', '111,4', '112,0'])],
              2: [Row(['1991', '102,7', '101,1', '102,2', '103,3', '104,4'])]
              }


class Sample:
    """Fixtures for testing"""
    def rows(i):
def test_to_rows():
    csvfile = io.StringIO(full_string)
    rows = list(to_rows(csvfile))
    assert rows[0] == Row(['Объем ВВП'])
    assert rows[1] == Row(['1999', '4823'])
    assert rows[2] == Row(['2000', '7306'])