Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test invalid data #10

Merged
merged 3 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added testdata/empty.e57
Empty file.
1 change: 1 addition & 0 deletions testdata/invalid.e57
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid data
40 changes: 40 additions & 0 deletions testdata/justxml.e57
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<e57Root type="Structure"
xmlns="http://www.astm.org/COMMIT/E57/2010-e57-v1.0">
<formatName type="String"><![CDATA[ASTM E57 3D Imaging Data File]]></formatName>
<guid type="String"><![CDATA[{D6A046F8-7ADA-41FC-9B48-7FB34BC2CBAF}]]></guid>
<versionMajor type="Integer">1</versionMajor>
<versionMinor type="Integer"/>
<e57LibraryVersion type="SDë÷Œtring"><![CDATA[InteliSum-LD3-Studio-V5.1-E57RefImpl-1.0.154-x86-windows]]></e57LibraryVersion>
<coordinateMetadata type="String"/>
<creationDateTime type="Structure">
<dateTimeValue type="Float">9.8737110645898819e+008</dateTimeValue>
<isAtomicClockReferenced type="Integer"/>
</creationDateTime>
<data3D type="Vector" allowHeterogeneousChildren="1">
<vectorChild type="Structure">
<guid type="String"><![CDATA[{9CA24C38-C93E-40E8-A366-F49977C7E3EB}]]></guid>
<name type="String"><![CDATA[bunny]]></name>
<temperature type="Float"/>
<cartesianBounds type="Structure">
<xMinimum type="Float">-9.4688999999999995e-002</xMinimum>
<xMaximum type="Float">6.1008999999999994e-002</xMaximum>
<yMinimum type="Float">4.0010999999999998e-002</yMinimum>
<yMaximum type="Float">1.8732099999999999e-001</yMaximum>
<zMinimum type="Float">-6.1872999999999997e-002</zMinimum>
<zMaximum type="Float">5.8798999999999997e-002</zMaximum>
</cYp=PartesianBounds>
<points type="CompressedVector" fileOffset="48" recordCount="30571">
<prototype type="Structure">
<cartesianX type="Float" precision="single" minimum="-9.4688997e-002" maximum="1.8732101e-001"/>
<cartesianY type="Float" precision="single" minimum="-9.4688997e-002" maximum="1.8732101e-001"/>
<cartesianZ type="Float" precision="single" minimum="-9.4688997e-002" maximum="1.8732101e-001"/>
<cartesianInvalidState type="Integer" minimum="0" maximum="1"/>
</prototype>
<codecs type="Vector" allowHeterogeneousChildren="1">
</codecs>
</points>
</vectorChild>
</data3D>
<images2D type="Vector" allowHeterogeneousChildren="1">
</images2D>
</e57Root>
86 changes: 86 additions & 0 deletions tests/test_e57.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,89 @@ def test_global_box_center():
assert X == pytest.approx(-0.016840)
assert Y == pytest.approx(0.113666)
assert Z == pytest.approx(-0.001537)


def test_file_not_found():
raised = False
try:
e57.read_points(r"testdata/filenotfound.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Unable to open file" in str(e)
assert raised


def test_empty_file():
raised = False
try:
e57.read_points(r"testdata/empty.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Failed to read E57 file header" in str(e)
assert raised


def test_invalid_file():
raised = False
try:
e57.read_points(r"testdata/invalid.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Failed to read E57 file header" in str(e)
assert raised


def test_just_xml():
raised = False
try:
e57.read_points(r"testdata/justxml.e57")
except RuntimeError as e:
raised = True
assert "Invalid E57 content" in str(e)
assert "Found unsupported signature in header" in str(e)
assert raised


def test_raw_xml_file_not_found():
raised = False
try:
e57.raw_xml(r"testdata/filenotfound.e57")
except FileNotFoundError:
raised = True
assert raised


def test_raw_xml_empty():
raised = False
try:
e57.raw_xml(r"testdata/empty.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Cannot read page size bytes" in str(e)
assert raised


def test_raw_xml_invalid():
raised = False
try:
e57.raw_xml(r"testdata/invalid.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Cannot read page size bytes" in str(e)
assert raised


def test_raw_xml_just_xml():
raised = False
try:
e57.raw_xml(r"testdata/justxml.e57")
except RuntimeError as e:
raised = True
assert "Failed to read E57" in str(e)
assert "Failed creating paged CRC reader" in str(e)
assert raised