Skip to content

Commit 06b27ef

Browse files
authored
Merge pull request #10 from devdanzin/test_invalid_data
Test invalid data
2 parents 9c8d5ec + 1fb95d7 commit 06b27ef

4 files changed

Lines changed: 127 additions & 0 deletions

File tree

testdata/empty.e57

Whitespace-only changes.

testdata/invalid.e57

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Invalid data

testdata/justxml.e57

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<e57Root type="Structure"
2+
xmlns="http://www.astm.org/COMMIT/E57/2010-e57-v1.0">
3+
<formatName type="String"><![CDATA[ASTM E57 3D Imaging Data File]]></formatName>
4+
<guid type="String"><![CDATA[{D6A046F8-7ADA-41FC-9B48-7FB34BC2CBAF}]]></guid>
5+
<versionMajor type="Integer">1</versionMajor>
6+
<versionMinor type="Integer"/>
7+
<e57LibraryVersion type="SDë÷Œtring"><![CDATA[InteliSum-LD3-Studio-V5.1-E57RefImpl-1.0.154-x86-windows]]></e57LibraryVersion>
8+
<coordinateMetadata type="String"/>
9+
<creationDateTime type="Structure">
10+
<dateTimeValue type="Float">9.8737110645898819e+008</dateTimeValue>
11+
<isAtomicClockReferenced type="Integer"/>
12+
</creationDateTime>
13+
<data3D type="Vector" allowHeterogeneousChildren="1">
14+
<vectorChild type="Structure">
15+
<guid type="String"><![CDATA[{9CA24C38-C93E-40E8-A366-F49977C7E3EB}]]></guid>
16+
<name type="String"><![CDATA[bunny]]></name>
17+
<temperature type="Float"/>
18+
<cartesianBounds type="Structure">
19+
<xMinimum type="Float">-9.4688999999999995e-002</xMinimum>
20+
<xMaximum type="Float">6.1008999999999994e-002</xMaximum>
21+
<yMinimum type="Float">4.0010999999999998e-002</yMinimum>
22+
<yMaximum type="Float">1.8732099999999999e-001</yMaximum>
23+
<zMinimum type="Float">-6.1872999999999997e-002</zMinimum>
24+
<zMaximum type="Float">5.8798999999999997e-002</zMaximum>
25+
</cYp=PartesianBounds>
26+
<points type="CompressedVector" fileOffset="48" recordCount="30571">
27+
<prototype type="Structure">
28+
<cartesianX type="Float" precision="single" minimum="-9.4688997e-002" maximum="1.8732101e-001"/>
29+
<cartesianY type="Float" precision="single" minimum="-9.4688997e-002" maximum="1.8732101e-001"/>
30+
<cartesianZ type="Float" precision="single" minimum="-9.4688997e-002" maximum="1.8732101e-001"/>
31+
<cartesianInvalidState type="Integer" minimum="0" maximum="1"/>
32+
</prototype>
33+
<codecs type="Vector" allowHeterogeneousChildren="1">
34+
</codecs>
35+
</points>
36+
</vectorChild>
37+
</data3D>
38+
<images2D type="Vector" allowHeterogeneousChildren="1">
39+
</images2D>
40+
</e57Root>

tests/test_e57.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,89 @@ def test_global_box_center():
3333
assert X == pytest.approx(-0.016840)
3434
assert Y == pytest.approx(0.113666)
3535
assert Z == pytest.approx(-0.001537)
36+
37+
38+
def test_file_not_found():
39+
raised = False
40+
try:
41+
e57.read_points(r"testdata/filenotfound.e57")
42+
except RuntimeError as e:
43+
raised = True
44+
assert "Failed to read E57" in str(e)
45+
assert "Unable to open file" in str(e)
46+
assert raised
47+
48+
49+
def test_empty_file():
50+
raised = False
51+
try:
52+
e57.read_points(r"testdata/empty.e57")
53+
except RuntimeError as e:
54+
raised = True
55+
assert "Failed to read E57" in str(e)
56+
assert "Failed to read E57 file header" in str(e)
57+
assert raised
58+
59+
60+
def test_invalid_file():
61+
raised = False
62+
try:
63+
e57.read_points(r"testdata/invalid.e57")
64+
except RuntimeError as e:
65+
raised = True
66+
assert "Failed to read E57" in str(e)
67+
assert "Failed to read E57 file header" in str(e)
68+
assert raised
69+
70+
71+
def test_just_xml():
72+
raised = False
73+
try:
74+
e57.read_points(r"testdata/justxml.e57")
75+
except RuntimeError as e:
76+
raised = True
77+
assert "Invalid E57 content" in str(e)
78+
assert "Found unsupported signature in header" in str(e)
79+
assert raised
80+
81+
82+
def test_raw_xml_file_not_found():
83+
raised = False
84+
try:
85+
e57.raw_xml(r"testdata/filenotfound.e57")
86+
except FileNotFoundError:
87+
raised = True
88+
assert raised
89+
90+
91+
def test_raw_xml_empty():
92+
raised = False
93+
try:
94+
e57.raw_xml(r"testdata/empty.e57")
95+
except RuntimeError as e:
96+
raised = True
97+
assert "Failed to read E57" in str(e)
98+
assert "Cannot read page size bytes" in str(e)
99+
assert raised
100+
101+
102+
def test_raw_xml_invalid():
103+
raised = False
104+
try:
105+
e57.raw_xml(r"testdata/invalid.e57")
106+
except RuntimeError as e:
107+
raised = True
108+
assert "Failed to read E57" in str(e)
109+
assert "Cannot read page size bytes" in str(e)
110+
assert raised
111+
112+
113+
def test_raw_xml_just_xml():
114+
raised = False
115+
try:
116+
e57.raw_xml(r"testdata/justxml.e57")
117+
except RuntimeError as e:
118+
raised = True
119+
assert "Failed to read E57" in str(e)
120+
assert "Failed creating paged CRC reader" in str(e)
121+
assert raised

0 commit comments

Comments
 (0)