Skip to content

Commit

Permalink
Add tests for the remaining part of the codebase
Browse files Browse the repository at this point in the history
Co-authored-by: Shounak Dey <[email protected]>
Co-authored-by: Akashdeep Dhar <[email protected]>
  • Loading branch information
sdglitched and gridhead committed Oct 17, 2024
1 parent 596e1be commit 090a340
Show file tree
Hide file tree
Showing 17 changed files with 460 additions and 189 deletions.
19 changes: 8 additions & 11 deletions gi_loadouts/face/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from io import BytesIO

from PIL import Image, ImageEnhance, ImageFilter, UnidentifiedImageError
from PIL import Image, ImageEnhance, ImageFilter
from PySide6.QtCore import QResource
from PySide6.QtGui import QImage, QPixmap

Expand All @@ -27,16 +27,13 @@ def modify_graphics_resource(path: str, radius: float = 2.5, shadow: float = 0.5
:param path: Path to the imported image file in the resource
:return: Pixmap created on transformation for user interface
"""
try:
resource = QResource(path)
data = resource.data()
iobt = BytesIO(data)
proc = Image.open(iobt).convert("RGBA").filter(ImageFilter.GaussianBlur(radius=radius))
proc = ImageEnhance.Brightness(proc).enhance(shadow)
qimg = QImage(proc.tobytes(), proc.width, proc.height, QImage.Format_RGBA8888)
rtrn = QPixmap.fromImage(qimg)
except UnidentifiedImageError:
rtrn = QPixmap(path)
resource = QResource(path)
data = resource.data()
iobt = BytesIO(data)
proc = Image.open(iobt).convert("RGBA").filter(ImageFilter.GaussianBlur(radius=radius))
proc = ImageEnhance.Brightness(proc).enhance(shadow)
qimg = QImage(proc.tobytes(), proc.width, proc.height, QImage.Format_RGBA8888)
rtrn = QPixmap.fromImage(qimg)
return rtrn


Expand Down
2 changes: 1 addition & 1 deletion gi_loadouts/face/wind/fclt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class Facility(Dialog):
def __init__(self) -> None:
super().__init__()
super().__init__() # pragma: no cover

def arti_save(self, part: str) -> None:
"""
Expand Down
11 changes: 9 additions & 2 deletions gi_loadouts/face/wind/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
class MainWindow(Rule):
def __init__(self) -> None:
super().__init__()
self.dialog = QMessageBox()
self.dialog = QMessageBox(parent=self)
self.setupUi(self)
self.setWindowTitle(f"Loadouts for Genshin Impact v{__versdata__}")
self.initialize_events()
self.initialize_elements()
make_temp_file()
try:
make_temp_file()
except Exception as expt:
self.show_dialog(
QMessageBox.Information,
"Initialisation Failed",
f"{expt}",
)

def __del__(self) -> None:
kill_temp_file()
Expand Down
2 changes: 1 addition & 1 deletion gi_loadouts/face/wind/talk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class Dialog:
def __init__(self) -> None:
def __init__(self) -> None: # pragma: no cover
self.dialog = QMessageBox(parent=self)

def show_dialog(self, icon: QMessageBox.Icon, head: str, text: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions gi_loadouts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def load_custom_font() -> None:
QFontDatabase.addApplicationFont(indx)


def main() -> None:
def main() -> None: # pragma: no cover
"""
Initialize the user interface before starting up
Expand All @@ -40,5 +40,5 @@ def main() -> None:
sys.exit(app.exec())


if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
main()
158 changes: 0 additions & 158 deletions gi_loadouts/type/weap/hpak.py

This file was deleted.

36 changes: 35 additions & 1 deletion test/face/otpt/test_otpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QMainWindow
from PySide6.QtWidgets import QMainWindow, QMessageBox

from gi_loadouts import __versdata__
from gi_loadouts.data.char import __charmaps__
Expand Down Expand Up @@ -159,3 +159,37 @@ def test_otpt(runner, qtbot, type, cond) -> None:
assert runner.otptobjc.area_phys_perc_data.text() == f"{str(round(runner.otptobjc.tyvt.damage_bonus_physical_perc.stat_data, 1))}%"
assert runner.otptobjc.area_phys_resi_data.text() == f"{str(round(runner.otptobjc.tyvt.resistance_physical_perc.stat_data, 1))}%"
assert runner.otptobjc.area_crvl_data.text() == f"{str(round(runner.otptobjc.tyvt.critical_damage_perc.stat_data + 2*(runner.otptobjc.tyvt.critical_rate_perc.stat_data), 1))}"


@pytest.mark.parametrize(
"subdata",
[
pytest.param("empty", id="face.otpt.rule: Failing to generate final calculation based on character, bow and default artifact set with empty substats value"),
pytest.param("invalid", id="face.otpt.rule: Failing to generate final calculation based on character, bow and default artifact set with invalid substats value")
]
)
def test_otpt_fail(runner, qtbot, subdata) -> None:
"""
Attempt failing to generate final calculation based on character, weapon and default artifact
:return:
"""

"""
Set the user interface elements as intended
"""
if subdata == "invalid":
runner.arti_fwol_data_a.setText("abc")

"""
Perform the action of clicking the help button
"""
qtbot.mouseClick(runner.head_scan, Qt.LeftButton)

"""
Confirm if the user interface elements change accordingly
"""
assert isinstance(runner.dialog, QMessageBox)
assert runner.dialog.icon() == QMessageBox.Information
assert runner.dialog.windowTitle() == "Inaccuracy detected"
assert "Please consider checking your input." in runner.dialog.text()
Loading

0 comments on commit 090a340

Please sign in to comment.