Skip to content

Commit

Permalink
add fourth example with std lib module
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammed-ali-1 committed Nov 21, 2023
1 parent ca51361 commit 50e26e4
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 16 deletions.
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
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

0 comments on commit 50e26e4

Please sign in to comment.