-
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.
feat: add tests for newly added charts
- Loading branch information
1 parent
929312b
commit 8a857e6
Showing
5 changed files
with
161 additions
and
5 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,53 @@ | ||
from unittest.mock import Mock | ||
|
||
from endstone_bstats._charts.advanced_bar_chart import AdvancedBarChart | ||
|
||
|
||
def test_get_chart_data_none(): | ||
"""Test that get_chart_data returns None when the callable returns None.""" | ||
callable_mock = Mock(return_value=None) | ||
advanced_bar_chart = AdvancedBarChart("chart_id", callable_mock) | ||
|
||
result = advanced_bar_chart.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={}) | ||
advanced_bar_chart = AdvancedBarChart("chart_id", callable_mock) | ||
|
||
result = advanced_bar_chart.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 = {"Bar A": [10, 20], "Bar B": [15, 25], "Bar C": [30]} | ||
callable_mock = Mock(return_value=data) | ||
advanced_bar_chart = AdvancedBarChart("chart_id", callable_mock) | ||
|
||
result = advanced_bar_chart.get_chart_data() | ||
expected_result = {"values": {"Bar A": [10, 20], "Bar B": [15, 25], "Bar C": [30]}} | ||
assert result == expected_result | ||
|
||
|
||
def test_get_chart_data_some_empty_values(): | ||
"""Test that get_chart_data omits bars with empty lists.""" | ||
data = {"Bar A": [10, 20], "Bar B": [], "Bar C": [30]} | ||
callable_mock = Mock(return_value=data) | ||
advanced_bar_chart = AdvancedBarChart("chart_id", callable_mock) | ||
|
||
result = advanced_bar_chart.get_chart_data() | ||
expected_result = {"values": {"Bar A": [10, 20], "Bar C": [30]}} | ||
assert result == expected_result | ||
|
||
|
||
def test_get_chart_data_all_empty_values(): | ||
"""Test that get_chart_data returns None when all bars in the callable result have empty lists.""" | ||
data = {"Bar A": [], "Bar B": [], "Bar C": []} | ||
callable_mock = Mock(return_value=data) | ||
advanced_bar_chart = AdvancedBarChart("chart_id", callable_mock) | ||
|
||
result = advanced_bar_chart.get_chart_data() | ||
assert result is None |
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,53 @@ | ||
from unittest.mock import Mock | ||
|
||
from endstone_bstats._charts.multi_line_chart import MultiLineChart | ||
|
||
|
||
def test_get_chart_data_none(): | ||
"""Test that get_chart_data returns None when the callable returns None.""" | ||
callable_mock = Mock(return_value=None) | ||
multi_line_chart = MultiLineChart("chart_id", callable_mock) | ||
|
||
result = multi_line_chart.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={}) | ||
multi_line_chart = MultiLineChart("chart_id", callable_mock) | ||
|
||
result = multi_line_chart.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 = {"Line A": 10, "Line B": 20, "Line C": 30} | ||
callable_mock = Mock(return_value=data) | ||
multi_line_chart = MultiLineChart("chart_id", callable_mock) | ||
|
||
result = multi_line_chart.get_chart_data() | ||
expected_result = {"values": {"Line A": 10, "Line B": 20, "Line C": 30}} | ||
assert result == expected_result | ||
|
||
|
||
def test_get_chart_data_some_zero_values(): | ||
"""Test that get_chart_data omits keys with zero values.""" | ||
data = {"Line A": 10, "Line B": 0, "Line C": 30} | ||
callable_mock = Mock(return_value=data) | ||
multi_line_chart = MultiLineChart("chart_id", callable_mock) | ||
|
||
result = multi_line_chart.get_chart_data() | ||
expected_result = {"values": {"Line A": 10, "Line C": 30}} | ||
assert result == expected_result | ||
|
||
|
||
def test_get_chart_data_all_zero_values(): | ||
"""Test that get_chart_data returns None when all values in the callable result are zero.""" | ||
data = {"Line A": 0, "Line B": 0, "Line C": 0} | ||
callable_mock = Mock(return_value=data) | ||
multi_line_chart = MultiLineChart("chart_id", callable_mock) | ||
|
||
result = multi_line_chart.get_chart_data() | ||
assert result is None |
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,54 @@ | ||
from unittest.mock import Mock | ||
|
||
from endstone_bstats._charts.simple_bar_chart import SimpleBarChart | ||
|
||
|
||
def test_get_chart_data_none(): | ||
"""Test that get_chart_data returns None when the callable returns None.""" | ||
callable_mock = Mock(return_value=None) | ||
simple_bar_chart = SimpleBarChart("chart_id", callable_mock) | ||
|
||
result = simple_bar_chart.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={}) | ||
simple_bar_chart = SimpleBarChart("chart_id", callable_mock) | ||
|
||
result = simple_bar_chart.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 = {"Bar A": 10, "Bar B": 20, "Bar C": 30} | ||
callable_mock = Mock(return_value=data) | ||
simple_bar_chart = SimpleBarChart("chart_id", callable_mock) | ||
|
||
result = simple_bar_chart.get_chart_data() | ||
expected_result = {"values": {"Bar A": [10], "Bar B": [20], "Bar C": [30]}} | ||
assert result == expected_result | ||
|
||
|
||
def test_get_chart_data_some_zero_values(): | ||
"""Test that get_chart_data includes zero values wrapped in a list.""" | ||
data = {"Bar A": 10, "Bar B": 0, "Bar C": 30} | ||
callable_mock = Mock(return_value=data) | ||
simple_bar_chart = SimpleBarChart("chart_id", callable_mock) | ||
|
||
result = simple_bar_chart.get_chart_data() | ||
expected_result = {"values": {"Bar A": [10], "Bar B": [0], "Bar C": [30]}} | ||
assert result == expected_result | ||
|
||
|
||
def test_get_chart_data_all_zero_values(): | ||
"""Test that get_chart_data includes bars with zero values wrapped in a list.""" | ||
data = {"Bar A": 0, "Bar B": 0, "Bar C": 0} | ||
callable_mock = Mock(return_value=data) | ||
simple_bar_chart = SimpleBarChart("chart_id", callable_mock) | ||
|
||
result = simple_bar_chart.get_chart_data() | ||
expected_result = {"values": {"Bar A": [0], "Bar B": [0], "Bar C": [0]}} | ||
assert result == expected_result |