Ejemplo n.º 1
0
    def test_make_records_from_rows(self):
        rows = [
            ["name", "size"],
            ["bottle", 123],
            ["screen", 567],
            ["mug", 12],
        ]

        records = make_dicts(rows)

        assert_that(
            records,
            only_contains(
                {
                    "name": "bottle",
                    "size": 123
                },
                {
                    "name": "screen",
                    "size": 567
                },
                {
                    "name": "mug",
                    "size": 12
                },
            ))
Ejemplo n.º 2
0
    def test_fail_if_a_row_contains_fewer_values_than_the_first_row(self):
        rows = [
            ["name", "size"],
            ["bottle", 123],
            ["screen"],
        ]

        self.assertRaises(ParseError, lambda rows: list(make_dicts(rows)),
                          rows)
    def as_json(self):
        json = None

        with open(self.filename) as spreadsheet:
            if is_excel(spreadsheet):
                lines = parse_excel(spreadsheet)
            else:
                lines = parse_csv(spreadsheet)

            json = list(make_dicts(lines))

        return json
    def as_json(self):
        json = None

        with open(self.filename) as spreadsheet:
            if is_excel(spreadsheet):
                lines = parse_excel(spreadsheet)
            else:
                lines = parse_csv(spreadsheet)

            json = list(make_dicts(lines))

        return json
Ejemplo n.º 5
0
    def test_processes_rows_containg_just_numbers_correctly(self):
        rows = [
            ['count'],
            [818],
            [602],
        ]

        records = list(make_dicts(rows))

        assert_that(records, only_contains(
            {'count': 818},
            {'count': 602},
        ))
Ejemplo n.º 6
0
    def test_ignores_empty_rows(self):
        rows = [["name", "size"], ["val1", 123], ["", ""], [None, None],
                ["val2", 456]]

        records = list(make_dicts(rows))

        assert_that(
            records,
            only_contains(
                {
                    "name": "val1",
                    "size": 123
                },
                {
                    "name": "val2",
                    "size": 456
                },
            ))
Ejemplo n.º 7
0
    def test_works_if_given_an_iterator(self):
        def rows():
            yield ("name", "size")
            yield ("bottle", 123)
            yield ("screen", 567)

        records = list(make_dicts(rows()))

        assert_that(
            records,
            only_contains(
                {
                    "name": "bottle",
                    "size": 123
                },
                {
                    "name": "screen",
                    "size": 567
                },
            ))