diff --git a/trollsched/tests/conftest.py b/trollsched/tests/conftest.py index 38f423b..6cdd7b1 100644 --- a/trollsched/tests/conftest.py +++ b/trollsched/tests/conftest.py @@ -35,6 +35,19 @@ 2 43013 98.7102 196.6451 0000981 27.6583 181.3633 14.19588904353826 """ +FAKE_XML_SCHEDULE = """Pytrollrequestnrk2024-12-02-21:54:342024-12-02-23:54:34SMHI2024-12-02-19:55:05""" # 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.""" @@ -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 diff --git a/trollsched/tests/test_pass_outlines.py b/trollsched/tests/test_pass_outlines.py index 8c51cd7..8b8be8b 100644 --- a/trollsched/tests/test_pass_outlines.py +++ b/trollsched/tests/test_pass_outlines.py @@ -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, @@ -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