Skip to content

Commit

Permalink
Add test for scan window
Browse files Browse the repository at this point in the history
Create new fixture `scantest` for testing `scan` window separately
Remove extra loop and include the lines in existing loop
Add `pragma: no cover` for the constructor of Assess to exclude it from the `coverage`

Signed-off-by: Shounak Dey <[email protected]>
  • Loading branch information
sdglitched committed Oct 2, 2024
1 parent 3da9dc2 commit 1e24db8
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gi_loadouts/face/wind/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class Assess:
def __init__(self) -> None:
def __init__(self) -> None: # pragma: no cover
self.collection = Collection()
self.c_team = None
self.c_weap = None
Expand Down
1 change: 0 additions & 1 deletion gi_loadouts/face/wind/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def initialize_events(self) -> None:
drop, text = getattr(self, f"arti_{part}_name_{alfa}"), getattr(self, f"arti_{part}_data_{alfa}")
drop.currentTextChanged.connect(lambda _, a_drop=drop, a_text=text: self.render_lineedit_readonly_when_none(a_drop, a_text))
text.textChanged.connect(self.validate_lineedit_userdata)
for part in ["fwol", "pmod", "sdoe", "gboe", "ccol"]:
getattr(self, f"arti_{part}_scan").clicked.connect(lambda _, a_part=part: self.show_scan_dialog(a_part))
getattr(self, f"arti_{part}_load").clicked.connect(lambda _, a_part=part: self.arti_load(a_part))
getattr(self, f"arti_{part}_save").clicked.connect(lambda _, a_part=part: self.arti_save(a_part))
Expand Down
13 changes: 13 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from gi_loadouts.face.scan.main import ScanDialog
from gi_loadouts.face.wind.main import MainWindow


Expand All @@ -8,3 +9,15 @@ def runner(qtbot):
testwind = MainWindow()
qtbot.addWidget(testwind)
return testwind


@pytest.fixture
def scantest(qtbot):
"""
The codebase will automatically detect the part
once the artifact is changed manually in the window
or changed by the after the scan
"""
testscan = ScanDialog("fwol")
qtbot.addWidget(testscan)
return testscan
15 changes: 15 additions & 0 deletions test/face/scan/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from gi_loadouts.type.arti.base import (
MainStatType_CCOL,
MainStatType_FWOL,
MainStatType_GBOE,
MainStatType_PMOD,
MainStatType_SDOE,
)

__dist__ = {
"Flower of Life": {"list": MainStatType_FWOL, "part": "fwol"},
"Plume of Death": {"list": MainStatType_PMOD, "part": "pmod"},
"Sands of Eon": {"list": MainStatType_SDOE, "part": "sdoe"},
"Goblet of Eonothem": {"list": MainStatType_GBOE, "part": "gboe"},
"Circlet of Logos": {"list": MainStatType_CCOL, "part": "ccol"},
}
122 changes: 122 additions & 0 deletions test/face/scan/test_scan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from random import choice

import pytest
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QDialog

from gi_loadouts import __versdata__
from gi_loadouts.data.arti import __artilist__
from gi_loadouts.face.util import truncate_text
from gi_loadouts.type.arti import ArtiLevl, base
from gi_loadouts.type.stat import STAT
from test.face.scan import __dist__


@pytest.mark.parametrize(
"_",
[
pytest.param(None, id="face.scan: Test OCR functionality")
]
)
def test_scan(scantest, _) -> None:
"""
Test OCR functionality
:return:
"""

"""
Confirm if the user interface elements change accordingly
"""
assert isinstance(scantest, QDialog)
assert scantest.windowTitle() == f"Loadouts for Genshin Impact v{__versdata__}"


@pytest.mark.parametrize(
"name, rare, part, part_type",
[
pytest.param(
name, team.rare, team.fwol, "Flower of Life", id=f"face.scan.rule: Configuration Flower of Life artifact - {name}"
) for name, team in __artilist__.items()
] +
[
pytest.param(
name, team.rare, team.pmod, "Plume of Death", id=f"face.scan.rule: Configuration Plume of Death artifact - {name}"
) for name, team in __artilist__.items()
] +
[
pytest.param(
name, team.rare, team.sdoe, "Sands of Eon", id=f"face.scan.rule: Configuration Sands of Eon artifact - {name}"
) for name, team in __artilist__.items()
] +
[
pytest.param(
name, team.rare, team.gboe, "Goblet of Eonothem", id=f"face.scan.rule: Configuration Goblet of Eonothem artifact - {name}"
) for name, team in __artilist__.items()
] +
[
pytest.param(
name, team.rare, team.ccol, "Circlet of Logos", id=f"face.scan.rule: Configuration Circlet of Logos artifact - {name}"
) for name, team in __artilist__.items()
]
)
def test_arti_drop(scantest, name, rare, part, part_type) -> None:
"""
Test the configuration of artifacts on the user interface
:return:
"""

"""
Set the user interface elements as intended
"""
conf = dict()

conf["dist"] = part_type
scantest.arti_dist.setCurrentText(conf["dist"])
conf["name"] = name
scantest.arti_type.setCurrentText(conf["name"])
conf["rare"] = choice([item for item in rare])
scantest.arti_rare.setCurrentText(conf["rare"].value.name)
conf["levl"] = choice([item for item in ArtiLevl if conf["rare"] in item.value.rare])
scantest.arti_levl.setCurrentText(conf["levl"].value.name)
conf["stat"] = choice([item for item in getattr(base, __dist__[conf["dist"]]["list"].__name__) if item.value != STAT.none])
scantest.arti_name_main.setCurrentText(conf["stat"].value.value)
"""
Confirm if the user interface elements change accordingly
"""
if name == "None":
return

assert scantest.arti_type_name.text() == truncate_text(part.__name__, 34)
assert scantest.arti_data_main.text() == str(round(part.stat_data, 1))


@pytest.mark.parametrize(
"_",
[
pytest.param(None, id="face.scan.rule: Clearing artifact")
]
)
def test_arti_wipe(scantest, qtbot, _) -> None:
"""
Test the configuration of characters on the user interface
:return:
"""

"""
Set the user interface elements as intended
"""
qtbot.mouseClick(scantest.arti_back_wipe, Qt.LeftButton)

"""
Confirm if the user interface elements change accordingly
"""
assert scantest.arti_type.currentText() == "None"
assert scantest.arti_levl.currentText() == "None"
assert scantest.arti_rare.currentText() == "Star 0"
assert scantest.arti_type_name.text() == "None"
for item in ["main", "a", "b", "c", "d"]:
assert getattr(scantest, f"arti_name_{item}").currentText() == "None"
assert getattr(scantest, f"arti_data_{item}").text() == ""

0 comments on commit 1e24db8

Please sign in to comment.