Code formatting.
All checks were successful
build / test (push) Successful in 4m23s
build / docs (push) Successful in 1m36s

This commit is contained in:
Dan Helfman 2025-01-23 12:11:27 -08:00
parent 86ad93676d
commit f08014e3be
2 changed files with 24 additions and 12 deletions

View File

@ -61,8 +61,10 @@ def collect_patterns(config):
if pattern_line.strip()
)
+ tuple(
parse_pattern(f'{borgmatic.borg.pattern.Pattern_type.EXCLUDE.value} {
exclude_line.strip()}', borgmatic.borg.pattern.Pattern_style.FNMATCH)
parse_pattern(
f'{borgmatic.borg.pattern.Pattern_type.EXCLUDE.value} {exclude_line.strip()}',
borgmatic.borg.pattern.Pattern_style.FNMATCH,
)
for exclude_line in config.get('exclude_patterns', ())
)
+ tuple(
@ -73,8 +75,10 @@ def collect_patterns(config):
if pattern_line.strip()
)
+ tuple(
parse_pattern(f'{borgmatic.borg.pattern.Pattern_type.EXCLUDE.value} {
exclude_line.strip()}', borgmatic.borg.pattern.Pattern_style.FNMATCH)
parse_pattern(
f'{borgmatic.borg.pattern.Pattern_type.EXCLUDE.value} {exclude_line.strip()}',
borgmatic.borg.pattern.Pattern_style.FNMATCH,
)
for filename in config.get('exclude_from', ())
for exclude_line in open(filename).readlines()
if not exclude_line.lstrip().startswith('#')

View File

@ -35,12 +35,14 @@ def test_collect_patterns_converts_source_directories():
def test_collect_patterns_parses_config_patterns():
flexmock(module).should_receive('parse_pattern').with_args(
'R /foo', Pattern_style.SHELL).and_return(Pattern('/foo'))
'R /foo', Pattern_style.SHELL
).and_return(Pattern('/foo'))
flexmock(module).should_receive('parse_pattern').with_args('# comment').never()
flexmock(module).should_receive('parse_pattern').with_args('').never()
flexmock(module).should_receive('parse_pattern').with_args(' ').never()
flexmock(module).should_receive('parse_pattern').with_args(
'R /bar', Pattern_style.SHELL).and_return(Pattern('/bar'))
'R /bar', Pattern_style.SHELL
).and_return(Pattern('/bar'))
assert module.collect_patterns({'patterns': ['R /foo', '# comment', '', ' ', 'R /bar']}) == (
Pattern('/foo'),
@ -63,14 +65,17 @@ def test_collect_patterns_reads_config_patterns_from_file():
io.StringIO('R /bar\n# comment\n\n \nR /baz')
)
flexmock(module).should_receive('parse_pattern').with_args(
'R /foo', Pattern_style.SHELL).and_return(Pattern('/foo'))
'R /foo', Pattern_style.SHELL
).and_return(Pattern('/foo'))
flexmock(module).should_receive('parse_pattern').with_args('# comment').never()
flexmock(module).should_receive('parse_pattern').with_args('').never()
flexmock(module).should_receive('parse_pattern').with_args(' ').never()
flexmock(module).should_receive('parse_pattern').with_args(
'R /bar', Pattern_style.SHELL).and_return(Pattern('/bar'))
'R /bar', Pattern_style.SHELL
).and_return(Pattern('/bar'))
flexmock(module).should_receive('parse_pattern').with_args(
'R /baz', Pattern_style.SHELL).and_return(Pattern('/baz'))
'R /baz', Pattern_style.SHELL
).and_return(Pattern('/baz'))
assert module.collect_patterns({'patterns_from': ['file1.txt', 'file2.txt']}) == (
Pattern('/foo'),
@ -95,14 +100,17 @@ def test_collect_patterns_reads_config_exclude_from_file():
io.StringIO('/bar\n# comment\n\n \n/baz')
)
flexmock(module).should_receive('parse_pattern').with_args(
'- /foo', default_style=Pattern_style.FNMATCH).and_return(Pattern('/foo', Pattern_type.EXCLUDE, Pattern_style.FNMATCH))
'- /foo', default_style=Pattern_style.FNMATCH
).and_return(Pattern('/foo', Pattern_type.EXCLUDE, Pattern_style.FNMATCH))
flexmock(module).should_receive('parse_pattern').with_args(
'- /bar', default_style=Pattern_style.FNMATCH).and_return(Pattern('/bar', Pattern_type.EXCLUDE, Pattern_style.FNMATCH))
'- /bar', default_style=Pattern_style.FNMATCH
).and_return(Pattern('/bar', Pattern_type.EXCLUDE, Pattern_style.FNMATCH))
flexmock(module).should_receive('parse_pattern').with_args('# comment').never()
flexmock(module).should_receive('parse_pattern').with_args('').never()
flexmock(module).should_receive('parse_pattern').with_args(' ').never()
flexmock(module).should_receive('parse_pattern').with_args(
'- /baz', default_style=Pattern_style.FNMATCH).and_return(Pattern('/baz', Pattern_type.EXCLUDE, Pattern_style.FNMATCH))
'- /baz', default_style=Pattern_style.FNMATCH
).and_return(Pattern('/baz', Pattern_type.EXCLUDE, Pattern_style.FNMATCH))
assert module.collect_patterns({'exclude_from': ['file1.txt', 'file2.txt']}) == (
Pattern('/foo', Pattern_type.EXCLUDE, Pattern_style.FNMATCH),