Skip to content

Commit

Permalink
Add more test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Adam.Dybbroe <[email protected]>
  • Loading branch information
Adam.Dybbroe committed Dec 2, 2024
1 parent ba59c38 commit 9df160b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
31 changes: 31 additions & 0 deletions trollsched/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@
2 43013 98.7102 196.6451 0000981 27.6583 181.3633 14.19588904353826
"""

FAKE_XML_SCHEDULE = """<acquisition-schedule><properties><project>Pytroll</project><type>request</type><station>nrk</station><file-start>2024-12-02-21:54:34</file-start><file-end>2024-12-02-23:54:34</file-end><requested-by>SMHI</requested-by><requested-on>2024-12-02-19:55:05</requested-on></properties><pass satellite="noaa18" start-time="2024-12-02-22:01:31" end-time="2024-12-02-22:16:17" /><pass satellite="npp" start-time="2024-12-02-22:38:18" end-time="2024-12-02-22:49:39" /><pass satellite="noaa20" start-time="2024-12-02-23:01:26" end-time="2024-12-02-23:14:17" /></acquisition-schedule>""" # noqa

TEST_TLEFILE2 = """NOAA-20
1 43013U 17073A 24336.73680280 .00000000 00000+0 21070-3 0 00017
2 43013 98.7240 271.9468 0002361 91.7021 243.0836 14.19579317364671
NOAA 18
1 28654U 05018A 24336.77887833 .00000603 00000+0 34401-3 0 9991
2 28654 98.8621 52.2610 0013351 310.3593 49.6413 14.13439071 6932
SUOMI NPP
1 37849U 11061A 24336.86623462 .00000353 00000+0 18825-3 0 9992
2 37849 98.7391 272.4265 0002092 106.9131 253.2275 14.19509233678657
"""

@pytest.fixture
def fake_tle_file(tmp_path):
"""Write fake TLE file."""
Expand All @@ -44,9 +57,27 @@ def fake_tle_file(tmp_path):

return file_path

@pytest.fixture
def fake_long_tle_file(tmp_path):
"""Write fake TLE file."""
file_path = tmp_path / "some_more_tles.txt"
with open(file_path, "w") as fpt:
fpt.write(TEST_TLEFILE2)

return file_path

@pytest.fixture
def fake_noaa20_viirs_pass_instance(fake_tle_file):
"""Create a fake trollsched.,satpass instance for NOAA-20 VIIRS."""
starttime = datetime(2024, 9, 17, 1, 25, 52)
endtime = starttime + timedelta(minutes=15)
return create_pass("NOAA-20", "viirs", starttime, endtime, str(fake_tle_file))

@pytest.fixture
def fake_xml_schedule_file(tmp_path):
"""Create a fake XML schedule file."""
file_path = tmp_path / "20241202-195434-aquisition-schedule-request-nrk.xml"
with open(file_path, "w") as fpt:
fpt.write(FAKE_XML_SCHEDULE)

return file_path
19 changes: 19 additions & 0 deletions trollsched/tests/test_pass_outlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
create_shapefile_filename,
create_shapefile_from_pass,
get_shapely_polygon_from_lonlat,
shapefiles_from_schedule_xml_requests,
)

CONT_POLY_LON = np.array([-2.13452262, -2.29587336, -2.71901413, 2.49884179, 1.84466852,
Expand Down Expand Up @@ -92,3 +93,21 @@ def test_create_shapefile_from_pass(fake_noaa20_viirs_pass_instance, tmp_path):
assert tmp_filename.exists()
nfiles = len([f for f in tmp_filename.parent.glob("fake_noaa20_viirs_shapefile.*")])
assert nfiles == 5


@pytest.mark.usefixtures("fake_long_tle_file")
@pytest.mark.usefixtures("fake_xml_schedule_file")
def test_shapefiles_from_schedule_xml_requests(fake_xml_schedule_file, fake_long_tle_file, tmp_path):
"""Test create shapefiles from an xml schedule request file."""
output_dir = tmp_path / "results"
output_dir.mkdir()
satellites = ["Suomi NPP", "NOAA 18", "NOAA-20"]
shapefiles_from_schedule_xml_requests(str(fake_xml_schedule_file), satellites,
str(fake_long_tle_file), str(output_dir))

n18files = [str(name) for name in output_dir.glob("avhrr_NOAA-18_202412022201_202412022216_outline.*")]
assert len(n18files) == 5
nppfiles = [str(name) for name in output_dir.glob("viirs_Suomi-NPP_202412022238_202412022249_outline.*")]
assert len(nppfiles) == 5
n20files = [str(name) for name in output_dir.glob("viirs_NOAA-20_202412022301_202412022314_outline.*")]
assert len(n20files) == 5

0 comments on commit 9df160b

Please sign in to comment.