diff --git a/src/osmium/replication/utils.py b/src/osmium/replication/utils.py index ef67ca1..dd41f5f 100644 --- a/src/osmium/replication/utils.py +++ b/src/osmium/replication/utils.py @@ -57,7 +57,7 @@ def get_replication_header(fname: str) -> ReplicationHeader: LOG.warning("Sequence id '%d' in OSM file header is negative. Ignored.", seq) seq = None except ValueError: - LOG.warning("Sequence id '%s' in OSM file header is not a number. Ignored.", seq) + LOG.warning("Sequence id '%s' in OSM file header is not a number. Ignored.", seqstr) seq = None else: seq = None diff --git a/test/test_replication_utils.py b/test/test_replication_utils.py index eff4a0a..1db9f03 100644 --- a/test/test_replication_utils.py +++ b/test/test_replication_utils.py @@ -4,6 +4,8 @@ # # Copyright (C) 2025 Sarah Hoffmann and others. # For a full list of authors see the git log. +import logging + import osmium.replication.utils as rutil from helpers import mkdate @@ -25,3 +27,49 @@ def test_get_replication_header_full(test_data_dir): assert val.url == 'http://download.geofabrik.de/europe/andorra-updates' assert val.sequence == 2167 assert val.timestamp == mkdate(2019, 2, 23, 21, 15, 2) + + +def test_get_replication_header_invalid_sequence(caplog): + from unittest.mock import MagicMock, patch + + mock_header = MagicMock() + mock_header.get.side_effect = lambda k: { + "osmosis_replication_base_url": "https://example.com/replication", + "osmosis_replication_sequence_number": "not-a-number", + "osmosis_replication_timestamp": "2024-01-01T00:00:00Z", + }.get(k) + + mock_reader = MagicMock() + mock_reader.header.return_value = mock_header + + with patch('osmium.replication.utils.oreader', return_value=mock_reader): + with caplog.at_level(logging.WARNING, logger='pyosmium'): + val = rutil.get_replication_header('dummy.pbf') + + assert val.url == 'https://example.com/replication' + assert val.sequence is None + assert val.timestamp is not None + assert 'not-a-number' in caplog.text + + +def test_get_replication_header_negative_sequence(caplog): + from unittest.mock import MagicMock, patch + + mock_header = MagicMock() + mock_header.get.side_effect = lambda k: { + "osmosis_replication_base_url": "https://example.com/replication", + "osmosis_replication_sequence_number": "-5", + "osmosis_replication_timestamp": "2024-01-01T00:00:00Z", + }.get(k) + + mock_reader = MagicMock() + mock_reader.header.return_value = mock_header + + with patch('osmium.replication.utils.oreader', return_value=mock_reader): + with caplog.at_level(logging.WARNING, logger='pyosmium'): + val = rutil.get_replication_header('dummy.pbf') + + assert val.url == 'https://example.com/replication' + assert val.sequence is None + assert val.timestamp is not None + assert '-5' in caplog.text