Skip to content

Commit

Permalink
tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernestas Toliatas authored and Ernestas Toliatas committed May 17, 2023
1 parent df1d895 commit 50b4de8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
4 changes: 2 additions & 2 deletions spinta/manifests/tabular/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ def _text_to_tabular(
yield torow(DATASET, {
'property': prop.name + '@' + lang,
'type': prop.dtype.name,
'level': prop.level.value,
'level': prop.level.value if prop.level is not None else '',
'access': prop.given.access
})

Expand Down Expand Up @@ -1996,7 +1996,7 @@ def _write_csv(
rows: Iterator[ManifestRow],
cols: List[ManifestColumn],
) -> None:
with path.open('w') as f:
with path.open('w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=cols)
writer.writeheader()
writer.writerows(rows)
Expand Down
2 changes: 1 addition & 1 deletion spinta/manifests/yaml/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def list_yaml_files(manifest: YamlManifest) -> Iterator[pathlib.Path]:

def read_yaml_file(path: pathlib.Path):
try:
with path.open() as f:
with path.open(encoding='utf8') as f:
for data in yaml.load_all(f):
yield data
except (ParserError, ScannerError, YAMLError) as e:
Expand Down
42 changes: 17 additions & 25 deletions tests/datasets/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,10 +1924,8 @@ def test_file(rc, tmp_path, sqlite):
assert listdata(resp, full=True) == [
{
'name': 'Lithuania',
'flag': {
'_id': 'lt.png',
'_content_type': None, # FIXME: Should be 'image/png'.
},
'flag._id': 'lt.png',
'flag._content_type': None, # FIXME: Should be 'image/png'.
},
]

Expand Down Expand Up @@ -1989,10 +1987,8 @@ def test_push_file(
assert listdata(resp, full=True) == [
{
'name': 'Lithuania',
'flag': {
'_id': 'lt.png',
'_content_type': None, # FIXME: Should be 'image/png'.
},
'flag._id': 'lt.png',
'flag._content_type': None, # FIXME: Should be 'image/png'.
},
]
_id = resp.json()['_data'][0]['_id']
Expand Down Expand Up @@ -2037,10 +2033,8 @@ def test_image(rc, tmp_path, sqlite):
assert listdata(resp, full=True) == [
{
'name': 'Lithuania',
'flag': {
'_id': 'lt.png',
'_content_type': None, # FIXME: Should be 'image/png'.
},
'flag._id': 'lt.png',
'flag._content_type': None, # FIXME: Should be 'image/png'.
},
]

Expand Down Expand Up @@ -2102,10 +2096,8 @@ def test_image_file(
assert listdata(resp, full=True) == [
{
'name': 'Lithuania',
'flag': {
'_id': 'lt.png',
'_content_type': None, # FIXME: Should be 'image/png'.
},
'flag._id': 'lt.png',
'flag._content_type': None, # FIXME: Should be 'image/png'.
},
]
_id = resp.json()['_data'][0]['_id']
Expand Down Expand Up @@ -2202,18 +2194,18 @@ def test_push_null_foreign_key(
assert listdata(resp, full=True, sort='name') == [
{
'name': 'Ryga',
'country': {'_id': countries['Latvia']},
'embassy': {'_id': None},
'country._id': countries['Latvia'],
'embassy._id': None,
},
{
'name': 'Vilnius',
'country': {'_id': countries['Lithuania']},
'embassy': {'_id': countries['Latvia']},
'country._id': countries['Lithuania'],
'embassy._id': countries['Latvia'],
},
{
'name': 'Winterfell',
'country': {'_id': None},
'embassy': {'_id': None},
'country._id': None,
'embassy._id': None,
},
]

Expand Down Expand Up @@ -2277,11 +2269,11 @@ def test_push_self_ref(
assert listdata(resp, full=True) == [
{
'name': 'Trakai',
'governance': {'_id': cities['Vilnius']},
'governance._id': cities['Vilnius'],
},
{
'name': 'Vilnius',
'governance': {'_id': None},
'governance._id': None,
},
]

Expand Down Expand Up @@ -2520,7 +2512,7 @@ def test_cast_string(


def test_type_text_push(postgresql, rc, cli: SpintaCliRunner, responses, tmpdir, geodb, request):
create_tabular_manifest(tmpdir / 'manifest_text.csv', striptable('''
create_tabular_manifest(tmpdir / 'manifest.csv', striptable('''
d | r | b | m | property| type | ref | source | access
datasets/gov/example | | | |
| data | sql | | |
Expand Down
4 changes: 2 additions & 2 deletions tests/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def test_getall(model: str, app: TestClient):

resp = app.get('/datasets/backends/postgres/dataset/:all')
assert listdata(resp, full=True) == [
{'code': 'lt', 'continent._id': eu, 'title': 'Lithuania'},
{'country._id': lt, 'title': 'Vilnius'},
{'title': 'Europe'},
{'code': 'lt', 'continent': {'_id': eu}, 'title': 'Lithuania'},
{'country': {'_id': lt}, 'title': 'Vilnius'},
]

resp = app.get('/datasets/csv/:all')
Expand Down

0 comments on commit 50b4de8

Please sign in to comment.