-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81d1ea7
commit 3e4747b
Showing
2 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import pytest | ||
from unittest.mock import Mock | ||
from typing import Dict, Optional | ||
from endstone_bstats._charts.drilldown_pie import DrilldownPie | ||
|
||
|
||
def test_get_chart_data_none(): | ||
"""Test that get_chart_data returns None when the callable returns None.""" | ||
callable_mock = Mock(return_value=None) | ||
drilldown_pie = DrilldownPie("chart_id", callable_mock) | ||
|
||
result = drilldown_pie.get_chart_data() | ||
assert result is None | ||
|
||
|
||
def test_get_chart_data_empty(): | ||
"""Test that get_chart_data returns None when the callable returns an empty dictionary.""" | ||
callable_mock = Mock(return_value={}) | ||
drilldown_pie = DrilldownPie("chart_id", callable_mock) | ||
|
||
result = drilldown_pie.get_chart_data() | ||
assert result is None | ||
|
||
|
||
def test_get_chart_data_valid(): | ||
"""Test that get_chart_data processes and returns valid data correctly.""" | ||
data = { | ||
"Category A": {"Sub A1": 10, "Sub A2": 20}, | ||
"Category B": {"Sub B1": 15, "Sub B2": 25}, | ||
"Category C": {} | ||
} | ||
callable_mock = Mock(return_value=data) | ||
drilldown_pie = DrilldownPie("chart_id", callable_mock) | ||
|
||
result = drilldown_pie.get_chart_data() | ||
expected_result = { | ||
"values": { | ||
"Category A": {"Sub A1": 10, "Sub A2": 20}, | ||
"Category B": {"Sub B1": 15, "Sub B2": 25} | ||
} | ||
} | ||
assert result == expected_result | ||
|
||
|
||
def test_get_chart_data_some_empty_values(): | ||
"""Test that get_chart_data omits empty sub-dictionaries.""" | ||
data = { | ||
"Category A": {"Sub A1": 10, "Sub A2": 20}, | ||
"Category B": {}, | ||
} | ||
callable_mock = Mock(return_value=data) | ||
drilldown_pie = DrilldownPie("chart_id", callable_mock) | ||
|
||
result = drilldown_pie.get_chart_data() | ||
expected_result = { | ||
"values": { | ||
"Category A": {"Sub A1": 10, "Sub A2": 20}, | ||
} | ||
} | ||
assert result == expected_result | ||
|
||
|
||
def test_get_chart_data_all_empty_values(): | ||
"""Test that get_chart_data returns None when all sub-dictionaries in the callable result are empty.""" | ||
data = { | ||
"Category A": {}, | ||
"Category B": {}, | ||
"Category C": {} | ||
} | ||
callable_mock = Mock(return_value=data) | ||
drilldown_pie = DrilldownPie("chart_id", callable_mock) | ||
|
||
result = drilldown_pie.get_chart_data() | ||
assert result is None |