Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import ast
import importlib.util
import pathlib
import tempfile
Expand Down Expand Up @@ -81,6 +82,30 @@ def pytest_sessionstart(session: pytest.Session) -> None:
break


_function_names = {}


@pytest.hookimpl(tryfirst=True)
def pytest_pycollect_makemodule(module_path: str, parent: str) -> None:
if duplicates := find_duplicate_functions(module_path):
pytest.exit(f"duplicate test function names found in module: {module_path}: {duplicates}")


def find_duplicate_functions(source_path: str) -> set[str]:
source_code = pathlib.Path(source_path).read_text()
tree = ast.parse(source_code, source_path)
duplicates = set()
allowlist = ("test_other", "test_all",) # ast will find some example Plugin functions from test_plugin.py

for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef) and node.name.startswith("test_") and node.name not in allowlist:
if node.name in _function_names:
duplicates.add(node.name)
else:
_function_names[node.name] = node
return duplicates


def pytest_runtest_setup(item: pytest.Item) -> None:
if not HAS_BENCHMARK and item.get_closest_marker("benchmark") is not None:
pytest.skip("pytest-benchmark is not installed")
Expand Down
2 changes: 1 addition & 1 deletion tests/filesystems/test_extfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tests._utils import absolute_path


def test_stat_information() -> None:
def test_extfs_stat_information() -> None:
extfs = Mock(block_size=0x1000)
extfs.sb.s_inode_size = 129

Expand Down
2 changes: 1 addition & 1 deletion tests/filesystems/test_ffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def ffs_fs_entry(ffs_fs: FfsFilesystem) -> FfsFilesystemEntry:
return FfsFilesystemEntry(ffs_fs, "/some_file", inode)


def test_jffs2_stat(ffs_fs_entry: FfsFilesystemEntry) -> None:
def test_ffs_stat(ffs_fs_entry: FfsFilesystemEntry) -> None:
stat = ffs_fs_entry.stat()

entry = ffs_fs_entry.entry
Expand Down
2 changes: 1 addition & 1 deletion tests/filesystems/test_nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_is_symlink(nfs_filesystem_entry: NfsFilesystemEntry) -> None:
assert nfs_filesystem_entry.is_symlink()


def test_readlink(nfs_filesystem_entry: NfsFilesystemEntry, mock_nfs_client: MagicMock) -> None:
def test_nfs_readlink(nfs_filesystem_entry: NfsFilesystemEntry, mock_nfs_client: MagicMock) -> None:
mock_nfs_client.readlink.return_value = "/target"
target = nfs_filesystem_entry.readlink()
mock_nfs_client.readlink.assert_called_with(FileHandle(opaque=b"file_handle"))
Expand Down
2 changes: 1 addition & 1 deletion tests/filesystems/test_ntfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_ntfs_unknown_file() -> None:
(0x1000, 0x2000, True, 0),
],
)
def test_stat_information(cluster_size: int, size: int, resident: bool, expected_blks: int) -> None:
def test_ntfs_stat_information(cluster_size: int, size: int, resident: bool, expected_blks: int) -> None:
ntfs = Mock(cluster_size=cluster_size)

entry = MftRecord()
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/sunrpc/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def test_getattr(mock_socket: MagicMock) -> None:
)


def test_readlink(mock_socket: MagicMock) -> None:
def test_sunrpc_readlink(mock_socket: MagicMock) -> None:
readlink_request = b"\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x01\x86\xa3\x00\x00\x00\x03\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x1ccy7\xba\x00\x00\x00\x07machine\x00\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00,\x01\x00\x07\x02\xda&\xee\x02\x00\x00\x00\x00\xb5g\x131&\xf1I\xed\xb8R\rx\\h8\xb4\x0f{\xee\x02\xefoz\xef\xda&\xee\x02'/\x00\x91" # noqa: E501
readlink_response = b"\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x01\xff\x00\x00\x00\x01\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Yq\x99zI\x1e5\r\x00\x00\x00\x00\x02\xee{\x0fg\xac\xba\xc3\r5\xab\xa0g\xa9\xbe\x0c:H\x15\xc0g\xa9\xbe\x0c:H\x15\xc0\x00\x00\x00\x0edir1/dir2/dir3\x00\x00" # noqa: E501

Expand Down
24 changes: 16 additions & 8 deletions tests/helpers/test_configutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,33 @@ def test_custom_comments(comment_string: str, comment_prefixes: tuple[str, ...])
@pytest.mark.parametrize(
("indented_string", "expected_output"),
[
(
pytest.param(
"""
key value1
value2
""",
{"key value1": "value2"},
id="variant-1",
),
(
pytest.param(
"""
key1 value1
key2 value2
""",
{"key1 value1": {"key2": "value2"}},
id="variant-2",
),
(
pytest.param(
"""
key value1
value2
key value1
value3
""",
{"key value1": ["value2", "value3"]},
id="variant-3",
),
(
pytest.param(
"""
key value1
key2 value2a
Expand All @@ -117,8 +120,9 @@ def test_custom_comments(comment_string: str, comment_prefixes: tuple[str, ...])
key3 value3b
""",
{"key value1": [{"key2": "value2a", "key3": "value3a"}, {"key2": "value2b", "key3": "value3b"}]},
id="variant-4",
),
(
pytest.param(
"""
key value
key2 value2
Expand All @@ -128,8 +132,9 @@ def test_custom_comments(comment_string: str, comment_prefixes: tuple[str, ...])
key2 value2
""",
{"key value": {"key2": "value2", "key3": "value3"}, "key value4": {"key2": "value2"}},
id="variant-5",
),
(
pytest.param(
"""
key value
key2 value2
Expand All @@ -139,15 +144,17 @@ def test_custom_comments(comment_string: str, comment_prefixes: tuple[str, ...])
key2
""",
{"key value": {"key2": "value2", "key3": "value3"}, "key value4": "key2"},
id="variant-6",
),
(
pytest.param(
"""
key value
value2
key2 value
key3 value3
""",
{"key value": "value2", "key2 value": {"key3": "value3"}},
id="variant-6",
),
],
)
Expand Down Expand Up @@ -383,7 +390,7 @@ def test_env_parser(input: str | Path, expected_output: dict) -> None:
@pytest.mark.parametrize(
("string_data", "expected_output"),
[
(
pytest.param(
'default-duid "\\000\\001\\000\\001\\037\\305\\371\\341\\001\\002\\003\\004\\005\\006"\nlease {\ninterface "eth0"; # some comment\nfixed-address "1.2.3.4";\noption subnet-mask 255.255.255.0;\nrenew 2 2023/10/04 13:37:04;\n# some other comment}', # noqa: E501
{
"default-duid": '"\\000\\001\\000\\001\\037\\305\\371\\341\\001\\002\\003\\004\\005\\006"',
Expand All @@ -394,6 +401,7 @@ def test_env_parser(input: str | Path, expected_output: dict) -> None:
"renew": "2 2023/10/04 13:37:04",
},
},
id="dhcp-lease",
),
],
)
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/test_fsutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ def glob_fs() -> VirtualFilesystem:
("/", "boo/bla/*", []),
],
)
def test_glob_ext(glob_fs: VirtualFilesystem, start_path: str, pattern: str, results: list[str]) -> None:
def test_fsutil_glob_ext(glob_fs: VirtualFilesystem, start_path: str, pattern: str, results: list[str]) -> None:
start_entry = glob_fs.get(start_path)
entries = fsutil.glob_ext(start_entry, pattern)

Expand Down
Loading