import os
import tempfile
import numpy as np
import pytest
import las_rs
test_dir = os.path.dirname(__file__)
def fixture(*parts):
return os.path.join(test_dir, "fixtures", *parts)
_GOOD_LAS = """\
~VERSION INFORMATION
VERS. 2.0 : LAS VERSION 2.0
WRAP. NO : ONE LINE PER DEPTH STEP
~WELL INFORMATION
STRT.M 100.0 : START DEPTH
STOP.M 102.0 : STOP DEPTH
STEP.M 1.0 : STEP VALUE
NULL. -999.25 : NULL VALUE
COMP. ERRTEST DRILLING : COMPANY
WELL. ERRTEST-1 #1 : WELL NAME
~CURVE INFORMATION
DEPT.M : MEASURED DEPTH
GR .GAPI : GAMMA RAY
~ASCII LOG DATA
100.0 41.22
101.0 53.77
102.0 38.95
"""
_MALFORMED_HEADER_LAS = """\
~VERSION INFORMATION
VERS 2.0 LAS VERSION 2.0 NO COLON SEPARATOR
~WELL INFORMATION
STRT.M 100.0 : START
STOP.M 102.0 : STOP
STEP.M 1.0 : STEP
NULL. -999.25 : NULL
~CURVE INFORMATION
DEPT.M : DEPTH
~ASCII LOG DATA
100.0
101.0
102.0
"""
_NO_SECTIONS_CONTENT = """\
This is not a LAS file at all.
It has no tilde-prefixed section markers.
"""
@pytest.mark.xfail(reason="not yet implemented")
def test_las_data_error_on_reshape():
las = las_rs.read(_GOOD_LAS)
bad_data = np.array([100.0, 41.0, 101.0, 53.0, 102.0]) with pytest.raises((las_rs.exceptions.LASDataError, las_rs.LASDataError, Exception)):
las.set_data(bad_data)
@pytest.mark.xfail(reason="not yet implemented")
def test_las_unknown_unit_error():
unknown_unit_las = """\
~VERSION INFORMATION
VERS. 2.0 : LAS VERSION 2.0
WRAP. NO : ONE LINE PER DEPTH STEP
~WELL INFORMATION
STRT.FATHOM 10.0 : START DEPTH
STOP.FATHOM 12.0 : STOP DEPTH
STEP.FATHOM 1.0 : STEP VALUE
NULL. -999.25 : NULL VALUE
COMP. ERRTEST LTD : COMPANY
WELL. ERRTEST-2 #2 : WELL NAME
~CURVE INFORMATION
DEPT.FATHOM : MEASURED DEPTH
GR .GAPI : GAMMA RAY
~ASCII LOG DATA
10.0 29.11
11.0 35.44
12.0 27.88
"""
las = las_rs.read(unknown_unit_las)
with pytest.raises(
(las_rs.exceptions.LASUnknownUnitError, las_rs.LASUnknownUnitError, Exception)
):
_ = las.depth_m
@pytest.mark.xfail(reason="not yet implemented")
def test_las_data_error_is_exception():
exc_class = las_rs.exceptions.LASDataError
assert issubclass(exc_class, Exception)
@pytest.mark.xfail(reason="not yet implemented")
def test_las_header_error_is_exception():
exc_class = las_rs.exceptions.LASHeaderError
assert issubclass(exc_class, Exception)
@pytest.mark.xfail(reason="not yet implemented")
def test_las_unknown_unit_error_is_exception():
exc_class = las_rs.exceptions.LASUnknownUnitError
assert issubclass(exc_class, Exception)
@pytest.mark.xfail(reason="not yet implemented")
def test_keyerror_on_no_sections():
with pytest.raises(KeyError):
las_rs.read(_NO_SECTIONS_CONTENT)
@pytest.mark.xfail(reason="not yet implemented")
def test_ioerror_on_lidar(tmp_path):
lidar_path = tmp_path / "fake_lidar_errtest.las"
lidar_path.write_bytes(b"LASF" + b"\x00" * 128)
with pytest.raises(IOError):
las_rs.read(str(lidar_path))