-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for #832 #1052
Fix for #832 #1052
Conversation
Thanks! It would be nice to see a test for this, since the tests I wrote for #832 clearly didn't catch this typo 😅 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1052 +/- ##
==========================================
+ Coverage 90.99% 91.03% +0.03%
==========================================
Files 26 26
Lines 4444 4451 +7
==========================================
+ Hits 4044 4052 +8
+ Misses 400 399 -1 ☔ View full report in Codecov by Sentry. |
Okay i will check what i can do 😉 |
Very simple minor fix 711676b To make test work properly just add another value to our ignore list and it imidiately fails. Before, function argument fix:=============test session starts=============
platform linux -- Python 3.10.11, pytest-7.4.3, pluggy-1.3.0 -- /home/mrgreen/code/babel/venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/mrgreen/code/babel
configfile: setup.cfg
plugins: cov-4.1.0
collected 60 items / 58 deselected / 2 selected
tests/messages/test_frontend.py::test_extract_ignore_dirs[False]
ignore_dirs = ['*ignored*', '.*']
FAILED
tests/messages/test_frontend.py::test_extract_ignore_dirs[True]
ignore_dirs = ['*ignored*', '.*', '_*']
FAILED
=============FAILURES =============
______________________ test_extract_ignore_dirs[False] ______________________
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7febbf363280>, capsys = <_pytest.capture.CaptureFixture object at 0x7febbf363520>, tmp_path = PosixPath('/tmp/pytest-of-mrgreen/pytest-33/test_extract_ignore_dirs_False0'), with_underscore_ignore = False
@pytest.mark.parametrize("with_underscore_ignore", (False, True))
def test_extract_ignore_dirs(monkeypatch, capsys, tmp_path, with_underscore_ignore):
pot_file = tmp_path / 'temp.pot'
monkeypatch.chdir(project_dir)
cmd = f"extract . -o '{pot_file}' --ignore-dirs '*ignored* .*' "
if with_underscore_ignore:
# This also tests that multiple arguments are supported.
cmd += "--ignore-dirs '_*'"
cmdinst = configure_cli_command(cmd)
assert isinstance(cmdinst, ExtractMessages)
assert cmdinst.directory_filter
cmdinst.run()
pot_content = pot_file.read_text()
# The `ignored` directory is now actually ignored:
> assert 'this_wont_normally_be_here' not in pot_content
E assert 'this_wont_normally_be_here' not in '# Translati...tr[1] ""\n\n'
E 'this_wont_normally_be_here' is contained here:
E # Translations template for PROJECT.
E # Copyright (C) 2023 ORGANIZATION
E # This file is distributed under the same license as the PROJECT project.
E # FIRST AUTHOR <EMAIL@ADDRESS>, 2023.
E #
E #, fuzzy...
E
E ...Full output truncated (33 lines hidden), use '-vv' to show
/home/mrgreen/code/babel/tests/messages/test_frontend.py:1588: AssertionError
______________________ test_extract_ignore_dirs[True] ______________________
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7febbeebbcd0>, capsys = <_pytest.capture.CaptureFixture object at 0x7febbeebb550>, tmp_path = PosixPath('/tmp/pytest-of-mrgreen/pytest-33/test_extract_ignore_dirs_True_0'), with_underscore_ignore = True
@pytest.mark.parametrize("with_underscore_ignore", (False, True))
def test_extract_ignore_dirs(monkeypatch, capsys, tmp_path, with_underscore_ignore):
pot_file = tmp_path / 'temp.pot'
monkeypatch.chdir(project_dir)
cmd = f"extract . -o '{pot_file}' --ignore-dirs '*ignored* .*' "
if with_underscore_ignore:
# This also tests that multiple arguments are supported.
cmd += "--ignore-dirs '_*'"
cmdinst = configure_cli_command(cmd)
assert isinstance(cmdinst, ExtractMessages)
assert cmdinst.directory_filter
cmdinst.run()
pot_content = pot_file.read_text()
# The `ignored` directory is now actually ignored:
> assert 'this_wont_normally_be_here' not in pot_content
E assert 'this_wont_normally_be_here' not in '# Translati...tr[1] ""\n\n'
E 'this_wont_normally_be_here' is contained here:
E # Translations template for PROJECT.
E # Copyright (C) 2023 ORGANIZATION
E # This file is distributed under the same license as the PROJECT project.
E # FIRST AUTHOR <EMAIL@ADDRESS>, 2023.
E #
E #, fuzzy...
E
E ...Full output truncated (29 lines hidden), use '-vv' to show
/home/mrgreen/code/babel/tests/messages/test_frontend.py:1588: AssertionError After, function argument fix:============= test session starts =============
platform linux -- Python 3.10.11, pytest-7.4.3, pluggy-1.3.0 -- /home/mrgreen/code/babel/venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/mrgreen/code/babel
configfile: setup.cfg
plugins: cov-4.1.0
collected 60 items / 58 deselected / 2 selected
tests/messages/test_frontend.py::test_extract_ignore_dirs[False]
ignore_dirs = ['*ignored*', '.*']
PASSED
tests/messages/test_frontend.py::test_extract_ignore_dirs[True]
ignore_dirs = ['*ignored*', '.*', '_*']
PASSED |
And i have a question/suggestion about this one. babel/babel/messages/extract.py Lines 112 to 115 in 2a1709a
babel/babel/messages/extract.py Lines 201 to 202 in 2a1709a
So in current realization we can have or default or user ignore list, maybe we should extend default one with user if it provided? def _make_directory_filter(ignore_patterns):
"""
Build a directory_filter function based on a list of ignore patterns.
"""
if not ignore_patterns:
ignore_patterns = []
def cli_directory_filter(dirname):
basename = os.path.basename(dirname)
return not any(
fnmatch.fnmatch(basename, ignore_pattern)
for ignore_pattern
in [*ignore_patterns, '.*', '_*']
)
return cli_directory_filter |
Adds multiple value for proper test. Fixes for python-babel#832
frontend.py: Fix function argument
Previosly in function was passed raw value
self.ignore_dirs
, not a list as expectedignore_dirs
.