Passed
Push — master ( fc8ab8...cdc1b3 )
by Kent
01:23 queued 40s
created

test_append_curve_and_item()   A

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
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
test_dir = os.path.dirname(__file__)
12
13
egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)
14
stegfn = lambda vers, fn: os.path.join(
15
    os.path.dirname(__file__), "examples", vers, fn)
16
17
def test_keys_curve_mnemonics():
18
    l = lasio.read(egfn("sample.las"))
19
     # DEPT.M                      :  1  DEPTH
20
     # DT  .US/M               :  2  SONIC TRANSIT TIME
21
     # RHOB.K/M3                   :  3  BULK DENSITY
22
     # NPHI.V/V                    :  4   NEUTRON POROSITY
23
     # SFLU.OHMM                   :  5  RXO RESISTIVITY
24
     # SFLA.OHMM                   :  6  SHALLOW RESISTIVITY
25
     # ILM .OHMM                   :  7  MEDIUM RESISTIVITY
26
     # ILD .OHMM                   :  8  DEEP RESISTIVITY
27
    assert l.keys() == ['DEPT', 'DT', 'RHOB', 'NPHI', 'SFLU', 'SFLA', 'ILM', 'ILD']
28
29
def test_LASFile_getitem():
30
    l = lasio.read(egfn("sample.las"))
31
    assert np.all(l['DT'] == [123.45, 123.45, 123.45])
32
33
def test_LASFile_getitem_int():
34
    l = lasio.read(egfn("sample.las"))
35
    assert np.all(l[1] == [123.45, 123.45, 123.45])
36
37
def test_LASFile_getitem_int_negative():
38
    l = lasio.read(egfn("sample.las"))
39
    assert np.all(l[-2] == [110.2, 110.2, 110.2])
40
41
def test_data_array_slice():
42
    l = lasio.read(egfn("sample.las"))
43
    assert np.all(l[1] == l.data[:, 1])
44
45
def test_curves_attribute():
46
    l = lasio.read(egfn("sample.las"))
47
    assert isinstance(l.curves[1], las.CurveItem)
48
49
def test_get_curves_method():
50
    l = lasio.read(egfn("sample.las"))
51
    assert l.get_curve('DT') == l.curves[1]
52
53
def test_missing_lasfile_mnemonic():
54
    las = lasio.read(egfn('sample.las'))
55
    with pytest.raises(KeyError):
56
        las['blahblahblah']
57
58
def test_append_curve_and_item():
59
    las = lasio.LASFile()
60
    data = [1, 2, 3]
61
    las.append_curve('TEST1', data=data)
62
    las.append_curve_item(lasio.CurveItem('TEST2', data=data))
63
    assert (las['TEST1'] == las['TEST2']).all()