Skip to content

Commit 881eaca

Browse files
fix tests so that they are as before the splitup
1 parent 5545af1 commit 881eaca

File tree

3 files changed

+74
-57
lines changed

3 files changed

+74
-57
lines changed

src/borg/testsuite/archiver/prune_cmd_test.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import re
2-
from datetime import datetime, timezone
2+
from datetime import datetime, timezone, timedelta
33

44
import pytest
55

66
from ...constants import * # NOQA
7-
from ...archiver.prune_cmd import prune_split
7+
from ...archiver.prune_cmd import prune_split, prune_within
88
from . import cmd, RK_ENCRYPTION, src_dir, generate_archiver_tests
9+
from ...helpers import interval
910

1011
pytest_generate_tests = lambda metafunc: generate_archiver_tests(metafunc, kinds="local,remote,binary") # NOQA
1112

@@ -282,6 +283,38 @@ def __repr__(self):
282283
local_tz = datetime.now(tz=timezone.utc).astimezone(tz=None).tzinfo
283284

284285

286+
def test_prune_within():
287+
def subset(lst, indices):
288+
return {lst[i] for i in indices}
289+
290+
def dotest(test_archives, within, indices):
291+
for ta in test_archives, reversed(test_archives):
292+
kept_because = {}
293+
keep = prune_within(ta, interval(within), kept_because)
294+
assert set(keep) == subset(test_archives, indices)
295+
assert all("within" == kept_because[a.id][0] for a in keep)
296+
297+
# 1 minute, 1.5 hours, 2.5 hours, 3.5 hours, 25 hours, 49 hours
298+
test_offsets = [60, 90 * 60, 150 * 60, 210 * 60, 25 * 60 * 60, 49 * 60 * 60]
299+
now = datetime.now(timezone.utc)
300+
test_dates = [now - timedelta(seconds=s) for s in test_offsets]
301+
test_archives = [MockArchive(date, i) for i, date in enumerate(test_dates)]
302+
303+
dotest(test_archives, "15S", [])
304+
dotest(test_archives, "2M", [0])
305+
dotest(test_archives, "1H", [0])
306+
dotest(test_archives, "2H", [0, 1])
307+
dotest(test_archives, "3H", [0, 1, 2])
308+
dotest(test_archives, "24H", [0, 1, 2, 3])
309+
dotest(test_archives, "26H", [0, 1, 2, 3, 4])
310+
dotest(test_archives, "2d", [0, 1, 2, 3, 4])
311+
dotest(test_archives, "50H", [0, 1, 2, 3, 4, 5])
312+
dotest(test_archives, "3d", [0, 1, 2, 3, 4, 5])
313+
dotest(test_archives, "1w", [0, 1, 2, 3, 4, 5])
314+
dotest(test_archives, "1m", [0, 1, 2, 3, 4, 5])
315+
dotest(test_archives, "1y", [0, 1, 2, 3, 4, 5])
316+
317+
285318
@pytest.mark.parametrize(
286319
"rule,num_to_keep,expected_ids",
287320
[

src/borg/testsuite/helpers/fs_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,16 @@ def os_unlink(_):
270270

271271
@pytest.mark.parametrize(
272272
"original_path, expected_path",
273-
[("foo", "foo"), ("foo/bar", "foo/bar"), ("/foo/bar", "foo/bar"), ("../foo/bar", "foo/bar")],
273+
[
274+
(".", "."),
275+
("..", "."),
276+
("/", "."),
277+
("//", "."),
278+
("foo", "foo"),
279+
("foo/bar", "foo/bar"),
280+
("/foo/bar", "foo/bar"),
281+
("../foo/bar", "foo/bar"),
282+
],
274283
)
275284
def test_remove_dotdot_prefixes(original_path, expected_path):
276285
assert remove_dotdot_prefixes(original_path) == expected_path

src/borg/testsuite/helpers/parseformat_test.py

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -281,21 +281,9 @@ def test_bad_syntax(self):
281281
@pytest.mark.parametrize(
282282
"name",
283283
[
284-
"foo",
285-
"foo bar",
286-
"foo_bar",
287-
"foo-bar",
288-
"foo.bar",
289-
"foo[bar]",
290-
"foo@2020-01-01T12:34:56",
291-
"foo{now}",
292-
"foo{now:%Y-%m-%d}",
293-
"foo{hostname}",
294-
"foo{hostname}-{now}",
295-
"foo{hostname}-{now:%Y-%m-%d}",
296-
"foo{hostname}-{now:%Y-%m-%d}@{now:%H:%M:%S}",
297-
"foo{hostname}-{now:%Y-%m-%d}@{now:%H:%M:%S}",
298-
"foo{hostname}-{now:%Y-%m-%d}@{now:%H:%M:%S}",
284+
"foobar",
285+
# placeholders
286+
"foobar-{now}",
299287
],
300288
)
301289
def test_archivename_ok(name):
@@ -305,59 +293,46 @@ def test_archivename_ok(name):
305293
@pytest.mark.parametrize(
306294
"name",
307295
[
308-
"", # empty name
309-
" ", # just a space
310-
" foo", # leading space
311-
"foo ", # trailing space
312-
"foo/bar", # / not allowed
313-
"foo\\bar", # \ not allowed
314-
"foo\nbar", # \n not allowed
315-
"foo\rbar", # \r not allowed
316-
"foo\tbar", # \t not allowed
317-
"foo\0bar", # \0 not allowed
318-
"foo\x01bar", # \x01 not allowed
319-
"foo\x02bar", # \x02 not allowed
320-
"foo\x03bar", # \x03 not allowed
321-
"foo\x04bar", # \x04 not allowed
322-
"foo\x05bar", # \x05 not allowed
323-
"foo\x06bar", # \x06 not allowed
324-
"foo\x07bar", # \x07 not allowed
325-
"foo\x08bar", # \x08 not allowed
326-
"foo\x09bar", # \x09 not allowed
327-
"foo\x0abar", # \x0a not allowed
328-
"foo\x0bbar", # \x0b not allowed
329-
"foo\x0cbar", # \x0c not allowed
330-
"foo\x0dbar", # \x0d not allowed
331-
"foo\x0ebar", # \x0e not allowed
332-
"foo\x0fbar", # \x0f not allowed
296+
"", # too short
297+
"x" * 201, # too long
298+
# invalid chars:
299+
"foo/bar",
300+
"foo\\bar",
301+
">foo",
302+
"<foo",
303+
"|foo",
304+
'foo"bar',
305+
"foo?",
306+
"*bar",
307+
"foo\nbar",
308+
"foo\0bar",
309+
# leading/trailing blanks
310+
" foo",
311+
"bar ",
312+
# contains surrogate-escapes
313+
"foo\udc80bar",
314+
"foo\udcffbar",
333315
],
334316
)
335317
def test_archivename_invalid(name):
336318
with pytest.raises(ArgumentTypeError):
337319
archivename_validator(name)
338320

339321

340-
@pytest.mark.parametrize("text", ["foo", "bar", "baz"])
322+
@pytest.mark.parametrize("text", ["", "single line", "multi\nline\ncomment"])
341323
def test_text_ok(text):
342324
assert text_validator(name="text", max_length=100)(text) == text
343325

344326

345327
@pytest.mark.parametrize(
346328
"text",
347329
[
348-
"", # empty
349-
"foo\0bar", # contains null byte
350-
"foo\nbar", # contains newline
351-
"foo\rbar", # contains carriage return
352-
"foo\tbar", # contains tab
353-
"foo\x01bar", # contains control character
354-
"foo\x02bar", # contains control character
355-
"foo\x03bar", # contains control character
356-
"foo\x04bar", # contains control character
357-
"foo\x05bar", # contains control character
358-
"foo\x06bar", # contains control character
359-
"foo\x07bar", # contains control character
360-
"foo\x08bar", # contains control character
330+
"x" * 101, # too long
331+
# invalid chars:
332+
"foo\0bar",
333+
# contains surrogate-escapes
334+
"foo\udc80bar",
335+
"foo\udcffbar",
361336
],
362337
)
363338
def test_text_invalid(text):

0 commit comments

Comments
 (0)