-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_acf.py
65 lines (45 loc) · 1.65 KB
/
test_acf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import io
import os
import pytest
from collections import OrderedDict
from steamfiles import acf
from . import sort_dict
test_file_name = os.path.join(os.path.dirname(__file__), 'test_data/appmanifest_202970.acf')
@pytest.fixture(name='acf_data')
def _acf_data():
with open(test_file_name, 'rt') as f:
yield f.read()
def test_acf_keys_exist(acf_data):
data = acf.loads(acf_data)
assert 'BytesDownloaded' in data['AppState']['DlcDownloads']['202988']
assert 'BytesToDownload' in data['AppState']['DlcDownloads']['202988']
def test_loads_dumps(acf_data):
loaded = acf.loads(acf_data)
assert acf.dumps(sort_dict(loaded)) == acf_data
def test_loads_dumps_with_wrapper(acf_data):
loaded = acf.loads(acf_data, wrapper=OrderedDict)
assert isinstance(loaded, OrderedDict)
assert acf.dumps(loaded) == acf_data
def test_load_dump(acf_data):
with open(test_file_name, 'rt') as in_file:
out_file = io.StringIO()
loaded = acf.load(in_file)
acf.dump(sort_dict(loaded), out_file)
# Rewind to the beginning
out_file.seek(0)
assert out_file.read() == acf_data
def test_load_dump_with_wrapper(acf_data):
with open(test_file_name, 'rt') as in_file:
out_file = io.StringIO()
loaded = acf.load(in_file, wrapper=OrderedDict)
acf.dump(loaded, out_file)
# Rewind to the beginning
out_file.seek(0)
assert isinstance(loaded, OrderedDict)
assert out_file.read() == acf_data
def test_loads_wrong_type():
with pytest.raises(TypeError):
acf.loads(b'\x00\x01\x02')
def test_dumps_wrong_type():
with pytest.raises(TypeError):
acf.dumps([1, 2, 3])