Skip to content

Commit

Permalink
remove debugging code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Jan 7, 2025
1 parent 9a00d53 commit c7d8670
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
23 changes: 9 additions & 14 deletions src/borg/helpers/parseformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,20 @@ def interval(s):
seconds_in_a_month = 31 * seconds_in_a_day
seconds_in_a_year = 365 * seconds_in_a_day
multiplier = dict(
S = 1,
M = seconds_in_a_minute,
H = seconds_in_an_hour,
d = seconds_in_a_day,
w = seconds_in_a_week,
m = seconds_in_a_month,
y = seconds_in_a_year,
y=seconds_in_a_year,
m=seconds_in_a_month,
w=seconds_in_a_week,
d=seconds_in_a_day,
H=seconds_in_an_hour,
M=seconds_in_a_minute,
S=1,
)

if s.endswith(tuple(multiplier.keys())):
number = s[:-1]
suffix = s[-1]
else:
raise argparse.ArgumentTypeError(
f'Unexpected time unit "{s[-1]}": choose from {", ".join(multiplier)}'
)
raise argparse.ArgumentTypeError(f'Unexpected time unit "{s[-1]}": choose from {", ".join(multiplier)}')

try:
seconds = int(number) * multiplier[suffix]
Expand Down Expand Up @@ -579,10 +577,7 @@ def with_timestamp(self, timestamp):
def location_validator(proto=None, other=False):
def validator(text):
try:
try:
loc = Location(text, other=other)
except Exception as e:
assert False
loc = Location(text, other=other)
except ValueError as err:
raise argparse.ArgumentTypeError(str(err)) from None
if proto is not None and loc.proto != proto:
Expand Down
23 changes: 13 additions & 10 deletions src/borg/testsuite/helpers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,15 +553,18 @@ def test_prune_split_no_archives():
assert kept_because == {}


@pytest.mark.parametrize("timeframe, num_hours", [
("5S", 5),
("2M", 120),
("1H", 3600),
("1d", 86_400),
("1w", 604_800),
("1m", 2_678_400),
("1y", 31_536_000)
])
@pytest.mark.parametrize(
"timeframe, num_hours",
[
("5S", 5),
("2M", 2 * 60),
("1H", 60 * 60),
("1d", 24 * 60 * 60),
("1w", 7 * 24 * 68 * 60),
("1m", 31 * 24 * 68 * 60),
("1y", 365 * 24 * 68 * 60),
],
)
def test_interval(timeframe, num_secs):
assert interval(timeframe) == num_secs

Expand All @@ -571,7 +574,7 @@ def test_interval(timeframe, num_secs):
[
("H", ('Unexpected number "": expected positive integer',)),
("-1d", ('Unexpected number "-1": expected positive integer',)),
("food", ('Unexpectedinterval number "foo": expected positive integer',)),
("food", ('Unexpected number "foo": expected positive integer',)),
],
)
def test_interval_time_unit(invalid_interval, error_tuple):
Expand Down

0 comments on commit c7d8670

Please sign in to comment.