-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG skip zero length truth files more robustly (#17)
* BUG skip zero length truth files more robustly * TST fix buggy test * wrong column * try again
- Loading branch information
Showing
2 changed files
with
67 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import tempfile | ||
import os | ||
|
||
from montara.eastlake_step import read_galsim_truth_file | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize("head", [True, False]) | ||
@pytest.mark.parametrize("ndata", [0, 1, 2]) | ||
def test_read_file(head, ndata): | ||
letters = "abc" | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
fname = os.path.join(tmpdir, "blah.dat") | ||
with open(fname, "w") as fp: | ||
if head: | ||
fp.write("# a band c\n") | ||
for nd in range(ndata): | ||
fp.write("%d %s %f\n" % (nd, letters[nd], nd*3.14159)) | ||
|
||
if not head and ndata > 0: | ||
with pytest.raises(RuntimeError) as e: | ||
read_galsim_truth_file(fname) | ||
|
||
assert "No header line found for truth file" in str(e.value) | ||
else: | ||
d = read_galsim_truth_file(fname) | ||
if ndata == 0: | ||
assert d is None | ||
else: | ||
assert d.dtype.descr == [("a", "<i8"), ("band", "<U1"), ("c", "<f8")] | ||
assert d.shape[0] == ndata |