summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2022-01-27 16:20:34 +0200
committerAarni Koskela <akx@iki.fi>2022-01-27 18:58:32 +0200
commit1984ec7c4c6be474c25318c8d201dac696186e00 (patch)
treefb99162c02fb402914a65204bf2c58cc2774b29b /tests
parent6d4ab52b5b14f71717fb645f1f8f34f75bbae392 (diff)
downloadbabel-1984ec7c4c6be474c25318c8d201dac696186e00.tar.gz
Add frontend for extract directory filter
Co-authored-by: Kinshuk Dua <kinshukduaexam@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/messages/data/project/_hidden_by_default/hidden_file.py5
-rw-r--r--tests/messages/test_frontend.py23
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/messages/data/project/_hidden_by_default/hidden_file.py b/tests/messages/data/project/_hidden_by_default/hidden_file.py
new file mode 100644
index 0000000..325afc9
--- /dev/null
+++ b/tests/messages/data/project/_hidden_by_default/hidden_file.py
@@ -0,0 +1,5 @@
+from gettext import gettext
+
+
+def foo():
+ print(gettext('ssshhh....'))
diff --git a/tests/messages/test_frontend.py b/tests/messages/test_frontend.py
index 50471e7..2dc5330 100644
--- a/tests/messages/test_frontend.py
+++ b/tests/messages/test_frontend.py
@@ -1431,3 +1431,26 @@ def test_extract_error_code(monkeypatch, capsys):
if err:
# replace hack below for py2/py3 compatibility
assert "unknown named placeholder 'merkki'" in err.replace("u'", "'")
+
+
+@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 = "extract . -o '{}' --ignore-dirs '*ignored*' ".format(pot_file)
+ if with_underscore_ignore:
+ # This also tests that multiple arguments are supported.
+ cmd += "--ignore-dirs '_*'"
+ cmdinst = configure_cli_command(cmd)
+ assert isinstance(cmdinst, extract_messages)
+ 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
+
+ # Since we manually set a filter, the otherwise `_hidden` directory is walked into,
+ # unless we opt in to ignore it again
+ assert ('ssshhh....' in pot_content) != with_underscore_ignore
+ assert ('_hidden_by_default' in pot_content) != with_underscore_ignore