Fix patterns parsing #976
Reference in New Issue
Block a user
Delete Branch "pasha132/borgmatic:fix-exclude-parser"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hello!
It seems that after patterns refactoring original borg patterns stopped to work: they always passed with "fn:" style prefix.
My variant of fix is in this PR.
@@ -88,11 +89,6 @@ def test_collect_patterns_reads_config_exclude_from_file():builtins.should_receive('open').with_args('file2.txt').and_return(io.StringIO('/bar\n# comment\n\n \n/baz'))flexmock(module).should_receive('parse_pattern').with_args('/bar').and_return(Pattern('/bar'))It seems that this is dead code. Anyway it's nice to have real
parse_patternfunction tested here to.I don't think it's dead...? Although maybe I'm missing something.
In any case, unit tests in this codebase generally only test a single unit (function) at a time and don't integrate multiple units under test. So
parse_pattern()is intended to be mocked out here. Any tests integrating multiple units can generally be found undertests/integrationortests/end-to-end.Sorry, my mistake: never used flexmock before. Just saw that without this code test didn't fail.
That's understandable!
The solution here looks good to me! I just left a few comments about expanding scope a bit and also one of the tests. Thank you!
@@ -75,11 +73,8 @@ def collect_patterns(config):if pattern_line.strip()Since you now have the handy
default_styleparameter, what do you think of addingdefault_sytle=borgmatic.borg.pattern.Pattern_style.SHELLfor thepatternsandpatterns_fromoptions here? Based on these docs, that'd be more correct than the existing behavior prior to your changes.Turns out this was a terrible idea.. My bad for suggesting it. The problem was that tacking on "sh:" unconditionally breaks root patterns in particular (e.g.
R /foo/bar), because they don't have pattern style prefixes.borgmatic 1.9.8 fixes that.
@@ -88,11 +89,6 @@ def test_collect_patterns_reads_config_exclude_from_file():builtins.should_receive('open').with_args('file2.txt').and_return(io.StringIO('/bar\n# comment\n\n \n/baz')Also: Do you think this test could benefit from a
sh:pattern added here like you did for the test above?Looks great! Thank you.