-
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.
- Loading branch information
1 parent
00de859
commit 569dde2
Showing
5 changed files
with
92 additions
and
5 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,24 @@ | ||
import os.path | ||
|
||
import pytest | ||
|
||
DATA_DIR_NAME = "data" | ||
TEST_DIR = os.path.dirname(__file__) | ||
|
||
|
||
@pytest.fixture | ||
def test_data_dir(): | ||
"""Return the base test data directory.""" | ||
return os.path.join(TEST_DIR, DATA_DIR_NAME) | ||
|
||
|
||
@pytest.fixture | ||
def grid_data_good_file(test_data_dir): | ||
"""Return the file path for the good grid input file.""" | ||
return os.path.join(test_data_dir, "grid_input_good.ecsv") | ||
|
||
|
||
@pytest.fixture | ||
def grid_data_bad_file(test_data_dir): | ||
"""Return the file path for the bad grid input file.""" | ||
return os.path.join(test_data_dir, "grid_input_bad.txt") |
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,6 @@ | ||
0.0 1.0 0.0 | ||
0.0 1.5 1.0 | ||
1.0 1.0 2.0 | ||
1.0 1.5 3.0 | ||
2.0 1.5 5.0 | ||
2.0 1.0 4.0 |
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,8 @@ | ||
# Comment up here. | ||
x0, x1, values | ||
0.0, 1.0, 0.0 | ||
0.0, 1.5, 1.0 | ||
1.0, 1.0, 2.0 | ||
1.0, 1.5, 3.0 | ||
2.0, 1.0, 4.0 | ||
2.0, 1.5, 5.0 |
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,25 @@ | ||
import numpy as np | ||
import pytest | ||
from tdastro.io_utils import read_grid_data | ||
|
||
|
||
def test_read_grid_data_good(grid_data_good_file): | ||
"""Test that we can read a well formatted grid data file.""" | ||
x0, x1, values = read_grid_data(grid_data_good_file, format="ascii.csv") | ||
x0_expected = np.array([0.0, 1.0, 2.0]) | ||
x1_expected = np.array([1.0, 1.5]) | ||
values_expected = np.array([[0.0, 1.0], [2.0, 3.0], [4.0, 5.0]]) | ||
|
||
np.testing.assert_allclose(x0, x0_expected, atol=1e-5) | ||
np.testing.assert_allclose(x1, x1_expected, atol=1e-5) | ||
np.testing.assert_allclose(values, values_expected, atol=1e-5) | ||
|
||
|
||
def test_read_grid_data_bad(grid_data_bad_file): | ||
"""Test that we correctly handle a badly formatted grid data file.""" | ||
# We load without a problem is validation is off. | ||
x0, x1, values = read_grid_data(grid_data_bad_file, format="ascii") | ||
assert values.shape == (3, 2) | ||
|
||
with pytest.raises(ValueError): | ||
_, _, _ = read_grid_data(grid_data_bad_file, format="ascii", validate=True) |