-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_iscc_code.py
86 lines (63 loc) · 3.01 KB
/
test_iscc_code.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
85
86
# -*- coding: utf-8 -*-
import pytest
import iscc_core as ic
MID_64 = "AAAYPXW445FTYNJ3"
CID_64 = "EAARMJLTQCUWAND2"
DID_128 = "GABVVC5DMJJGYKZ4ZBYVNYABFFYXG"
IID_256 = "IADWIK7A7JTUAQ2D6QARX7OBEIK3OOUAM42LOBLCZ4ZOGDLRHMDL6TQ"
DID_64 = "GAAQQICFKJYKY4KU"
def test_gen_iscc_code_full():
icode = ic.gen_iscc_code([MID_64, CID_64, DID_128, IID_256])
assert icode == {"iscc": "ISCC:KACYPXW445FTYNJ3CYSXHAFJMA2HUWULUNRFE3BLHRSCXYH2M5AEGQY"}
assert (
ic.iscc_explain(icode["iscc"])
== "ISCC-TEXT-V0-MCDI-87dedce74b3c353b16257380a960347a5a8ba362526c2b3c642be0fa67404343"
)
def test_gen_iscc_code_v0_full():
icode = ic.gen_iscc_code_v0([MID_64, CID_64, DID_128, IID_256])
assert icode == {"iscc": "ISCC:KACYPXW445FTYNJ3CYSXHAFJMA2HUWULUNRFE3BLHRSCXYH2M5AEGQY"}
assert (
ic.iscc_explain(icode["iscc"])
== "ISCC-TEXT-V0-MCDI-87dedce74b3c353b16257380a960347a5a8ba362526c2b3c642be0fa67404343"
)
def test_gen_iscc_code_v0_no_meta():
icode = ic.gen_iscc_code_v0([CID_64, DID_128, IID_256])
assert icode == {"iscc": "ISCC:KAARMJLTQCUWAND2LKF2GYSSNQVTYZBL4D5GOQCDIM"}
assert (
ic.iscc_explain(icode["iscc"])
== "ISCC-TEXT-V0-CDI-16257380a960347a5a8ba362526c2b3c642be0fa67404343"
)
def test_gen_iscc_code_v0_no_meta_content():
icode = ic.gen_iscc_code_v0([DID_128, IID_256])
assert icode == {"iscc": "ISCC:KUAFVC5DMJJGYKZ4MQV6B6THIBBUG"}
# we may also get a ISCC-SUM-V0-256 version
assert ic.iscc_explain(icode["iscc"]) == "ISCC-SUM-V0-DI-5a8ba362526c2b3c642be0fa67404343"
def test_gen_iscc_code_v0_no_meta_content_128():
icode = ic.gen_iscc_code_v0([DID_64, IID_256])
assert icode == {"iscc": "ISCC:KUAAQICFKJYKY4KUMQV6B6THIBBUG"}
assert ic.iscc_explain(icode["iscc"]) == "ISCC-SUM-V0-DI-0820455270ac7154642be0fa67404343"
def test_gen_iscc_code_v0_ordering():
icode = ic.gen_iscc_code_v0([CID_64, MID_64, IID_256, DID_128])
assert icode == {"iscc": "ISCC:KACYPXW445FTYNJ3CYSXHAFJMA2HUWULUNRFE3BLHRSCXYH2M5AEGQY"}
assert (
ic.iscc_explain(icode["iscc"])
== "ISCC-TEXT-V0-MCDI-87dedce74b3c353b16257380a960347a5a8ba362526c2b3c642be0fa67404343"
)
def test_gen_iscc_code_v0_insufficient_codes_raises():
with pytest.raises(ValueError) as e:
ic.gen_iscc_code_v0([CID_64])
assert "Minimum two" in str(e)
def test_gen_iscc_code_v0_32_bit_codes_raise():
with pytest.raises(ValueError) as e:
ic.gen_iscc_code_v0(["AAAGKLHFXM", "EAAP5Q74YU"])
assert "Cannot build" in str(e)
def test_gen_iscc_code_v0_data_or_instance_missing_raises():
with pytest.raises(ValueError) as e:
ic.gen_iscc_code_v0([MID_64, CID_64, DID_128])
assert "ISCC-CODE requires" in str(e)
def test_gen_iscc_code_v0_incompat_semantic_content_raises():
sema = ic.Code.rnd(ic.MT.SEMANTIC, 0, bits=64).code
cont = ic.Code.rnd(ic.MT.CONTENT, 1, bits=64).code
with pytest.raises(ValueError) as e:
ic.gen_iscc_code_v0([sema, cont, DID_64, IID_256])
assert "Semantic-Code" in str(e)