Skip to content

Commit

Permalink
Flake8 maintenance for test suite final set (#563)
Browse files Browse the repository at this point in the history
- tests/test_serialization.py
- tests/test_speed.py
- tests/test_stack_curves.py
- tests/test_version.py
- tests/test_wrapped.py
- tests/test_write.py

Test data in test_write.py has lines with trailing white space.
Test data in test_wrapped.py has lines with trailing white space and
long lines.
Flake8 should be configured to ignore those lines. Below is the
suggested configuration for a .flake8 file.

[flake8]
per-file-ignores =
    test_wrapped.py:W291,E501
    test_write.py:W291
  • Loading branch information
dcslagel committed Feb 28, 2023
1 parent 57839f0 commit aee63ef
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 78 deletions.
22 changes: 12 additions & 10 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import os, sys
import os
import pickle

sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
# 02-20-2023: dcs: leaving this commented out for now, in case it needs to be
# restored. Remove after 05-2023
# import sys
# sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

import fnmatch
from lasio import read

import numpy
import pytest
import pickle
test_dir = os.path.dirname(__file__)

from lasio import las, read, exceptions

def egfn(fn):
return os.path.join(test_dir, "examples", fn)

test_dir = os.path.dirname(__file__)

egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)
stegfn = lambda vers, fn: os.path.join(os.path.dirname(__file__), "examples", vers, fn)
def stegfn(vers, fn):
return os.path.join(test_dir, "examples", vers, fn)


def test_pickle_default_wb():
Expand Down
25 changes: 14 additions & 11 deletions tests/test_speed.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import os, sys

sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
import glob
import fnmatch
import traceback
import os
import logging

import numpy
import pytest

# 02-20-2023: dcs: leaving this commented out for now, in case it needs to be
# restored. Remove after 05-2023
# import sys
# sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

import lasio

test_dir = os.path.dirname(__file__)
logger = logging.getLogger(__name__)

egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)
stegfn = lambda vers, fn: os.path.join(os.path.dirname(__file__), "examples", vers, fn)

logger = logging.getLogger(__name__)
def egfn(fn):
return os.path.join(test_dir, "examples", fn)


def stegfn(vers, fn):
return os.path.join(test_dir, "examples", vers, fn)


def read_file():
las = lasio.read(stegfn("1.2", "sample_big.las"))
assert isinstance(las, lasio.LASFile)


def test_read_v12_sample_big(benchmark):
Expand Down
14 changes: 8 additions & 6 deletions tests/test_stack_curves.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import os, sys

sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

import os
import pytest
import numpy as np

# 02-20-2023: dcs: leaving this commented out for now, in case it needs to be
# restored. Remove after 05-2023
# import sys
# sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
import lasio

test_dir = os.path.dirname(__file__)

egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)

def egfn(fn):
return os.path.join(test_dir, "examples", fn)


def test_stack_curves_with_stub():
Expand Down
12 changes: 6 additions & 6 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# coding=utf-8

import os, sys

sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

import os
import re
# 02-20-2023: dcs: leaving this commented out for now, in case it needs to be
# restored. Remove after 05-2023
# import sys
# sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
import lasio.las_version

version_regex = re.compile(r"^\d+\.\d+")

import lasio.las_version


def test_non_existent_vcs_tool():
version_cmd = ["gt", "describe", "--tags", "--match", "v*"]
Expand Down
32 changes: 21 additions & 11 deletions tests/test_wrapped.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
import os, sys
import os

sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

from lasio import read
# 02-20-2023: dcs: leaving this commented out for now, in case it needs to be
# restored. Remove after 05-2023
# import sys
# sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

from lasio import read, LASFile
from lasio.reader import StringIO

egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)
stegfn = lambda vers, fn: os.path.join(os.path.dirname(__file__), "examples", vers, fn)
test_dir = os.path.dirname(__file__)


def egfn(fn):
return os.path.join(test_dir, "examples", fn)


def stegfn(vers, fn):
return os.path.join(test_dir, "examples", vers, fn)


def test_wrapped():
fn = egfn("1001178549.las")
l = read(fn)
las = read(fn)
assert isinstance(las, LASFile)


def test_write_wrapped():
fn = stegfn("1.2", "sample_wrapped.las")
l = read(fn)
las = read(fn)
s = StringIO()
l.write(s, version=2.0, wrap=True, fmt="%.5f")
las.write(s, version=2.0, wrap=True, fmt="%.5f")
s.seek(0)
assert (
s.read()
Expand Down Expand Up @@ -116,9 +126,9 @@ def test_write_wrapped():

def test_write_unwrapped():
fn = stegfn("1.2", "sample_wrapped.las")
l = read(fn)
las = read(fn)
s = StringIO()
l.write(s, version=2, wrap=False, fmt="%.5f")
las.write(s, version=2, wrap=False, fmt="%.5f")
s.seek(0)
assert (
s.read()
Expand Down
71 changes: 37 additions & 34 deletions tests/test_write.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import os, sys

sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

import pytest
import os
import sys
import numpy as np

# 02-20-2023: dcs: leaving this commented out for now, in case it needs to be
# restored. Remove after 05-2023
# import sys
# sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

import lasio
import lasio.examples
from lasio import read
from lasio.excel import ExcelConverter

from lasio.reader import StringIO

test_dir = os.path.dirname(__file__)

egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)

def egfn(fn):
return os.path.join(test_dir, "examples", fn)


def test_write_sect_widths_12(capsys):
Expand All @@ -31,18 +34,18 @@ def test_write_to_filename():


def test_write_sect_widths_12_curves():
l = read(egfn("sample_write_sect_widths_12.las"))
las = read(egfn("sample_write_sect_widths_12.las"))
s = StringIO()
l.write(s, version=1.2)
las.write(s, version=1.2)
for start in ("D.M ", "A.US/M ", "B.K/M3 ", "C.V/V "):
s.seek(0)
assert "\n" + start in s.read()


def test_write_sect_widths_20_narrow():
l = read(egfn("sample_write_sect_widths_20_narrow.las"))
las = read(egfn("sample_write_sect_widths_20_narrow.las"))
s = StringIO()
l.write(s, version=2)
las.write(s, version=2)
s.seek(0)
assert (
s.read()
Expand Down Expand Up @@ -92,9 +95,9 @@ def test_write_sect_widths_20_narrow():


def test_write_sect_widths_20_wide():
l = read(egfn("sample_write_sect_widths_20_wide.las"))
las = read(egfn("sample_write_sect_widths_20_wide.las"))
s = StringIO()
l.write(s, version=2)
las.write(s, version=2)
s.seek(0)
assert (
s.read()
Expand Down Expand Up @@ -144,17 +147,17 @@ def test_write_sect_widths_20_wide():


def test_write_sample_empty_params():
l = read(egfn("sample_write_empty_params.las"))
l.write(StringIO(), version=2)
las = read(egfn("sample_write_empty_params.las"))
las.write(StringIO(), version=2)


def test_df_curve_addition_on_export():
l = read(egfn("sample.las"))
df = l.df()
las = read(egfn("sample.las"))
df = las.df()
df["ILD_COND"] = 1000 / df.ILD
l.set_data_from_df(df, truncate=False)
las.set_data_from_df(df, truncate=False)
s = StringIO()
l.write(s, version=2, wrap=False, fmt="%.5f")
las.write(s, version=2, wrap=False, fmt="%.5f")
s.seek(0)
assert (
s.read()
Expand Down Expand Up @@ -204,24 +207,24 @@ def test_df_curve_addition_on_export():


def test_write_xlsx():
l = read(egfn("sample.las"))
e = ExcelConverter(l)
las = read(egfn("sample.las"))
e = ExcelConverter(las)
xlsxfn = "test.xlsx"
e.write(xlsxfn)
os.remove(xlsxfn)


def test_export_xlsx():
l = read(egfn("sample.las"))
las = read(egfn("sample.las"))
xlsxfn = "test2.xlsx"
l.to_excel(xlsxfn)
las.to_excel(xlsxfn)
os.remove(xlsxfn)


def test_multi_curve_mnemonics_rewrite():
l = read(egfn("sample_issue105_a.las"))
las = read(egfn("sample_issue105_a.las"))
s = StringIO()
l.write(s, version=2, wrap=False, fmt="%.5f")
las.write(s, version=2, wrap=False, fmt="%.5f")
s.seek(0)
assert (
s.read()
Expand Down Expand Up @@ -267,9 +270,9 @@ def test_multi_curve_mnemonics_rewrite():


def test_multi_curve_missing_mnemonics_rewrite():
l = read(egfn("sample_issue105_b.las"))
las = read(egfn("sample_issue105_b.las"))
s = StringIO()
l.write(s, version=2, wrap=False, fmt="%.5f")
las.write(s, version=2, wrap=False, fmt="%.5f")
s.seek(0)
assert (
s.read()
Expand Down Expand Up @@ -315,10 +318,10 @@ def test_multi_curve_missing_mnemonics_rewrite():


def test_write_units():
l = read(egfn("sample.las"))
l.curves[0].unit = "FT"
las = read(egfn("sample.las"))
las.curves[0].unit = "FT"
s = StringIO()
l.write(s, version=2, wrap=False, fmt="%.5f")
las.write(s, version=2, wrap=False, fmt="%.5f")
s.seek(0)
assert (
s.read()
Expand Down Expand Up @@ -422,17 +425,17 @@ def test_to_csv_specify_units():


def test_rename_and_write_curve_mnemonic():
l = read(egfn("sample.las"))
for curve in l.curves:
las = read(egfn("sample.las"))
for curve in las.curves:
if curve.mnemonic != "DEPT":
curve.mnemonic = "New_" + curve.mnemonic
for curve in l.curves:
for curve in las.curves:
print(
"mnemonic=%s original_mnemonic=%s"
% (curve.mnemonic, curve.original_mnemonic)
)
s = StringIO()
l.write(s, version=2)
las.write(s, version=2)
s.seek(0)
assert (
s.read()
Expand Down

0 comments on commit aee63ef

Please sign in to comment.