-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(plugins): add aggregate and regexp plugin
- Loading branch information
Showing
32 changed files
with
245 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
|
||
|
||
def pytest_addoption(parser: pytest.Parser) -> None: | ||
parser.addoption( | ||
'--integration', | ||
action='store_true', | ||
dest="integration", | ||
default=False, | ||
help="enable integration tests", | ||
) | ||
|
||
|
||
def pytest_configure(config: pytest.Config) -> None: | ||
config.addinivalue_line("markers", "integration: mark test as integration test") | ||
|
||
|
||
def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None: | ||
if config.getoption("--integration"): | ||
# --integration given in cli: do not skip integration tests | ||
return | ||
|
||
skip_integration = pytest.mark.skip(reason="need --integration option to run") | ||
|
||
for item in items: | ||
if "integration" in item.keywords: | ||
item.add_marker(skip_integration) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import pytest | ||
from pydantic import ValidationError | ||
|
||
from checker.plugins.aggregate import AggregatePlugin | ||
from checker.exceptions import ExecutionFailedError | ||
|
||
|
||
class TestAggregatePlugin: | ||
|
||
@pytest.mark.parametrize("parameters, expected_exception", [ | ||
({'scores': [0.5, 1.0, 1], 'weights': [1, 2, 3], 'strategy': 'mean'}, None), | ||
({'scores': [0.5, 1.0, 1], 'weights': [1, 2, 3]}, None), | ||
({'scores': [0.5, 1.0, 1], 'weights': None}, None), | ||
({'scores': [0.5, 1.0, 1], 'strategy': 'mean'}, None), | ||
({'scores': [0.5, 1.0, 1]}, None), | ||
({'scores': [0.5, 1.0, 1], 'weights': [1, 2, 3], 'strategy': 'invalid_strategy'}, ValidationError), | ||
({}, ValidationError), | ||
]) | ||
def test_plugin_args(self, parameters: dict[str, Any], expected_exception: Exception | None) -> None: | ||
if expected_exception: | ||
with pytest.raises(expected_exception): | ||
AggregatePlugin.Args(**parameters) | ||
else: | ||
AggregatePlugin.Args(**parameters) | ||
|
||
@pytest.mark.parametrize("scores, weights, strategy, expected", [ | ||
([10, 20, 30], None, "mean", "Score: 20.00"), | ||
([1, 2, 3], [0.5, 0.5, 0.5], "sum", "Score: 3.00"), | ||
([2, 4, 6], [1, 2, 3], "min", "Score: 2.00"), | ||
([5, 10, 15], [1, 1, 1], "max", "Score: 15.00"), | ||
([3, 3, 3], [1, 1, 1], "product", "Score: 27.00"), | ||
]) | ||
def test_aggregate_strategies(self, scores, weights, strategy, expected): | ||
plugin = AggregatePlugin() | ||
args = AggregatePlugin.Args(scores=scores, weights=weights, strategy=strategy) | ||
|
||
result = plugin._run(args) | ||
assert expected in result # TODO: test float output when implemented | ||
|
||
@pytest.mark.parametrize("scores, weights", [ | ||
([1, 2, 3], [1, 2]), | ||
([1], [1, 2]), | ||
([], []), | ||
]) | ||
def test_length_mismatch(self, scores: list[float], weights: list[float]) -> None: | ||
# TODO: move to args validation | ||
plugin = AggregatePlugin() | ||
args = AggregatePlugin.Args(scores=scores, weights=weights) | ||
|
||
with pytest.raises(ExecutionFailedError) as e: | ||
plugin._run(args) | ||
assert "Length of scores" in str(e.value) | ||
|
||
def test_default_weights(self) -> None: | ||
plugin = AggregatePlugin() | ||
args = AggregatePlugin.Args(scores=[10, 20, 30], strategy="mean") | ||
|
||
result = plugin._run(args) | ||
assert "Score: 20.00" in result # TODO: test float output when implemented |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# TODO: test plugin loader |
Oops, something went wrong.