-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from acostapazo/feature/add-tests
ENH: add some missing unit testing
- Loading branch information
Showing
7 changed files
with
101 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from gradgpad.foundations.metrics.metric import * # noqa | ||
|
||
from .create_dataframe import * # noqa | ||
# from .create_dataframe import * # noqa | ||
from .group_dataframe import * # noqa | ||
from .open_result_json import * # noqa |
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import pandas as pd | ||
|
||
|
||
def create_dataframe(metric_retriever, results): | ||
|
||
data = {"Metric": [], "Error Rate (%)": [], "Protocol": []} | ||
|
||
for protocol_name, performance_info in sorted(results.items()): | ||
metric, value = metric_retriever(performance_info) | ||
data["Metric"].append(metric) | ||
data["Error Rate (%)"].append(value) | ||
data["Protocol"].append(protocol_name) | ||
df = pd.DataFrame(data, columns=list(data.keys())) | ||
return df | ||
# import pandas as pd | ||
# | ||
# | ||
# def create_dataframe(metric_retriever, results): | ||
# | ||
# data = {"Metric": [], "Error Rate (%)": [], "Protocol": []} | ||
# | ||
# for protocol_name, performance_info in sorted(results.items()): | ||
# metric, value = metric_retriever(performance_info) | ||
# data["Metric"].append(metric) | ||
# data["Error Rate (%)"].append(value) | ||
# data["Protocol"].append(protocol_name) | ||
# df = pd.DataFrame(data, columns=list(data.keys())) | ||
# return df |
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 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
38 changes: 38 additions & 0 deletions
38
tests/unit/tools/visualization/histogram/test_histogram_plotter.py
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,38 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from gradgpad import ( | ||
Approach, | ||
HistogramPlotter, | ||
Protocol, | ||
ScoresProvider, | ||
SplitByLabelMode, | ||
Subset, | ||
) | ||
|
||
|
||
@pytest.mark.unit | ||
@pytest.mark.parametrize("split_by_label_mode", SplitByLabelMode.options_for_curves()) | ||
def test_should_save_a_histogram_plotter(split_by_label_mode: SplitByLabelMode): | ||
os.makedirs("output", exist_ok=True) | ||
output_filename = "output/radar.png" | ||
scores = ScoresProvider.get(Approach.AUXILIARY, Protocol.GRANDTEST, Subset.TEST) | ||
plotter = HistogramPlotter( | ||
title="My Title", | ||
split_by_label_mode=split_by_label_mode, | ||
) | ||
plotter.save(output_filename=output_filename, scores=scores) | ||
assert os.path.isfile(output_filename) | ||
|
||
|
||
@pytest.mark.unit | ||
def test_should_raise_a_io_error_when_save_a_histogram_plotter_with_no_valid_output_filename(): | ||
plotter = HistogramPlotter( | ||
title="My Title", | ||
split_by_label_mode=SplitByLabelMode.DATASET, | ||
) | ||
pytest.raises( | ||
IOError, | ||
lambda: plotter.save(output_filename="not_valid_folder/name", scores=None), | ||
) |
9 changes: 9 additions & 0 deletions
9
tests/unit/tools/visualization/radar/test_fine_grained_pais_provider.py
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,9 @@ | ||
import pytest | ||
|
||
from gradgpad import CombinedScenario, FineGrainedPaisProvider | ||
|
||
|
||
@pytest.mark.unit | ||
@pytest.mark.parametrize("combined_scenario", CombinedScenario.options()) | ||
def test_should_get_fine_grained_pais_provider(combined_scenario: CombinedScenario): | ||
FineGrainedPaisProvider.by(combined_scenario) |