예제 #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
                },
            ))
예제 #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)
예제 #3
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)
예제 #4
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},
        ))
예제 #5
0
    def test_ignores_empty_rows(self):
        rows = [
            ["name", "size"],
            ["val1", 123],
            ["", ""],
            ["val2", 456]
        ]

        records = list(make_dicts(rows))

        assert_that(records, only_contains(
            {"name": "val1", "size": 123},
            {"name": "val2", "size": 456},
        ))
예제 #6
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},
        ))
예제 #7
0
    def test_ignores_empty_rows(self):
        rows = [["name", "size"], ["val1", 123], ["", ""], ["val2", 456]]

        records = list(make_dicts(rows))

        assert_that(
            records,
            only_contains(
                {
                    "name": "val1",
                    "size": 123
                },
                {
                    "name": "val2",
                    "size": 456
                },
            ))
예제 #8
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
                },
            ))