• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenDataServices / flatten-tool / 6507626273

13 Oct 2023 11:25AM UTC coverage: 42.006% (-53.7%) from 95.72%
6507626273

Pull #433

github

odscjames
New "Geo" optional dependencies

https://github.com/OpenDataServices/flatten-tool/issues/424
Pull Request #433: New "Geo" optional dependencies

38 of 38 new or added lines in 6 files covered. (100.0%)

1466 of 3490 relevant lines covered (42.01%)

4.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.77
/flattentool/tests/test_unflatten.py
1
import json
10✔
2
import os
10✔
3

4
import pytest
10✔
5

6
from flattentool import unflatten
10✔
7

8

9
def test_360_main_sheetname_insensitive(tmpdir):
10✔
10
    input_name = "flattentool/tests/fixtures/xlsx/fundingproviders-grants_2_grants.xlsx"
×
11
    unflatten(
×
12
        input_name=input_name,
13
        output_name=tmpdir.join("output_grant.json").strpath,
14
        input_format="xlsx",
15
        schema="flattentool/tests/fixtures/360-giving-schema.json",
16
        main_sheet_name="grants",
17
        root_list_path="grants",
18
        root_id="",
19
        convert_titles=True,
20
    )
21
    output_json_grants = json.load(tmpdir.join("output_grant.json"))
×
22

23
    input_name = "flattentool/tests/fixtures/xlsx/fundingproviders-grants_2_grants_sheet_title_case.xlsx"
×
24
    unflatten(
×
25
        input_name=input_name,
26
        output_name=tmpdir.join("output_grant_sheet_title_case.json").strpath,
27
        input_format="xlsx",
28
        schema="flattentool/tests/fixtures/360-giving-schema.json",
29
        main_sheet_name="grants",
30
        root_list_path="grants",
31
        root_id="",
32
        convert_titles=True,
33
    )
34
    output_json_Grants = json.load(tmpdir.join("output_grant_sheet_title_case.json"))
×
35

36
    assert output_json_grants == output_json_Grants
×
37

38

39
def test_360_fields_case_insensitive(tmpdir):
10✔
40
    input_name = "flattentool/tests/fixtures/xlsx/fundingproviders-grants_2_grants.xlsx"
×
41
    unflatten(
×
42
        input_name=input_name,
43
        output_name=tmpdir.join("output_grant.json").strpath,
44
        input_format="xlsx",
45
        schema="flattentool/tests/fixtures/360-giving-schema.json",
46
        main_sheet_name="grants",
47
        root_list_path="grants",
48
        root_id="",
49
        convert_titles=True,
50
    )
51
    output_json_grants = json.load(tmpdir.join("output_grant.json"))
×
52

53
    input_name = "flattentool/tests/fixtures/xlsx/fundingproviders-grants_2_grants_title_space_case.xlsx"
×
54
    unflatten(
×
55
        input_name=input_name,
56
        output_name=tmpdir.join("output_space_case.json").strpath,
57
        input_format="xlsx",
58
        schema="flattentool/tests/fixtures/360-giving-schema.json",
59
        main_sheet_name="grants",
60
        root_list_path="grants",
61
        root_id="",
62
        convert_titles=True,
63
    )
64
    output_json_space_case = json.load(tmpdir.join("output_space_case.json"))
×
65

66
    assert output_json_grants == output_json_space_case
×
67

68

69
@pytest.mark.parametrize(
10✔
70
    "dirname,input_format",
71
    [
72
        ("examples/iati", "csv"),
73
        ("examples/iati", "ods"),
74
        ("examples/iati", "xlsx"),
75
        ("examples/iati_multilang", "csv"),
76
    ],
77
)
78
def test_unflatten_xml(tmpdir, dirname, input_format):
8✔
79
    schema_path = "examples/iati"
×
80
    schemas = ["iati-activities-schema.xsd", "iati-common.xsd"]
×
81
    schema_filepaths = ["{}/{}".format(schema_path, schema) for schema in schemas]
×
82
    unflatten(
×
83
        input_name=dirname
84
        + (".{}".format(input_format) if input_format != "csv" else ""),
85
        output_name=tmpdir.join("output.xml").strpath,
86
        input_format=input_format,
87
        root_list_path="iati-activity",
88
        id_name="iati-identifier",
89
        xml=True,
90
        xml_schemas=schema_filepaths,
91
    )
92
    assert (
×
93
        open(os.path.join(dirname, "expected.xml")).read()
94
        == tmpdir.join("output.xml").read()
95
    )
96

97

98
@pytest.mark.parametrize("dirname", ["examples/iati_xml_comment"])
10✔
99
def test_unflatten_xml_comment(tmpdir, dirname):
8✔
100
    """
101
    Edit default xml comment 'XML generated by flatten-tool' by 'XML generated by ODS'
102
    """
103
    schema_path = "examples/iati"
×
104
    schemas = ["iati-activities-schema.xsd", "iati-common.xsd"]
×
105
    schema_filepaths = ["{}/{}".format(schema_path, schema) for schema in schemas]
×
106
    unflatten(
×
107
        input_name=dirname,
108
        output_name=tmpdir.join("output.xml").strpath,
109
        input_format="csv",
110
        root_list_path="iati-activity",
111
        id_name="iati-identifier",
112
        xml=True,
113
        xml_schemas=schema_filepaths,
114
        xml_comment="XML generated by ODS",
115
    )
116
    assert (
×
117
        open(os.path.join(dirname, "expected.xml")).read()
118
        == tmpdir.join("output.xml").read()
119
    )
120

121

122
@pytest.mark.parametrize("input_format", ["xlsx", "ods"])
10✔
123
def test_unflatten_org_xml_minimal(tmpdir, input_format):
8✔
124
    schema_path = "examples/iati"
×
125
    schemas = [
×
126
        "iati-activities-schema.xsd",
127
        "iati-organisations-schema.xsd",
128
        "iati-common.xsd",
129
    ]
130
    schema_filepaths = ["{}/{}".format(schema_path, schema) for schema in schemas]
×
131
    unflatten(
×
132
        input_name="flattentool/tests/fixtures/{}/iati-org.{}".format(
133
            input_format, input_format
134
        ),
135
        output_name=tmpdir.join("output.xml").strpath,
136
        input_format=input_format,
137
        id_name="organisation-identifier",
138
        xml=True,
139
        metatab_name="Meta",
140
        xml_schemas=schema_filepaths,
141
    )
142
    assert (
×
143
        open("flattentool/tests/fixtures/iati-org.xml").read()
144
        == tmpdir.join("output.xml").read()
145
    )
146

147

148
@pytest.mark.parametrize("input_format", ["xlsx"])
10✔
149
def test_unflatten_org_xml_with_documents(tmpdir, input_format):
8✔
150
    schema_path = "examples/iati"
×
151
    schemas = [
×
152
        "iati-activities-schema.xsd",
153
        "iati-organisations-schema.xsd",
154
        "iati-common.xsd",
155
    ]
156
    schema_filepaths = ["{}/{}".format(schema_path, schema) for schema in schemas]
×
157
    unflatten(
×
158
        input_name="flattentool/tests/fixtures/{}/IATI CoVE #organisation #broken-docs #template #public #demo.{}".format(
159
            input_format, input_format
160
        ),
161
        output_name=tmpdir.join("output.xml").strpath,
162
        input_format=input_format,
163
        id_name="organisation-identifier",
164
        xml=True,
165
        metatab_name="Meta",
166
        xml_schemas=schema_filepaths,
167
    )
168
    assert (
×
169
        open("flattentool/tests/fixtures/iati-org-with-documents.xml").read()
170
        == tmpdir.join("output.xml").read()
171
    )
172

173

174
@pytest.mark.parametrize("input_format", ["xlsx", "ods"])
10✔
175
def test_unflatten_empty_column_header(tmpdir, input_format):
8✔
176
    unflatten(
×
177
        input_name="flattentool/tests/fixtures/{}/empty_column_header.{}".format(
178
            input_format, input_format
179
        ),
180
        output_name=tmpdir.join("output.json").strpath,
181
        input_format=input_format,
182
    )
183
    assert (
×
184
        tmpdir.join("output.json").read()
185
        == """{
186
    "main": [
187
        {
188
            "colA": "cell1"
189
        },
190
        {
191
            "colA": "cell3"
192
        }
193
    ]
194
}"""
195
    )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc