Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example with std library module #13

Merged
merged 4 commits into from
Nov 23, 2023
Merged
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
984 changes: 504 additions & 480 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python-tool-competition-2024"
version = "0.1.1"
version = "0.2.0"
description = "Pipeline to create test generators"
authors = ["Nicolas Erni <[email protected]>"]
readme = "README.md"
Expand Down
3 changes: 1 addition & 2 deletions python_tool_competition_2024/calculation/cli_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import os
import subprocess # nosec B404
from collections.abc import Mapping
from typing import Literal, get_args, overload

from ..config import Config
Expand Down Expand Up @@ -112,7 +111,7 @@ def _run_command(config: Config, command: _COMMAND, args: tuple[str, ...]) -> st
raise CommandFailedError((command, *args))


def _extend_env(config: Config) -> Mapping[str, str]:
def _extend_env(config: Config) -> dict[str, str]:
env = os.environ | {
"PYTHONPATH": os.pathsep.join(
(str(config.targets_dir), str(config.results_dir))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import gzip

def compress_string(s):
"""
Compress a string using gzip.

:param s: String to be compressed
:type s: str
:return: Compressed string
:rtype: bytes
"""
return gzip.compress(s.encode('utf-8'))

def decompress_string(compressed):
"""
Decompress a gzipped string.

:param compressed: Compressed string
:type compressed: bytes
:return: Decompressed string
:rtype: str
"""
return gzip.decompress(compressed).decode('utf-8')
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def test_cosmic_ray_calculator(tmp_path: Path) -> None:
"example2": RatioResult(11, 1),
"sub_example": RatioResult(12, 2),
"sub_example.example3": RatioResult(13, 3),
"sub_example.example4": RatioResult(14, 4),
}

assert run_command_mock.call_args_list == [
*_cr_calls(config, "example1"),
*_cr_calls(config, "example2"),
*_cr_calls(config, "sub_example"),
*_cr_calls(config, "sub_example.example3"),
*_cr_calls(config, "sub_example.example4"),
]
cr_path = tmp_path / "dummy" / "cosmic_ray"
assert {
Expand All @@ -67,6 +69,10 @@ def test_cosmic_ray_calculator(tmp_path: Path) -> None:
TARGETS_DIR / "sub_example" / "example3.py", None
),
cr_path
/ "sub_example.example4.toml": _cr_config(
TARGETS_DIR / "sub_example" / "example4.py", None
),
cr_path
/ "sub_example.toml": _cr_config(
TARGETS_DIR / "sub_example" / "__init__.py", None
),
Expand Down Expand Up @@ -101,6 +107,7 @@ def test_cosmic_ray_calculator_with_failing_baseline(tmp_path: Path) -> None:
"example2": RatioResult(11, 1),
"sub_example": RatioResult(12, 2),
"sub_example.example3": RatioResult(13, 3),
"sub_example.example4": RatioResult(14, 4),
}
assert tuple(capture.get().splitlines()) == tuple(
(
Expand All @@ -112,6 +119,7 @@ def test_cosmic_ray_calculator_with_failing_baseline(tmp_path: Path) -> None:
"example2",
"sub_example",
"sub_example.example3",
"sub_example.example4",
)
)

Expand All @@ -120,6 +128,7 @@ def test_cosmic_ray_calculator_with_failing_baseline(tmp_path: Path) -> None:
*_cr_calls(config, "example2", skip_exec=True),
*_cr_calls(config, "sub_example", skip_exec=True),
*_cr_calls(config, "sub_example.example3", skip_exec=True),
*_cr_calls(config, "sub_example.example4", skip_exec=True),
]


Expand Down Expand Up @@ -149,6 +158,7 @@ def test_cosmic_ray_calculator_with_failing_baseline_and_output(tmp_path: Path)
"example2": RatioResult(11, 1),
"sub_example": RatioResult(12, 2),
"sub_example.example3": RatioResult(13, 3),
"sub_example.example4": RatioResult(14, 4),
}
assert tuple(capture.get().splitlines()) == tuple(
f"Could not run mutation testing for {module}."
Expand All @@ -157,6 +167,7 @@ def test_cosmic_ray_calculator_with_failing_baseline_and_output(tmp_path: Path)
"example2",
"sub_example",
"sub_example.example3",
"sub_example.example4",
)
)

Expand All @@ -165,6 +176,7 @@ def test_cosmic_ray_calculator_with_failing_baseline_and_output(tmp_path: Path)
*_cr_calls(config, "example2", skip_exec=True),
*_cr_calls(config, "sub_example", skip_exec=True),
*_cr_calls(config, "sub_example.example3", skip_exec=True),
*_cr_calls(config, "sub_example.example4", skip_exec=True),
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_mutpy_calculator(tmp_path: Path) -> None:
"example2": RatioResult(11, 1),
"sub_example": RatioResult(12, 2),
"sub_example.example3": RatioResult(13, 3),
"sub_example.example4": RatioResult(14, 4),
}

assert run_command_mock.call_args_list == [
Expand All @@ -52,6 +53,7 @@ def test_mutpy_calculator(tmp_path: Path) -> None:
),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "__init__.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "example3.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "example4.py", None),
]


Expand Down Expand Up @@ -88,6 +90,7 @@ def test_mutpy_calculator_always_failing(tmp_path: Path) -> None:
_mutpy_call(config, TARGETS_DIR / "example2.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "__init__.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "example3.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "example4.py", None),
]


Expand Down Expand Up @@ -118,6 +121,7 @@ def test_mutpy_calculator_failing(tmp_path: Path) -> None:
"example2": RatioResult(11, 1),
"sub_example": RatioResult(12, 2),
"sub_example.example3": RatioResult(13, 3),
"sub_example.example4": RatioResult(14, 4),
}

assert tuple(capture.get().splitlines()) == tuple(
Expand All @@ -139,6 +143,7 @@ def test_mutpy_calculator_failing(tmp_path: Path) -> None:
_mutpy_call(config, TARGETS_DIR / "example2.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "__init__.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "example3.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "example4.py", None),
]


Expand Down Expand Up @@ -169,6 +174,7 @@ def test_mutpy_calculator_failing_with_output(tmp_path: Path) -> None:
"example2": RatioResult(11, 1),
"sub_example": RatioResult(12, 2),
"sub_example.example3": RatioResult(13, 3),
"sub_example.example4": RatioResult(14, 4),
}

assert tuple(capture.get().splitlines()) == tuple(
Expand All @@ -187,6 +193,7 @@ def test_mutpy_calculator_failing_with_output(tmp_path: Path) -> None:
_mutpy_call(config, TARGETS_DIR / "example2.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "__init__.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "example3.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "example4.py", None),
]


Expand Down Expand Up @@ -239,6 +246,7 @@ def test_mutpy_calculator_failing_with_wrong_numbers(tmp_path: Path) -> None:
),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "__init__.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "example3.py", None),
_mutpy_call(config, TARGETS_DIR / "sub_example" / "example4.py", None),
]


Expand Down
6 changes: 2 additions & 4 deletions tests/calculation/test_cli_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import re
import subprocess # nosec: B404
from collections.abc import Iterator, Mapping
from collections.abc import Iterator
from contextlib import contextmanager
from pathlib import Path
from unittest import mock
Expand Down Expand Up @@ -91,9 +91,7 @@ def test_invalid_command(capsys: pytest.CaptureFixture[str], *, verbose: bool) -
({"SOME": "test"}, {"SOME": "test"}),
),
)
def test_extend_env(
original_env: Mapping[str, str], expected_env: Mapping[str, str]
) -> None:
def test_extend_env(original_env: dict[str, str], expected_env: dict[str, str]) -> None:
config_mock = sealed_mock(
targets_dir=Path("targets", "path"), results_dir=Path("some", "results", "path")
)
Expand Down
2 changes: 2 additions & 0 deletions tests/cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ def _register_generators(
RatioResult(50, 1),
RatioResult(1, 1),
RatioResult(49, 0),
RatioResult(49, 0),
)

_COVERAGES = (
Coverages(RatioResult(10, 5), RatioResult(15, 6)),
Coverages(RatioResult(3, 0), RatioResult(8, 2)),
Coverages(RatioResult(7, 7), RatioResult(12, 6)),
Coverages(RatioResult(20, 5), RatioResult(25, 16)),
Coverages(RatioResult(20, 5), RatioResult(25, 16)),
)


Expand Down
1 change: 1 addition & 0 deletions tests/cli/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"sub_example": {
"__init__.py": (TARGETS_DIR / "sub_example" / "__init__.py").read_text(),
"example3.py": (TARGETS_DIR / "sub_example" / "example3.py").read_text(),
"example4.py": (TARGETS_DIR / "sub_example" / "example4.py").read_text(),
},
}

Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_main_with_help(help_arg: str) -> None:

def test_main_with_version() -> None:
assert run_successful_cli(("--version",), generators_called=False) == (
"main-cli, version 0.1.1",
"main-cli, version 0.2.0",
)


Expand Down
Loading