Skip to content

Commit 9479530

Browse files
committed
update tests
1 parent a5ea835 commit 9479530

File tree

8 files changed

+180
-221
lines changed

8 files changed

+180
-221
lines changed

conftest.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
11
from os import getenv
2+
from pathlib import Path
23

34
import pytest
45
from dotenv import load_dotenv
56

7+
from src.tf2_utils.utils import read_json_file
8+
69
assert load_dotenv()
710

811
MARKETPLACE_TF_API_KEY = getenv("MARKETPLACE_TF_API_KEY")
912
BACKPACK_TF_TOKEN = getenv("BACKPACK_TF_TOKEN")
1013
EXPRESS_LOAD_API_KEY = getenv("EXPRESS_LOAD_API_KEY")
1114

1215

16+
def get_item_data(file_name: str) -> dict:
17+
path = Path(__file__).parent / f"tests/json/{file_name}.json"
18+
return read_json_file(path)
19+
20+
21+
# items
22+
CRUSADERS_CROSSBOW = get_item_data("crusaders_crossbow")
23+
UNCRAFTABLE_HAT = get_item_data("uncraftable_hat")
24+
HONG_KONG_CONE = get_item_data("hong_kong_cone")
25+
SPELLED_ITEM = get_item_data("spelled_item")
26+
PAINTED_HAT = get_item_data("painted_hat")
27+
ELLIS_CAP = get_item_data("ellis_cap")
28+
29+
1330
@pytest.fixture
1431
def steam_id() -> str:
1532
return "76561198253325712"
1633

1734

35+
@pytest.fixture
36+
def account_id() -> str:
37+
return "293059984"
38+
39+
1840
@pytest.fixture
1941
def marketplace_tf_api_key() -> str:
2042
return MARKETPLACE_TF_API_KEY
@@ -28,3 +50,34 @@ def backpack_tf_token() -> str:
2850
@pytest.fixture
2951
def express_load_api_key() -> str:
3052
return EXPRESS_LOAD_API_KEY
53+
54+
55+
# items
56+
@pytest.fixture
57+
def crusaders_crossbow() -> dict:
58+
return CRUSADERS_CROSSBOW
59+
60+
61+
@pytest.fixture
62+
def uncraftable_hat() -> dict:
63+
return UNCRAFTABLE_HAT
64+
65+
66+
@pytest.fixture
67+
def hong_kong_cone() -> dict:
68+
return HONG_KONG_CONE
69+
70+
71+
@pytest.fixture
72+
def spelled_item() -> dict:
73+
return SPELLED_ITEM
74+
75+
76+
@pytest.fixture
77+
def painted_hat() -> dict:
78+
return PAINTED_HAT
79+
80+
81+
@pytest.fixture
82+
def ellis_cap() -> dict:
83+
return ELLIS_CAP

src/tf2_utils/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import math
33
import struct
4+
from pathlib import Path
45

56
__all__ = [
67
"to_scrap",
@@ -14,7 +15,7 @@
1415
]
1516

1617

17-
def read_json_file(path: str) -> dict | list:
18+
def read_json_file(path: Path | str) -> dict | list:
1819
data = {}
1920

2021
with open(path, "r") as f:
@@ -23,7 +24,7 @@ def read_json_file(path: str) -> dict | list:
2324
return data
2425

2526

26-
def write_json_file(path: str, data: dict | list) -> None:
27+
def write_json_file(path: Path | str, data: dict | list) -> None:
2728
with open(path, "w") as f:
2829
json.dump(data, f, indent=4)
2930

tests/test_currency.py

Lines changed: 48 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,20 @@ def test_utils() -> None:
3535
)
3636
c.calculate()
3737

38-
assert 22 == c.their_scrap
39-
assert 12 == c.our_scrap
40-
41-
assert {
38+
assert c.their_scrap == 22
39+
assert c.our_scrap == 12
40+
assert c.their_overview == {
4241
"Mann Co. Supply Crate Key": 0,
4342
"Refined Metal": 2,
4443
"Reclaimed Metal": 1,
4544
"Scrap Metal": 1,
46-
} == c.their_overview
47-
assert {
45+
}
46+
assert c.our_overview == {
4847
"Mann Co. Supply Crate Key": 0,
4948
"Refined Metal": 1,
5049
"Reclaimed Metal": 1,
5150
"Scrap Metal": 0,
52-
} == c.our_overview
53-
51+
}
5452
assert not c.is_possible
5553

5654

@@ -68,7 +66,7 @@ def test_not_enough() -> None:
6866
)
6967
c.calculate()
7068

71-
assert 19 == c.their_scrap
69+
assert c.their_scrap == 19
7270
assert not c.is_possible
7371

7472

@@ -88,10 +86,9 @@ def test_no_combination() -> None:
8886
)
8987
c.calculate()
9088

91-
assert 18 == c.their_scrap
92-
assert 12 == c.our_scrap
93-
94-
# they have enough but there is no combo which would work
89+
assert c.their_scrap == 18
90+
assert c.our_scrap == 12
91+
# they have enough but there is no combination which would work
9592
assert not c.is_possible
9693

9794

@@ -116,34 +113,31 @@ def test_possible() -> None:
116113
)
117114
c.calculate()
118115

119-
assert 15 == c.their_scrap
120-
assert 12 == c.our_scrap
121-
122-
assert {
116+
assert c.their_scrap == 15
117+
assert c.our_scrap == 12
118+
assert c.their_overview == {
123119
"Mann Co. Supply Crate Key": 0,
124120
"Refined Metal": 1,
125121
"Reclaimed Metal": 0,
126122
"Scrap Metal": 6,
127-
} == c.their_overview
128-
assert {
123+
}
124+
assert c.our_overview == {
129125
"Mann Co. Supply Crate Key": 0,
130126
"Refined Metal": 1,
131127
"Reclaimed Metal": 1,
132128
"Scrap Metal": 0,
133-
} == c.our_overview
134-
129+
}
135130
assert c.is_possible
136-
137131
# 0.44, but we pay 1 ref
138132
# that means they have to add 0.55
139-
assert ["Refined Metal"] == c.our_combination
140-
assert [
133+
assert c.our_combination == ["Refined Metal"]
134+
assert c.their_combination == [
141135
"Scrap Metal",
142136
"Scrap Metal",
143137
"Scrap Metal",
144138
"Scrap Metal",
145139
"Scrap Metal",
146-
] == c.their_combination
140+
]
147141

148142

149143
def test_best_possible() -> None:
@@ -169,31 +163,28 @@ def test_best_possible() -> None:
169163
)
170164
c.calculate()
171165

172-
assert KEY_RATE + 20 == c.their_scrap
173-
assert 18 == c.our_scrap
174-
175-
assert {
166+
assert c.their_scrap == KEY_RATE + 20
167+
assert c.our_scrap == 18
168+
assert c.their_overview == {
176169
"Mann Co. Supply Crate Key": 1,
177170
"Refined Metal": 1,
178171
"Reclaimed Metal": 2,
179172
"Scrap Metal": 5,
180-
} == c.their_overview
181-
assert {
173+
}
174+
assert c.our_overview == {
182175
"Mann Co. Supply Crate Key": 0,
183176
"Refined Metal": 2,
184177
"Reclaimed Metal": 0,
185178
"Scrap Metal": 0,
186-
} == c.our_overview
187-
179+
}
188180
assert c.is_possible
189-
190-
assert [
181+
assert c.their_combination == [
191182
"Scrap Metal",
192183
"Scrap Metal",
193184
"Reclaimed Metal",
194185
"Refined Metal",
195-
] == c.their_combination
196-
assert [] == c.our_combination
186+
]
187+
assert c.our_combination == []
197188

198189

199190
def test_only_metal() -> None:
@@ -216,32 +207,29 @@ def test_only_metal() -> None:
216207
)
217208
c.calculate()
218209

219-
assert 9 == c.their_scrap
220-
assert 18 == c.our_scrap
221-
222-
assert {
210+
assert c.their_scrap == 9
211+
assert c.our_scrap == 18
212+
assert c.their_overview == {
223213
"Mann Co. Supply Crate Key": 0,
224214
"Refined Metal": 0,
225215
"Reclaimed Metal": 2,
226216
"Scrap Metal": 3,
227-
} == c.their_overview
228-
assert {
217+
}
218+
assert c.our_overview == {
229219
"Mann Co. Supply Crate Key": 0,
230220
"Refined Metal": 2,
231221
"Reclaimed Metal": 0,
232222
"Scrap Metal": 0,
233-
} == c.our_overview
234-
223+
}
235224
assert c.is_possible
236-
237-
assert [
225+
assert c.their_combination == [
238226
"Reclaimed Metal",
239227
"Reclaimed Metal",
240228
"Scrap Metal",
241229
"Scrap Metal",
242230
"Scrap Metal",
243-
] == c.their_combination
244-
assert ["Refined Metal"] == c.our_combination
231+
]
232+
assert c.our_combination == ["Refined Metal"]
245233

246234

247235
def test_real_inventory() -> None:
@@ -257,34 +245,31 @@ def test_real_inventory() -> None:
257245

258246
c.calculate()
259247

260-
assert 591 == c.their_scrap
261-
assert 0 == c.our_scrap
262-
263-
assert {
248+
assert c.their_scrap == 591
249+
assert c.our_scrap == 0
250+
assert c.their_overview == {
264251
"Mann Co. Supply Crate Key": 0,
265252
"Refined Metal": 65,
266253
"Reclaimed Metal": 1,
267254
"Scrap Metal": 3,
268-
} == c.their_overview
269-
assert {
255+
}
256+
assert c.our_overview == {
270257
"Mann Co. Supply Crate Key": 0,
271258
"Refined Metal": 0,
272259
"Reclaimed Metal": 0,
273260
"Scrap Metal": 0,
274-
} == c.our_overview
275-
261+
}
276262
assert c.is_possible
277-
278-
assert [
263+
assert c.their_combination == [
279264
"Reclaimed Metal",
280265
"Scrap Metal",
281266
"Scrap Metal",
282267
"Scrap Metal",
283268
"Refined Metal",
284-
] == c.their_combination
285-
assert [] == c.our_combination
269+
]
270+
assert c.our_combination == []
286271

287272
their_items, our_items = c.get_currencies()
288273

289-
assert PICKED_METALS == their_items
290-
assert [] == our_items
274+
assert their_items == PICKED_METALS
275+
assert our_items == []

0 commit comments

Comments
 (0)