From 5710d6cce5966f008024cbbd9488aaee5fc0b2f9 Mon Sep 17 00:00:00 2001 From: Jos Verlinde Date: Sun, 5 Nov 2023 22:18:37 +0100 Subject: [PATCH] Add test for stub_ignore function Signed-off-by: Jos Verlinde --- .vscode/settings.json | 2 +- snippets/test_snippets.py | 1 + tests/snippets/test_snippet_filter.py | 49 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/snippets/test_snippet_filter.py diff --git a/.vscode/settings.json b/.vscode/settings.json index cc78e038..7e47fc1a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -97,7 +97,7 @@ "markiscodecoverage.searchCriteria": "results/coverage*.lcov", "debug.allowBreakpointsEverywhere": true, "debug.terminal.clearBeforeReusing": true, - "python.analysis.typeCheckingMode": "strict", + "python.analysis.typeCheckingMode": "basic", "python.analysis.diagnosticSeverityOverrides": { "reportUnusedVariable": "warning", "reportUnusedImport": "warning", diff --git a/snippets/test_snippets.py b/snippets/test_snippets.py index 29402cc4..24a2848d 100644 --- a/snippets/test_snippets.py +++ b/snippets/test_snippets.py @@ -140,6 +140,7 @@ def stub_ignore(line, version, port, board, linter="pyright", is_source=True) -> id, condition = comment.split(":") if id.strip() != "stubs-ignore": return False + condition = condition.strip() else: condition = line.strip() if condition.lower().startswith("skip"): diff --git a/tests/snippets/test_snippet_filter.py b/tests/snippets/test_snippet_filter.py new file mode 100644 index 00000000..14e73f00 --- /dev/null +++ b/tests/snippets/test_snippet_filter.py @@ -0,0 +1,49 @@ +from pathlib import Path +from typing import Dict, List + +import pytest + +# Assuming the functions filter_issues and stub_ignore are in a module named 'mymodule' +from snippets.test_snippets import stub_ignore + + +@pytest.mark.parametrize( + "line, version, port, board, ignore", + [ + ( + "import espnow # stubs-ignore: version<1.21.0 or port.startswith('esp')", + "1.21.0", + "esp32", + "", + True, + ), + ( + "import espnow # stubs-ignore: skip port.lower().startswith('pybd')", + "1.21.0", + "PYBD_SF6", + "", + True, + ), + ("import espnow # stubs-ignore: version < 1.21.0", "1.20.0", "esp32", "", True), + ("import espnow # stubs-ignore : version < 1.21.0", "1.20.0", "esp32", "", True), + ("import espnow # stubs-ignore :version<1.21.0", "1.20.0", "esp32", "", True), + ("import espnow # stubs-ignore:skip version < 1.21.0", "1.20.0", "esp32", "", True), + ("import espnow # stubs-ignore : skip version < 1.21.0", "1.20.0", "esp32", "", True), + ("import espnow # stubs-ignore :skip version<1.21.0", "1.20.0", "esp32", "", True), + ("version<1.21.0", "1.21.0", "esp32", "", False), + ("invalid condition", "1.21.0", "esp32", "", False), + ], +) +def test_stub_ignore(line, version, port, board, ignore): + is_source = "#" in line + assert ( + stub_ignore( + line, + version, + port, + board, + linter="pytest", + is_source=is_source, + ) + == ignore + )