Skip to content

Commit

Permalink
Add test for stub_ignore function
Browse files Browse the repository at this point in the history
Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
  • Loading branch information
Josverl committed Nov 5, 2023
1 parent 322f96c commit 5710d6c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions snippets/test_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
49 changes: 49 additions & 0 deletions tests/snippets/test_snippet_filter.py
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 5710d6c

Please sign in to comment.