Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test function for empty ICGEM gdf file #345

Merged
merged 3 commits into from
Aug 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions harmonica/tests/test_icgem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

import numpy as np
import numpy.testing as npt
from pytest import raises
import pytest
from pytest import raises, warns

from .. import load_icgem_gdf

Expand Down Expand Up @@ -280,14 +281,20 @@ def test_corrupt_area(tmpdir):
load_icgem_gdf(corrupt)


def test_empty_file(tmpdir, recwarn):
"Empty ICGEM file"
@pytest.fixture(name="empty_fname")
def fixture_empty_fname(tmpdir):
"""
Return the path to a temporary empty file
"""
empty_fname = str(tmpdir.join("empty.gdf"))
with open(empty_fname, "w") as gdf_file:
gdf_file.write("")
with raises(IOError):
return empty_fname


def test_empty_file(empty_fname):
"Empty ICGEM file"
error = raises(IOError, match=r"Couldn't read \w+ field from gdf file header")
warn = warns(UserWarning, match=r"loadtxt: input contained no data")
with error, warn:
load_icgem_gdf(empty_fname)
assert len(recwarn) == 1
warning = recwarn.pop()
assert warning.category == UserWarning
assert "Empty input file" in str(warning.message)