File: test_converter.py

package info (click to toggle)
python-tabledata 1.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 300 kB
  • sloc: python: 1,406; makefile: 69; sh: 5
file content (55 lines) | stat: -rw-r--r-- 1,455 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

from collections import OrderedDict

from tabledata import to_value_matrix


class Test_to_value_matrix:
    def test_normal_dict_rows(self):
        expect = [
            [1, None, None],
            [None, 2.1, "hoge"],
            [0, 0.1, "foo"],
            [None, None, None],
            [-1, -0.1, "bar"],
        ]

        assert (
            to_value_matrix(
                ["A", "B", "C"],
                [
                    {"A": 1},
                    {"B": 2.1, "C": "hoge"},
                    {"A": 0, "B": 0.1, "C": "foo"},
                    {},
                    {"A": -1, "B": -0.1, "C": "bar", "D": "extra"},
                ],
            )
            == expect
        )

    def test_normal_OrderedDict_rows(self):
        expect = [
            [1, None, None],
            [None, 2.1, "hoge"],
            [0, 0.1, "foo"],
            [None, None, None],
            [-1, -0.1, "bar"],
        ]

        assert (
            to_value_matrix(
                ["A", "B", "C"],
                [
                    OrderedDict({"A": 1}),
                    OrderedDict({"B": 2.1, "C": "hoge"}),
                    OrderedDict({"A": 0, "B": 0.1, "C": "foo"}),
                    OrderedDict({}),
                    OrderedDict({"A": -1, "B": -0.1, "C": "bar", "D": "extra"}),
                ],
            )
            == expect
        )