-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_code_flake.py
84 lines (55 loc) · 1.78 KB
/
test_code_flake.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pytest
import iscc_core as ic
TS = 1644830125.1892536
def test_gen_flake_code():
flake = ic.gen_flake_code()["iscc"]
assert len(flake) == 21
assert flake.startswith("ISCC:OAA")
def test_gen_flake_code_v0():
flake = ic.gen_flake_code_v0()["iscc"]
assert len(flake) == 21
assert flake.startswith("ISCC:OAA")
def test_uid_flake_v0():
assert ic.uid_flake_v0(0).hex().startswith("000000000000")
ts = 1644789890.9664667
assert ic.uid_flake_v0(ts).hex().startswith("017ef51dff96")
def test_uid_flake_v0_raises():
with pytest.raises(ValueError):
ic.uid_flake_v0(bits=31)
with pytest.raises(ValueError):
ic.uid_flake_v0(bits=257)
with pytest.raises(ValueError):
ic.uid_flake_v0(bits=65)
def test_Flake_init():
flake = ic.Flake()
assert isinstance(flake, ic.Flake)
def test_Flake_iscc():
flake = ic.Flake(ts=TS)
assert flake.iscc.startswith("ISCC:OAAQC7XXQPWI")
def test_Flake_repr():
flake = ic.Flake(ts=TS)
assert repr(flake).startswith('Flake("05VFF0VC')
def test_Flake_str():
flake = ic.Flake(ts=TS)
assert str(flake) == flake.string
assert flake.string.startswith("05VFF0VCG")
def test_Flake_int():
flake = ic.Flake(ts=TS)
assert isinstance(flake.int, int)
assert str(flake.int).startswith("107795587084")
def test_Flake_time():
flake = ic.Flake(ts=TS)
assert flake.time == "2022-02-14T09:15:25.189"
def test_Flake_from_int():
flake = ic.Flake()
assert flake == ic.Flake.from_int(flake.int)
def test_Flake_from_str():
flake = ic.Flake()
assert flake == ic.Flake.from_string(flake.string)
def test_Flake_hashable():
assert {ic.Flake()}
def test_Flake_ordered():
f1 = ic.Flake()
f2 = ic.Flake()
assert f1 < f2
assert f2 > f1