Skip to content

Commit 36a2ade

Browse files
author
fieryhenry
committed
Added more tests
1 parent d97032d commit 36a2ade

11 files changed

+589
-27
lines changed

requirements_dev.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
flake8==3.9.2
2+
tox==3.24.3
3+
pytest==6.2.5
4+
pytest-cov==2.12.1
5+
mypy==0.910

tests/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import test_parse
1+
from . import test_item, test_parse, test_edits

tests/test_edits/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_basic, test_cats
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_talent_orbs, test_basic
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Test basic item editing"""
2+
3+
from pytest import MonkeyPatch
4+
from BCSFE_Python.edits.basic import basic_items
5+
6+
7+
def test_cf_normal(monkeypatch: MonkeyPatch):
8+
"""Test that the value is set correctly"""
9+
10+
inputs = ["y", "10"]
11+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
12+
13+
save_stats = {"cat_food": {"Value": 50}}
14+
15+
save_stats = basic_items.edit_cat_food(save_stats)
16+
assert save_stats["cat_food"]["Value"] == 10
17+
18+
19+
def test_catfood_leave(monkeypatch: MonkeyPatch):
20+
"""Test that the value is left unchanged"""
21+
22+
inputs = ["n", "10"]
23+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
24+
25+
save_stats = {"cat_food": {"Value": 50}}
26+
27+
save_stats = basic_items.edit_cat_food(save_stats)
28+
assert save_stats["cat_food"]["Value"] == 50
29+
30+
31+
def test_iq_normal(monkeypatch: MonkeyPatch):
32+
"""Test that the value is set correctly"""
33+
34+
inputs = ["abcdefghi"]
35+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
36+
37+
save_stats = {"inquiry_code": "123456789"}
38+
39+
save_stats = basic_items.edit_inquiry_code(save_stats)
40+
assert save_stats["inquiry_code"] == "abcdefghi"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""Test talent orbs"""
2+
3+
from typing import Any
4+
from pytest import MonkeyPatch
5+
6+
from BCSFE_Python.edits.basic import talent_orbs
7+
8+
9+
def test_create_orb_list():
10+
"""Test that the list of all possible talent orbs is created correctly"""
11+
12+
types = talent_orbs.get_talent_orbs_types()
13+
assert len(types) == 155
14+
15+
assert "Red D Attack" == types[0]
16+
assert "Red C Attack" == types[1]
17+
18+
assert "Red D Defense" == types[5]
19+
20+
assert "Floating D Attack" == types[10]
21+
22+
assert "Red D Strong" == types[65]
23+
assert "Alien S Resistant" == types[139]
24+
25+
26+
def test_edit_all_orbs(monkeypatch: MonkeyPatch):
27+
"""Test that all talent orbs are edited correctly"""
28+
29+
inputs = ["10"]
30+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
31+
save_stats: dict[str, Any] = {
32+
"talent_orbs": {
33+
51: 5,
34+
0: 10,
35+
98: 0,
36+
19: 1,
37+
}
38+
}
39+
types = talent_orbs.get_talent_orbs_types()
40+
save_stats = talent_orbs.edit_all_orbs(save_stats, types)
41+
42+
assert len(save_stats["talent_orbs"]) == len(types)
43+
for i in range(len(types)):
44+
assert save_stats["talent_orbs"][i] == 10
45+
46+
47+
def test_edit_all_orbs_invalid(monkeypatch: MonkeyPatch):
48+
"""Test that all talent orbs are edited correctly"""
49+
50+
inputs = ["aaa", "15"]
51+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
52+
save_stats_b: dict[str, Any] = {
53+
"talent_orbs": {
54+
51: 5,
55+
0: 10,
56+
98: 0,
57+
19: 1,
58+
}
59+
}
60+
types = talent_orbs.get_talent_orbs_types()
61+
save_stats = talent_orbs.edit_all_orbs(save_stats_b, types)
62+
63+
assert save_stats_b == save_stats
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_cat_id_selector
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
from pytest import MonkeyPatch
2+
from BCSFE_Python.edits.cats import cat_id_selector
3+
4+
5+
def test_get_all_cats():
6+
"""Test that the ids are correct"""
7+
save_stats = {"cats": [1, 1, 1, 0, 1]}
8+
ids = cat_id_selector.get_all_cats(save_stats)
9+
assert ids == [0, 1, 2, 3, 4]
10+
11+
12+
def test_select_range(monkeypatch: MonkeyPatch):
13+
"""Test that the ids are correct"""
14+
15+
inputs = ["1-5"]
16+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
17+
save_stats = {"cats": [1, 1, 1, 0, 1]}
18+
19+
ids = cat_id_selector.select_cats_range(save_stats)
20+
actual_ids = [1, 2, 3, 4, 5]
21+
assert ids == actual_ids
22+
23+
def test_select_current():
24+
"""Test that the ids are correct"""
25+
26+
save_stats = {"cats": [1, 1, 1, 0, 1]}
27+
28+
ids = cat_id_selector.select_current_cats(save_stats)
29+
actual_ids = [0, 1, 2, 4]
30+
assert ids == actual_ids
31+
32+
def test_select_rarity(monkeypatch: MonkeyPatch):
33+
"""Test that the ids are correct"""
34+
35+
inputs = ["1"]
36+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
37+
38+
ids = cat_id_selector.select_cats_rarity(False)
39+
actual_ids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 643]
40+
assert ids == actual_ids
41+
42+
def test_select_range_reverse(monkeypatch: MonkeyPatch):
43+
"""Test that the ids are correct"""
44+
45+
inputs = ["5-1"]
46+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
47+
save_stats = {"cats": [1, 1, 1, 0, 1]}
48+
49+
ids = cat_id_selector.select_cats_range(save_stats)
50+
actual_ids = [1, 2, 3, 4, 5]
51+
assert ids == actual_ids
52+
53+
def test_select_range_mult(monkeypatch: MonkeyPatch):
54+
"""Test that the ids are correct"""
55+
56+
inputs = ["1-5 7-10"]
57+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
58+
save_stats = {"cats": [1, 1, 1, 0, 1]}
59+
60+
ids = cat_id_selector.select_cats_range(save_stats)
61+
actual_ids = [1, 2, 3, 4, 5, 7, 8, 9, 10]
62+
assert ids == actual_ids
63+
64+
def test_select_range_spaces(monkeypatch: MonkeyPatch):
65+
"""Test that the ids are correct"""
66+
67+
inputs = ["1 4 7 2"]
68+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
69+
save_stats = {"cats": [1, 1, 1, 0, 1]}
70+
71+
ids = cat_id_selector.select_cats_range(save_stats)
72+
actual_ids = [1, 4, 7, 2]
73+
assert ids == actual_ids
74+
75+
def test_select_range_comb(monkeypatch: MonkeyPatch):
76+
"""Test that the ids are correct"""
77+
78+
inputs = ["1 4 7 2 8-10"]
79+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
80+
save_stats = {"cats": [1, 1, 1, 0, 1]}
81+
82+
ids = cat_id_selector.select_cats_range(save_stats)
83+
actual_ids = [1, 4, 7, 2, 8, 9, 10]
84+
assert ids == actual_ids
85+
86+
def test_select_range_all(monkeypatch: MonkeyPatch):
87+
"""Test that the ids are correct"""
88+
89+
inputs = ["all"]
90+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
91+
save_stats = {"cats": [1, 1, 1, 0, 1]}
92+
93+
ids = cat_id_selector.select_cats_range(save_stats)
94+
actual_ids = [0, 1, 2, 3, 4]
95+
assert ids == actual_ids
96+
97+
98+
def test_gatya_banner(monkeypatch: MonkeyPatch):
99+
"""Test that the ids are correct"""
100+
101+
inputs = ["602"]
102+
monkeypatch.setattr("builtins.input", lambda: inputs.pop(0))
103+
104+
ids = cat_id_selector.select_cats_gatya_banner(False)
105+
ids.sort()
106+
actual_ids = [
107+
448,
108+
449,
109+
450,
110+
451,
111+
455,
112+
461,
113+
463,
114+
478,
115+
481,
116+
493,
117+
544,
118+
612,
119+
138,
120+
259,
121+
330,
122+
195,
123+
496,
124+
358,
125+
376,
126+
502,
127+
526,
128+
533,
129+
564,
130+
229,
131+
30,
132+
31,
133+
32,
134+
33,
135+
35,
136+
36,
137+
39,
138+
40,
139+
61,
140+
150,
141+
151,
142+
152,
143+
153,
144+
199,
145+
307,
146+
377,
147+
522,
148+
37,
149+
38,
150+
41,
151+
42,
152+
46,
153+
47,
154+
48,
155+
49,
156+
50,
157+
51,
158+
52,
159+
55,
160+
56,
161+
58,
162+
106,
163+
145,
164+
146,
165+
147,
166+
148,
167+
149,
168+
197,
169+
198,
170+
308,
171+
325,
172+
495,
173+
271,
174+
523,
175+
]
176+
actual_ids.sort()
177+
assert ids == actual_ids

tests/test_helper.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Test helper module"""
2+
3+
from BCSFE_Python import helper
4+
5+
6+
def test_str_to_gv():
7+
"""Test that a game version with . is converted to an int representation"""
8+
assert helper.str_to_gv("1.0.0") == "10000"
9+
assert helper.str_to_gv("11.8.2") == "110802"
10+
assert helper.str_to_gv("1.7") == "10700"
11+
assert helper.str_to_gv("10.87") == "108700"
12+
13+
14+
def test_gv_to_str():
15+
"""Test that an int representation is converted to a game version with ."""
16+
assert helper.gv_to_str(10000) == "1.0.0"
17+
assert helper.gv_to_str(110802) == "11.8.2"
18+
assert helper.gv_to_str(10700) == "1.7.0"
19+
assert helper.gv_to_str(108700) == "10.87.0"

0 commit comments

Comments
 (0)