From 2d81d5088006a690f10dcfcabcc3068ad27d32cd Mon Sep 17 00:00:00 2001 From: Panu Lahtinen Date: Tue, 18 Nov 2025 13:21:31 +0200 Subject: [PATCH 1/3] Add empty line to written TLE files --- pyorbital/tests/test_tlefile.py | 4 ++-- pyorbital/tlefile.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pyorbital/tests/test_tlefile.py b/pyorbital/tests/test_tlefile.py index 2d2264c..f0ae9b4 100644 --- a/pyorbital/tests/test_tlefile.py +++ b/pyorbital/tests/test_tlefile.py @@ -859,7 +859,7 @@ def test_write_tle_txt(self): assert "%" not in files[0] # The satellite name should be in the file with open(files[0], "r") as fid: - data = fid.read().split("\n") + data = fid.read().strip("\n").split("\n") assert len(data) == 3 assert "ISS" in data[0] assert data[1] == LINE1 @@ -883,7 +883,7 @@ def test_write_tle_txt(self): files = sorted(glob.glob(os.path.join(tle_dir, "tle_*txt"))) assert len(files) == 2 with open(files[1], "r") as fid: - data = fid.read().split("\n") + data = fid.read().strip("\n").split("\n") assert len(data) == 2 assert data[0] == LINE1 assert data[1] == LINE2 diff --git a/pyorbital/tlefile.py b/pyorbital/tlefile.py index b9730b5..787c4f3 100644 --- a/pyorbital/tlefile.py +++ b/pyorbital/tlefile.py @@ -680,6 +680,8 @@ def write_tle_txt(self): with open(fname, "w") as fid: fid.write("\n".join(data)) + # Add a line-change after the last entry + fid.write("\n") logging.info("Wrote %d TLEs to %s", len(data), fname) From c8491a8e143b3a9a745e25689928e2e1f1188303 Mon Sep 17 00:00:00 2001 From: Panu Lahtinen Date: Tue, 18 Nov 2025 14:14:28 +0200 Subject: [PATCH 2/3] Clarify test docstrings --- pyorbital/tests/test_tlefile.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pyorbital/tests/test_tlefile.py b/pyorbital/tests/test_tlefile.py index f0ae9b4..685926e 100644 --- a/pyorbital/tests/test_tlefile.py +++ b/pyorbital/tests/test_tlefile.py @@ -533,11 +533,7 @@ def test_init(self): @mock.patch("pyorbital.tlefile.requests") def test_fetch_plain_tle_not_configured(self, requests): - """Test downloading and a TLE file from internet.""" - requests.get = mock.MagicMock() - requests.get.return_value = _get_req_response(200) - - # Not configured + """Test that plain TLE downloading is not called when not configured.""" self.dl.config["downloaders"] = {} res = self.dl.fetch_plain_tle() assert res == {} @@ -545,7 +541,7 @@ def test_fetch_plain_tle_not_configured(self, requests): @mock.patch("pyorbital.tlefile.requests") def test_fetch_plain_tle_two_sources(self, requests): - """Test downloading and a TLE file from internet.""" + """Test downloading a TLE file from internet.""" requests.get = mock.MagicMock() requests.get.return_value = _get_req_response(200) From 9ec69e66c99c93984c5d62851f2708bd3fbb6193 Mon Sep 17 00:00:00 2001 From: Panu Lahtinen Date: Tue, 18 Nov 2025 14:30:38 +0200 Subject: [PATCH 3/3] Test that written TLE file ends with a line-change --- pyorbital/tests/test_tlefile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyorbital/tests/test_tlefile.py b/pyorbital/tests/test_tlefile.py index 685926e..702adbb 100644 --- a/pyorbital/tests/test_tlefile.py +++ b/pyorbital/tests/test_tlefile.py @@ -855,7 +855,9 @@ def test_write_tle_txt(self): assert "%" not in files[0] # The satellite name should be in the file with open(files[0], "r") as fid: - data = fid.read().strip("\n").split("\n") + data = fid.read() + assert data.endswith("\n") + data = data.strip("\n").split("\n") assert len(data) == 3 assert "ISS" in data[0] assert data[1] == LINE1