Completed
Push — master ( f72807...fedb5c )
by Kent
9s
created

test_version()   A

Complexity

Conditions 2

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
c 1
b 1
f 0
dl 0
loc 2
rs 10
1
import os, sys; sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
2
3
import fnmatch
4
5
import numpy as np
6
import pytest
7
8
import lasio
9
from lasio import read, las
10
11
import logging
12
13
logger = logging.getLogger(__name__)
14
15
test_dir = os.path.dirname(__file__)
16
17
egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)
18
stegfn = lambda vers, fn: os.path.join(
19
    os.path.dirname(__file__), "examples", vers, fn)
20
21
def test_version():
22
    assert '.' in lasio.__version__
23
24
def test_keys_curve_mnemonics():
25
    l = lasio.read(egfn("sample.las"))
26
     # DEPT.M                      :  1  DEPTH
27
     # DT  .US/M               :  2  SONIC TRANSIT TIME
28
     # RHOB.K/M3                   :  3  BULK DENSITY
29
     # NPHI.V/V                    :  4   NEUTRON POROSITY
30
     # SFLU.OHMM                   :  5  RXO RESISTIVITY
31
     # SFLA.OHMM                   :  6  SHALLOW RESISTIVITY
32
     # ILM .OHMM                   :  7  MEDIUM RESISTIVITY
33
     # ILD .OHMM                   :  8  DEEP RESISTIVITY
34
    assert l.keys() == ['DEPT', 'DT', 'RHOB', 'NPHI', 'SFLU', 'SFLA', 'ILM', 'ILD']
35
36
def test_LASFile_getitem():
37
    l = lasio.read(egfn("sample.las"))
38
    assert np.all(l['DT'] == [123.45, 123.45, 123.45])
39
40
def test_LASFile_getitem_int():
41
    l = lasio.read(egfn("sample.las"))
42
    assert np.all(l[1] == [123.45, 123.45, 123.45])
43
44
def test_LASFile_getitem_int_negative():
45
    l = lasio.read(egfn("sample.las"))
46
    assert np.all(l[-2] == [110.2, 110.2, 110.2])
47
48
def test_data_array_slice():
49
    l = lasio.read(egfn("sample.las"))
50
    assert np.all(l[1] == l.data[:, 1])
51
52
def test_curves_attribute():
53
    l = lasio.read(egfn("sample.las"))
54
    assert isinstance(l.curves[1], las.CurveItem)
55
56
def test_get_curves_method():
57
    l = lasio.read(egfn("sample.las"))
58
    assert l.get_curve('DT') == l.curves[1]
59
60
def test_missing_lasfile_mnemonic():
61
    las = lasio.read(egfn('sample.las'))
62
    with pytest.raises(KeyError):
63
        las['blahblahblah']
64
65
def test_append_curve_and_item():
66
    las = lasio.LASFile()
67
    data = [1, 2, 3]
68
    las.append_curve('TEST1', data=data)
69
    las.append_curve_item(lasio.CurveItem('TEST2', data=data))
70
    assert (las['TEST1'] == las['TEST2']).all()
71
72
def test_data_attr():
73
    las = lasio.LASFile()
74
    las.append_curve('TEST1', data=[1, 2, 3])
75
    las.append_curve_item(lasio.CurveItem('TEST2', data=[4, 5, 6]))
76
    las.append_curve('TEST3', data=[7, 8, 9])
77
    logger.debug('las.data = {}'.format(las.data))
78
    # the .all() method assumes these are numpy ndarrays; that should be the case.
79
    assert (las.data == np.asarray([[1, 4, 7], [2, 5, 8], [3, 6, 9]])).all()