From 59b6b0680e110ca3bb16554bd21863230b787963 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Sun, 5 Jan 2025 14:20:49 +0200 Subject: [PATCH] Update tests, CI/CD workflow --- .flake8 | 2 -- .github/workflows/test.yaml | 22 +++++++++--- .pre-commit-config.yaml | 4 +-- pyproject.toml | 8 ++--- src/lingva/extractors/xml.py | 4 +-- tests/extractors/test_xml.py | 70 ++++++++++++++++++++---------------- 6 files changed, 64 insertions(+), 46 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index fff71c9..0000000 --- a/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -ignore = E501, E203 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index aa79135..822f475 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -5,9 +5,27 @@ on: - push jobs: + pre-commit: + name: Run pre-commit + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + check-latest: true + python-version: '3.13' + + - name: Run pre-commit + uses: pre-commit/action@v3.0.1 + test: name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} + needs: + - pre-commit strategy: matrix: os: @@ -15,7 +33,6 @@ jobs: - ubuntu-latest - windows-latest python-version: - - '3.8' - '3.9' - '3.10' - '3.11' @@ -32,9 +49,6 @@ jobs: check-latest: true python-version: ${{ matrix.python-version }} - - name: flake8 - uses: py-actions/flake8@v2 - - name: Install run: | python -m pip install .[chameleon,dev] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8945a2e..64c23c7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-ast - id: check-builtin-literals @@ -15,7 +15,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.7 + rev: v0.8.6 hooks: - id: ruff - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index 3e32afe..2a09b05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,9 +27,8 @@ dependencies = [ [project.optional-dependencies] dev = [ - "black >= 22.1.0", - "flake8 >= 4.0.1", - "pytest >=7.0.1", + "pytest >= 8.0.0", + "ruff >= 0.8.0" ] chameleon = [ "chameleon" @@ -65,10 +64,9 @@ profile = "black" [tool.ruff] line-length = 99 -target-version = "py311" [tool.ruff.lint] -select = ["E4", "E7", "E9", "F"] +select = ["E4", "E5", "E7", "E9", "F", "W"] [tool.ruff.lint.flake8-errmsg] max-string-length = 99 diff --git a/src/lingva/extractors/xml.py b/src/lingva/extractors/xml.py index 70a8b7b..8104015 100644 --- a/src/lingva/extractors/xml.py +++ b/src/lingva/extractors/xml.py @@ -157,8 +157,8 @@ def visit(self, kind, args): return visitor(*args) else: print( - "Warning: Unknown node type '%s' in %s, linenumbers might be off. Please report this warning." - % (kind, self.filename), + "Warning: Unknown node type '%s' in %s, linenumbers might be off. " + "Please report this warning." % (kind, self.filename), file=sys.stderr, ) diff --git a/tests/extractors/test_xml.py b/tests/extractors/test_xml.py index 242327c..32f96ed 100644 --- a/tests/extractors/test_xml.py +++ b/tests/extractors/test_xml.py @@ -539,12 +539,14 @@ def test_nested_braces(self): @pytest.mark.usefixtures("fake_source") def test_python_expression_in_tales_expressions(): global source - source = """ + source = b"""\ - Dummy + + Dummy + - """.encode("utf-8") + """ assert list(xml_extractor("filename", _options())) == [] @@ -619,25 +621,25 @@ def test_multiline_replace_with_structure(): @pytest.mark.usefixtures("fake_source") def test_spaces_around_tal_pipe_symbol(): global source - source = """\ + source = b"""\
- """.encode("utf-8") + """ list(xml_extractor("filename", _options())) @pytest.mark.usefixtures("fake_source") def test_empty_element(): global source - source = """\ + source = b"""\

- """.encode("utf-8") + """ messages = list(xml_extractor("filename", _options())) assert len(messages) == 1 @@ -645,12 +647,12 @@ def test_empty_element(): @pytest.mark.usefixtures("fake_source") def test_brace_in_python_expression(): global source - source = """\ + source = b"""\

${some_method(_('abc'), {'a':'b'})}

- """.encode("utf-8") + """ messages = list(xml_extractor("filename", _options())) assert len(messages) == 1 assert messages[0].msgid == "abc" @@ -659,11 +661,11 @@ def test_brace_in_python_expression(): @pytest.mark.usefixtures("fake_source") def test_translation_context(): global source - source = """ - """.encode("utf-8") + """ messages = list(xml_extractor("filename", _options())) assert messages[0].msgid == "Save" assert messages[0].msgctxt == "form" @@ -672,11 +674,11 @@ def test_translation_context(): @pytest.mark.usefixtures("fake_source") def test_translation_comment(): global source - source = """ - """.encode("utf-8") + """ messages = list(xml_extractor("filename", _options())) assert messages[0].msgid == "Save" assert messages[0].comment == "Generic save button" @@ -685,11 +687,13 @@ def test_translation_comment(): @pytest.mark.usefixtures("fake_source") def test_translation_comment_for_attribute(): global source - source = """ - + - """.encode("utf-8") + """ messages = list(xml_extractor("filename", _options())) assert messages[0].msgid == "Email address" assert messages[0].comment == "Placeholder text" @@ -698,11 +702,14 @@ def test_translation_comment_for_attribute(): @pytest.mark.usefixtures("fake_source") def test_translation_comment_and_msgid(): global source - source = """ - + - """.encode("utf-8") + """ messages = list(xml_extractor("filename", _options())) assert messages[0].msgid == "btn_save" assert messages[0].comment == "Generic save button\nDefault: Save" @@ -711,13 +718,13 @@ def test_translation_comment_and_msgid(): @pytest.mark.usefixtures("fake_source") def test_inherit_translation_comment(): global source - source = """
- """.encode("utf-8") + """ messages = list(xml_extractor("filename", _options())) assert messages[0].msgid == "Save" assert messages[0].comment == "Form buttons" @@ -726,7 +733,7 @@ def test_inherit_translation_comment(): @pytest.mark.usefixtures("fake_source") def test_linenumbers(): global source - source = """ + source = b""" @@ -748,7 +755,8 @@ def test_linenumbers():
Foo + save button"> + Foo