-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_protobuf.py
52 lines (40 loc) · 1.26 KB
/
test_protobuf.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
import sys
import os
import pytest
sys.path = [os.path.join(os.path.dirname(__file__), "..")] + sys.path
try:
from physt.io.protobuf import write, write_many, read, read_many
# PROTOBUF_TEST_ENABLED = os.environ.get("PROTOBUF_TEST_ENABLED", False)
PROTOBUF_TEST_ENABLED = True
except:
PROTOBUF_TEST_ENABLED = False
from physt.examples import normal_h1, normal_h2
@pytest.mark.skipif(not PROTOBUF_TEST_ENABLED, reason="Skipping protobuf tests because of an error")
class TestProtobuf:
# End-to-end test
def test_h1(self):
H = normal_h1()
message = write(H)
H_ = read(message)
assert H_ == H
def test_h2(self):
H = normal_h2()
message = write(H)
H_ = read(message)
assert H_ == H
def test_collection(self):
collection = {
"h1": normal_h1(),
"h2": normal_h2()
}
message = write_many(collection)
collection2 = read_many(message)
assert collection == collection2
def test_wrong_message_type(self):
H = normal_h1()
message = write(H)
with pytest.raises(AttributeError):
collection2 = read_many(message)
# TODO: Add more tests
if __name__ == "__main__":
pytest.main(__file__)