Add Tests and Coverage report (#341)

This commit is contained in:
aeon0
2021-12-28 14:40:28 +01:00
committed by GitHub
parent 3b6e92fcb1
commit 7eef36c2df
7 changed files with 56 additions and 5 deletions
+16
View File
@@ -0,0 +1,16 @@
# .coveragerc to control coverage.py
[run]
branch = True
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == "__main__":
+8 -2
View File
@@ -39,9 +39,15 @@ jobs:
run: |
C:\Miniconda\condabin\conda.bat init powershell
set PYTHONPATH=./src
- name: Pytest
- name: Pytest & Coverage
shell: powershell
run: |
C:\Miniconda\condabin\conda.bat activate botty
python -c "import sys; print(sys.version)"
pytest -v -s
coverage run --source=./src -m pytest -v -s
coverage xml
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2
with:
verbose: true
files: ./coverage.xml
+3
View File
@@ -22,3 +22,6 @@ info_screenshots/
loot_screenshots/
stats/
.venv
.coverage
htmlcov/
coverage.xml
+1
View File
@@ -0,0 +1 @@
comment: false
+1
View File
@@ -13,6 +13,7 @@ dependencies:
- beautifultable
- pytweening
- requests
- coverage
- pytest
- pytest-env
- pytest-pythonpath
+2 -3
View File
@@ -14,7 +14,6 @@ class GameStats:
def __init__(self):
self._config = Config()
self._messenger = Messenger()
self._picked_up_items = []
self._start_time = time.time()
self._timer = None
self._timepaused = None
@@ -54,8 +53,8 @@ class GameStats:
self._location_stats[self._location] = { "items": [], "deaths": 0, "chickens": 0, "merc_deaths": 0, "failed_runs": 0 }
def log_item_pickup(self, item_name: str, send_message: bool):
self._picked_up_items.append(item_name)
if self._location is not None:
filtered_items = ["_potion", "misc_gold"]
if self._location is not None and not any(substring in item_name for substring in filtered_items):
self._location_stats[self._location]["items"].append(item_name)
if send_message:
+25
View File
@@ -0,0 +1,25 @@
import pytest
from logger import Logger
from game_stats import GameStats
class TestGameStats:
def setup_method(self):
Logger.init()
Logger.remove_file_logger()
self.game_stats = GameStats()
@pytest.mark.parametrize("item_name, item_should_be_added", [
("some_magic_item", True),
("misc_jewel", True),
("misc_gold", False),
("some_potion", False),
("super_healing_potion", False),
])
def test_adjust_abs_range_to_screen(self, item_name: str, item_should_be_added: bool):
self.game_stats.update_location("test_location")
previous_item_count = len(self.game_stats._location_stats["test_location"]["items"])
self.game_stats.log_item_pickup(item_name, send_message=False)
new_item_count = len(self.game_stats._location_stats["test_location"]["items"])
item_was_added = previous_item_count < new_item_count
assert(item_was_added == item_should_be_added)