Skip to content

Commit 055254c

Browse files
committed
fix off-by-one issues in pyosmium-get-changes
When a start date is given, then start at the change that contains the date, not the one after. When writing out end sequences without downloading data, use the sequence ID **before** the computed start ID, i.e. the of the previous run. Note that this might result in negative state IDs.
1 parent 2a350cf commit 055254c

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

test/test_pyosmium_get_changes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_init_id(self, capsys):
6767

6868
output = capsys.readouterr().out.strip()
6969

70-
assert output == '454'
70+
assert output == '453'
7171

7272

7373
def test_init_date(self, capsys, mock_requests):
@@ -85,22 +85,22 @@ def test_init_date(self, capsys, mock_requests):
8585

8686
output = capsys.readouterr().out.strip()
8787

88-
assert output == '1'
88+
assert output == '-1'
8989

9090

9191
def test_init_to_file(self, tmp_path):
9292
fname = tmp_path / 'db.seq'
9393

9494
assert 0 == self.main('-I', '453', '-f', str(fname))
95-
assert fname.read_text() == '454'
95+
assert fname.read_text() == '453'
9696

9797

9898
def test_init_from_seq_file(self, tmp_path):
9999
fname = tmp_path / 'db.seq'
100100
fname.write_text('453')
101101

102102
assert 0 == self.main('-f', str(fname))
103-
assert fname.read_text() == '454'
103+
assert fname.read_text() == '453'
104104

105105

106106
def test_init_date_with_cookie(self, capsys, tmp_path, mock_urllib):
@@ -123,4 +123,4 @@ def test_init_date_with_cookie(self, capsys, tmp_path, mock_urllib):
123123

124124
output = capsys.readouterr().out.strip()
125125

126-
assert output == '1'
126+
assert output == '-1'

tools/pyosmium-get-changes

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,16 @@ class ReplicationStart(object):
6262
return self.seq_id + 1
6363

6464
log.debug("Looking up sequence ID for timestamp %s" % self.date)
65-
seq = svr.timestamp_to_sequence(self.date)
66-
67-
return seq + 1 if seq is not None else None
65+
return svr.timestamp_to_sequence(self.date)
6866

6967
@staticmethod
7068
def from_id(idstr):
7169
try:
72-
seq_id=int(idstr)
70+
seq_id = int(idstr)
7371
except ValueError:
7472
raise ArgumentTypeError("Sequence id '%s' is not a number" % idstr)
7573

76-
if seq_id < 0:
74+
if seq_id < -1:
7775
raise ArgumentTypeError("Sequence id '%s' is negative" % idstr)
7876

7977
return ReplicationStart(seq_id=seq_id)
@@ -229,7 +227,7 @@ def main(args):
229227
return 1
230228

231229
if options.outfile is None:
232-
write_end_sequence(options.seq_file, startseq)
230+
write_end_sequence(options.seq_file, startseq - 1)
233231
return 0
234232

235233
log.debug("Starting download at ID %d (max %d MB)" % (startseq, options.outsize))

0 commit comments

Comments
 (0)