-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_scpinfo.py
122 lines (90 loc) · 2.85 KB
/
test_scpinfo.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Test Code
from scpreader import FileReader, ScpReader
from scpformat import Section1TagsFormatter, PatientSexFormatter, PatientRaceFormatter
def test_scp_record():
scp = read_scp()
assert scp.has_section(0)
assert scp.has_section(1)
assert 34144 == scp.len, "SCP record length is wrong"
assert 1643 == scp.crc, "SCP record checksum is wrong"
assert scp.section(0), "No Section 0 in SCP record"
def test_number_of_leads():
scp = read_scp()
assert 12 == scp.number_of_leads(), "Section 3 should contain 12 leads"
def test_section_header():
scp = read_scp()
h = scp.section(0).h
assert 0 == h.id, "Section 0 id should be 0"
assert 136 == h.len, "Section 0 len should be 136"
assert 20 == h.versnr, "Section 0 version number should be 20"
assert 20 == h.protnr, "Section 0 protocol number should be 20"
assert h.reserved
def test_section0():
scp = read_scp()
s0 = scp.section(0)
assert s0
for i in range (1,8):
assert s0.has_section(i)
assert not s0.has_section(12)
p1 = s0.pointer_for_section(1)
assert p1
assert p1.section_has_data()
def test_section1():
scp = read_scp()
s1 = scp.section(1)
assert s1
assert 12 == len(s1.tags), "Section 1 should have 12 tags"
assert 152 == s1.datalen
def test_section1_tags():
scp = read_scp()
s1 = scp.section(1)
f = Section1TagsFormatter(s1.tags)
assert 0 == s1.tags[0].tag
assert 6 == s1.tags[0].len
assert 12 == len(s1.tags)
assert "Clark" == f.format_tag(0)
assert "SBJ-123" == f.format_tag(2)
assert "Male" == PatientSexFormatter(f.tag_data(8)).text
assert "Caucasian" == PatientRaceFormatter(f.tag_data(9)).text
assert 2 == s1.tags[1].tag
assert 8 == s1.tags[1].len
def test_section2():
scp = read_scp()
s = scp.section(2)
assert s.p.section_has_data()
assert s.h.crc == 22179
assert 19999 == s.nr_huffman_tables, "Section 2 (Nr of Huffman tables) should be 19999"
def test_section3():
scp = read_scp()
s3 = scp.section(3)
assert s3
assert s3.p.section_has_data()
assert s3.h.crc == 45638
assert 12 == s3.nrleads
def test_section4():
scp = read_scp()
s = scp.section(4)
assert s.h.crc == 4777
assert s.ref_beat_type_len == 1198
def test_section6():
scp = read_scp()
s = scp.section(6)
assert s.h.crc == 61490
assert s.h.len == 30084
assert s.avm == 2500
assert s.sample_time_interval == 2000
assert len(s.nr_bytes_for_leads) == 12
def test_section7():
scp = read_scp()
s = scp.section(7)
assert s.h.crc == 26535
assert s.h.len == 242
assert s.reference_count == 13
def read_scp():
fr = FileReader('example/example.scp')
scpReader = ScpReader(fr)
scp = scpReader.read_scp()
scpReader.close()
return scp