コード例 #1
0
    def test_xlsx_input_formula(self):
        """ When a forumla is present, we should use the value, rather than the
        formula itself. """

        xlsxinput = XLSXInput(
            input_name="flattentool/tests/fixtures/xlsx/formula.xlsx")

        xlsxinput.read_sheets()

        assert xlsxinput.sub_sheet_names == ["main", "subsheet"]
        assert list(xlsxinput.get_sheet_lines("main")) == [
            {
                "colA": 1,
                "colB": 2
            },
            {
                "colA": 2,
                "colB": 4
            },
        ]
        assert list(xlsxinput.get_sheet_lines("subsheet")) == [
            {
                "colC": 3,
                "colD": 9
            },
            {
                "colC": 4,
                "colD": 12
            },
        ]
コード例 #2
0
    def test_xlsx_input(self):
        xlsxinput = XLSXInput(
            input_name="flattentool/tests/fixtures/xlsx/basic.xlsx")

        xlsxinput.read_sheets()

        assert xlsxinput.sub_sheet_names == ["main", "subsheet"]
        assert list(xlsxinput.get_sheet_lines("main")) == [
            {
                "colA": "cell1",
                "colB": "cell2"
            },
            {
                "colA": "cell3",
                "colB": "cell4"
            },
        ]
        assert list(xlsxinput.get_sheet_lines("subsheet")) == [
            {
                "colC": "cell5",
                "colD": "cell6"
            },
            {
                "colC": "cell7",
                "colD": "cell8"
            },
        ]
コード例 #3
0
    def test_xlsx_vertical(self):
        xlsxinput = XLSXInput(input_name='flattentool/tests/fixtures/xlsx/basic_transpose.xlsx', vertical_orientation=True)

        xlsxinput.read_sheets()

        assert xlsxinput.sub_sheet_names == ['main', 'subsheet']
        assert list(xlsxinput.get_sheet_lines('main')) == \
            [{'colA': 'cell1', 'colB': 'cell2'}, {'colA': 'cell3', 'colB': 'cell4'}]
        assert list(xlsxinput.get_sheet_lines('subsheet')) == \
            [{'colC': 'cell5', 'colD': 'cell6'}, {'colC': 'cell7', 'colD': 'cell8'}]
コード例 #4
0
    def test_xlsx_input(self):
        xlsxinput = XLSXInput(
            input_name='flattentool/tests/fixtures/xlsx/basic.xlsx')

        xlsxinput.read_sheets()

        assert xlsxinput.sub_sheet_names == ['main', 'subsheet']
        assert list(xlsxinput.get_sheet_lines('main')) == \
            [{'colA': 'cell1', 'colB': 'cell2'}, {'colA': 'cell3', 'colB': 'cell4'}]
        assert list(xlsxinput.get_sheet_lines('subsheet')) == \
            [{'colC': 'cell5', 'colD': 'cell6'}, {'colC': 'cell7', 'colD': 'cell8'}]
コード例 #5
0
    def test_xlsx_input_integer2(self):
        xlsxinput = XLSXInput(input_name='flattentool/tests/fixtures/xlsx/integer2.xlsx')

        xlsxinput.read_sheets()

        assert list(xlsxinput.get_sheet_lines('Sheet1')) == \
            [{'activity-status/@code': 2}]
        # This is a float, but is converted to an int in the unflatten step, see
        # test_input_SpreadsheetInput_unflatten.py
        # 'Basic with float'
        assert type(list(xlsxinput.get_sheet_lines('Sheet1'))[0]['activity-status/@code']) == float
        assert xlsxinput.sub_sheet_names == ['Sheet1']
コード例 #6
0
    def test_xlsx_input_integer(self):
        xlsxinput = XLSXInput(input_name='flattentool/tests/fixtures/xlsx/integer.xlsx')

        xlsxinput.read_sheets()

        assert list(xlsxinput.get_sheet_lines('main')) == \
            [{'colA': 1}]
        if sys.version_info[0] == 2:
            assert type(list(xlsxinput.get_sheet_lines('main'))[0]['colA']) == long
        else:
            assert type(list(xlsxinput.get_sheet_lines('main'))[0]['colA']) == int
        assert xlsxinput.sub_sheet_names == ['main']
コード例 #7
0
    def test_xlsx_input_formula(self):
        """ When a forumla is present, we should use the value, rather than the
        formula itself. """

        xlsxinput = XLSXInput(input_name='flattentool/tests/fixtures/xlsx/formula.xlsx')

        xlsxinput.read_sheets()

        assert xlsxinput.sub_sheet_names == ['main', 'subsheet']
        assert list(xlsxinput.get_sheet_lines('main')) == \
            [{'colA': 1, 'colB': 2}, {'colA': 2, 'colB': 4}]
        assert list(xlsxinput.get_sheet_lines('subsheet')) == \
            [{'colC': 3, 'colD': 9}, {'colC': 4, 'colD': 12}]
コード例 #8
0
    def test_xlsx_input_formula(self):
        """ When a forumla is present, we should use the value, rather than the
        formula itself. """

        xlsxinput = XLSXInput(
            input_name='flattentool/tests/fixtures/xlsx/formula.xlsx')

        xlsxinput.read_sheets()

        assert xlsxinput.sub_sheet_names == ['main', 'subsheet']
        assert list(xlsxinput.get_sheet_lines('main')) == \
            [{'colA': 1, 'colB': 2}, {'colA': 2, 'colB': 4}]
        assert list(xlsxinput.get_sheet_lines('subsheet')) == \
            [{'colC': 3, 'colD': 9}, {'colC': 4, 'colD': 12}]
コード例 #9
0
    def test_xlsx_input_integer(self):
        xlsxinput = XLSXInput(
            input_name='flattentool/tests/fixtures/xlsx/integer.xlsx')

        xlsxinput.read_sheets()

        assert list(xlsxinput.get_sheet_lines('main')) == \
            [{'colA': 1}]
        if sys.version_info[0] == 2:
            assert type(list(
                xlsxinput.get_sheet_lines('main'))[0]['colA']) == long
        else:
            assert type(list(
                xlsxinput.get_sheet_lines('main'))[0]['colA']) == int
        assert xlsxinput.sub_sheet_names == ['main']
コード例 #10
0
    def test_xlsx_input_integer2(self):
        xlsxinput = XLSXInput(
            input_name='flattentool/tests/fixtures/xlsx/integer2.xlsx')

        xlsxinput.read_sheets()

        assert list(xlsxinput.get_sheet_lines('Sheet1')) == \
            [{'activity-status/@code': 2}]
        # This is a float, but is converted to an int in the unflatten step, see
        # test_input_SpreadsheetInput_unflatten.py
        # 'Basic with float'
        assert type(
            list(xlsxinput.get_sheet_lines('Sheet1'))[0]
            ['activity-status/@code']) == float
        assert xlsxinput.sub_sheet_names == ['Sheet1']
コード例 #11
0
    def test_xlsx_input_utf8(self):
        """This is an xlsx file saved by OpenOffice. It seems to use UTF8 internally."""
        csvinput = XLSXInput(
            input_name='flattentool/tests/fixtures/xlsx/unicode.xlsx')

        csvinput.read_sheets()
        assert list(csvinput.get_sheet_lines('main'))[0]['id'] == 'éαГ😼𝒞人'
コード例 #12
0
    def test_xlsx_input_utf8(self):
        """This is an xlsx file saved by OpenOffice. It seems to use UTF8 internally."""
        xlsxinput = XLSXInput(
            input_name="flattentool/tests/fixtures/xlsx/unicode.xlsx")

        xlsxinput.read_sheets()
        assert list(xlsxinput.get_sheet_lines("main"))[0]["id"] == "éαГ😼𝒞人"
コード例 #13
0
    def test_xlsx_input_integer2(self):
        xlsxinput = XLSXInput(
            input_name="flattentool/tests/fixtures/xlsx/integer2.xlsx")

        xlsxinput.read_sheets()

        assert list(xlsxinput.get_sheet_lines("Sheet1")) == [{
            "activity-status/@code":
            2
        }]
        # This is a float, but is converted to an int in the unflatten step, see
        # test_input_SpreadsheetInput_unflatten.py
        # 'Basic with float'
        assert (type(
            list(xlsxinput.get_sheet_lines("Sheet1"))[0]
            ["activity-status/@code"]) == float)
        assert xlsxinput.sub_sheet_names == ["Sheet1"]
コード例 #14
0
    def test_xlsx_include_ignore(self):
        xlsxinput = XLSXInput(input_name='flattentool/tests/fixtures/xlsx/basic_meta.xlsx', 
                              include_sheets=['Meta'], vertical_orientation=True
                             )
        xlsxinput.read_sheets()
        assert xlsxinput.sub_sheet_names == ['Meta']
        assert list(xlsxinput.get_sheet_lines('Meta')) == \
            [{'a': 'a1', 'b': 'b1', 'c': 'c1'}]

        xlsxinput = XLSXInput(input_name='flattentool/tests/fixtures/xlsx/basic_meta.xlsx', 
                              exclude_sheets=['Meta'])
        xlsxinput.read_sheets()

        assert xlsxinput.sub_sheet_names == ['main', 'subsheet']
        assert list(xlsxinput.get_sheet_lines('main')) == \
            [{'colA': 'cell1', 'colB': 'cell2'}, {'colA': 'cell3', 'colB': 'cell4'}]
        assert list(xlsxinput.get_sheet_lines('subsheet')) == \
            [{'colC': 'cell5', 'colD': 'cell6'}, {'colC': 'cell7', 'colD': 'cell8'}]
コード例 #15
0
    def test_xlsx_input(self):
        xlsxinput = XLSXInput(input_name='flattentool/tests/fixtures/xlsx/basic.xlsx', main_sheet_name='main')
        assert xlsxinput.main_sheet_name == 'main'

        xlsxinput.read_sheets()

        assert list(xlsxinput.get_main_sheet_lines()) == \
            [{'colA': 'cell1', 'colB': 'cell2'}, {'colA': 'cell3', 'colB': 'cell4'}]
        assert xlsxinput.sub_sheet_names == ['subsheet']
        assert list(xlsxinput.get_sheet_lines('subsheet')) == \
            [{'colC': 'cell5', 'colD': 'cell6'}, {'colC': 'cell7', 'colD': 'cell8'}]
コード例 #16
0
    def test_xlsx_include_ignore(self):
        xlsxinput = XLSXInput(
            input_name='flattentool/tests/fixtures/xlsx/basic_meta.xlsx',
            include_sheets=['Meta'],
            vertical_orientation=True)
        xlsxinput.read_sheets()
        assert xlsxinput.sub_sheet_names == ['Meta']
        assert list(xlsxinput.get_sheet_lines('Meta')) == \
            [{'a': 'a1', 'b': 'b1', 'c': 'c1'}]

        xlsxinput = XLSXInput(
            input_name='flattentool/tests/fixtures/xlsx/basic_meta.xlsx',
            exclude_sheets=['Meta'])
        xlsxinput.read_sheets()

        assert xlsxinput.sub_sheet_names == ['main', 'subsheet']
        assert list(xlsxinput.get_sheet_lines('main')) == \
            [{'colA': 'cell1', 'colB': 'cell2'}, {'colA': 'cell3', 'colB': 'cell4'}]
        assert list(xlsxinput.get_sheet_lines('subsheet')) == \
            [{'colC': 'cell5', 'colD': 'cell6'}, {'colC': 'cell7', 'colD': 'cell8'}]
コード例 #17
0
    def test_xlsx_include_ignore(self):
        xlsxinput = XLSXInput(
            input_name="flattentool/tests/fixtures/xlsx/basic_meta.xlsx",
            include_sheets=["Meta"],
            vertical_orientation=True,
        )
        xlsxinput.read_sheets()
        assert xlsxinput.sub_sheet_names == ["Meta"]
        assert list(xlsxinput.get_sheet_lines("Meta")) == [{
            "a": "a1",
            "b": "b1",
            "c": "c1"
        }]

        xlsxinput = XLSXInput(
            input_name="flattentool/tests/fixtures/xlsx/basic_meta.xlsx",
            exclude_sheets=["Meta"],
        )
        xlsxinput.read_sheets()

        assert xlsxinput.sub_sheet_names == ["main", "subsheet"]
        assert list(xlsxinput.get_sheet_lines("main")) == [
            {
                "colA": "cell1",
                "colB": "cell2"
            },
            {
                "colA": "cell3",
                "colB": "cell4"
            },
        ]
        assert list(xlsxinput.get_sheet_lines("subsheet")) == [
            {
                "colC": "cell5",
                "colD": "cell6"
            },
            {
                "colC": "cell7",
                "colD": "cell8"
            },
        ]
コード例 #18
0
    def test_xlsx_input_types(self):
        xlsxinput = XLSXInput(
            input_name="flattentool/tests/fixtures/xlsx/types.xlsx")

        xlsxinput.read_sheets()

        assert list(xlsxinput.get_sheet_lines("main")) == [{
            "colInt":
            1,
            "colFloat":
            1.2,
            "colDate":
            datetime.datetime(2020, 3, 5),
            "colDateTime":
            datetime.datetime(2020, 2, 7, 16, 41, 0, 1),
        }]
        assert type(list(
            xlsxinput.get_sheet_lines("main"))[0]["colInt"]) == int
        assert type(list(
            xlsxinput.get_sheet_lines("main"))[0]["colFloat"]) == float
        assert xlsxinput.sub_sheet_names == ["main"]
コード例 #19
0
    def test_xlsx_input_utf8(self):
        """This is an xlsx file saved by OpenOffice. It seems to use UTF8 internally."""
        csvinput = XLSXInput(input_name='flattentool/tests/fixtures/xlsx/unicode.xlsx')

        csvinput.read_sheets()
        assert list(csvinput.get_sheet_lines('main'))[0]['id'] == 'éαГ😼𝒞人'