-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_reference.py
55 lines (40 loc) · 1.35 KB
/
test_reference.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
# SPDX-FileCopyrightText: (c) 2021-2022 Artёm IG <github.com/rtmigo>
# SPDX-License-Identifier: MIT
import time
import unittest
from io import BytesIO
from pathlib import Path
from dmk._vault_file import DmkFile
from dmk.a_base import CodenameKey
ref_content = [
('one', bytes([11, 22, 33])),
('empty', bytes([])),
('192k large', bytes([1, 2, 3] * (1024 * 64)))
]
refs_file = Path(__file__).parent / "data" / "ref_vault.dmk"
def generate_references():
assert CodenameKey.is_standard_params()
if not input(f"Really replace {refs_file} (y/N)? ").lower().startswith('y'):
print("Canceled")
return
if refs_file.exists():
assert "ref_" in refs_file.name
refs_file.unlink()
d = DmkFile(refs_file)
for name, data in ref_content:
t = time.monotonic()
with BytesIO(data) as input_io:
d.set_from_io(name, input_io)
print(f"Written in {time.monotonic() - t}")
class TestRefs(unittest.TestCase):
"""Reading pre-encoded file, checking it reads the content as expected."""
def test(self):
assert CodenameKey.is_standard_params()
d = DmkFile(refs_file)
for name, data in ref_content:
self.assertEqual(d.get_bytes(name), data)
if __name__ == "__main__":
# unittest.main()
generate_references()
TestRefs().test()
print("OK")