Add Tests and Coverage report (#341)
This commit is contained in:
+16
@@ -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__":
|
||||
@@ -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
|
||||
|
||||
@@ -22,3 +22,6 @@ info_screenshots/
|
||||
loot_screenshots/
|
||||
stats/
|
||||
.venv
|
||||
.coverage
|
||||
htmlcov/
|
||||
coverage.xml
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
comment: false
|
||||
@@ -13,6 +13,7 @@ dependencies:
|
||||
- beautifultable
|
||||
- pytweening
|
||||
- requests
|
||||
- coverage
|
||||
- pytest
|
||||
- pytest-env
|
||||
- pytest-pythonpath
|
||||
|
||||
+2
-3
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user