Skip to content

Commit

Permalink
improvements to tests remove cache clearing (no longer needed) and cl…
Browse files Browse the repository at this point in the history
…ose all test data files after reading to avoid warnings
  • Loading branch information
locsmith committed Apr 18, 2024
1 parent 0eb656e commit 7b4d46e
Show file tree
Hide file tree
Showing 40 changed files with 243 additions and 352 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ lines marked with '!x' are current priorities
* Fasta export - done
* xEasy shifts - done
release - done
test_filter not committed
32 changes: 13 additions & 19 deletions src/nef_pipelines/tests/chains/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from nef_pipelines.lib.test_lib import (
assert_lines_match,
isolate_frame,
path_in_test_data,
read_test_data,
run_and_report,
)
from nef_pipelines.tools.chains.clone import clone
Expand All @@ -13,13 +13,13 @@
app = typer.Typer()
app.command()(clone)

INPUT_3AA_NEF = read_test_data("3aa.nef", __file__)

# noinspection PyUnusedLocal
def test_clone_basic(clear_cache):

INPUT = open(path_in_test_data(__file__, "3aa.nef")).read()
# noinspection PyUnusedLocal
def test_clone_basic():

result = run_and_report(app, ["A", "2"], input=INPUT)
result = run_and_report(app, ["A", "2"], input=INPUT_3AA_NEF)

EXPECTED = """\
save_nef_molecular_system
Expand Down Expand Up @@ -54,33 +54,27 @@ def test_clone_basic(clear_cache):


# noinspection PyUnusedLocal
def test_bad_count(clear_cache):
def test_bad_count():

INPUT = open(path_in_test_data(__file__, "3aa.nef")).read()

result = run_and_report(app, ["A", "0"], input=INPUT, expected_exit_code=1)
result = run_and_report(app, ["A", "0"], input=INPUT_3AA_NEF, expected_exit_code=1)

assert result.exit_code == 1

assert "clone count must be > 0" in result.stdout


# noinspection PyUnusedLocal
def test_bad_target(clear_cache):

INPUT = open(path_in_test_data(__file__, "3aa.nef")).read()
def test_bad_target():

result = run_and_report(app, ["B", "1"], input=INPUT, expected_exit_code=1)
result = run_and_report(app, ["B", "1"], input=INPUT_3AA_NEF, expected_exit_code=1)

assert "couldn't find target chain B" in result.stdout


# noinspection PyUnusedLocal
def test_custom_chains(clear_cache):

INPUT = open(path_in_test_data(__file__, "3aa.nef")).read()
def test_custom_chains():

result = run_and_report(app, ["A", "2", "--chains", "D,E"], input=INPUT)
result = run_and_report(app, ["A", "2", "--chains", "D,E"], input=INPUT_3AA_NEF)

EXPECTED = """\
save_nef_molecular_system
Expand Down Expand Up @@ -115,9 +109,9 @@ def test_custom_chains(clear_cache):


# noinspection PyUnusedLocal
def test_clone_chain_clash(clear_cache):
def test_clone_chain_clash():

INPUT = open(path_in_test_data(__file__, "3aa_x3.nef")).read()
INPUT = read_test_data("3aa_x3.nef", __file__)

result = run_and_report(app, ["A", "2"], input=INPUT)

Expand Down
8 changes: 4 additions & 4 deletions src/nef_pipelines/tests/chains/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from nef_pipelines.lib.test_lib import (
assert_lines_match,
path_in_test_data,
read_test_data,
run_and_report,
)
from nef_pipelines.tools.chains.list import list as list_app
Expand All @@ -12,11 +12,11 @@


# noinspection PyUnusedLocal
def test_frame_basic(clear_cache):
def test_frame_basic():

path = path_in_test_data(__file__, "multi_chain.nef")
input_data = read_test_data("multi_chain.nef", __file__)

result = run_and_report(app, [], input=open(path).read())
result = run_and_report(app, [], input=input_data)

EXPECTED = "A B C"

Expand Down
35 changes: 18 additions & 17 deletions src/nef_pipelines/tests/chains/test_rename.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import typer
from pytest import fixture
from typer.testing import CliRunner

from nef_pipelines.lib.test_lib import (
assert_lines_match,
path_in_test_data,
read_test_data,
run_and_report,
)
from nef_pipelines.tools.chains.rename import rename
Expand All @@ -17,12 +18,17 @@
RENAME_CHAINS_A_E = ["A", "E"]


@fixture
def INPUT_MULTI_CHAIN_SHIFTS_NEF():
return read_test_data("multi_chain_shifts.nef", __file__)


# noinspection PyUnusedLocal
def test_rename_basic(clear_cache):
def test_rename_basic():

path = path_in_test_data(__file__, "multi_chain.nef")
INPUT = read_test_data("multi_chain.nef", __file__)

result = run_and_report(app, [*RENAME_CHAINS_B_D], input=open(path))
result = run_and_report(app, [*RENAME_CHAINS_B_D], input=INPUT)

if result.exit_code != 0:
print("INFO: stdout from failed read:\n", result.stdout)
Expand Down Expand Up @@ -65,11 +71,11 @@ def test_rename_basic(clear_cache):


# noinspection PyUnusedLocal
def test_rename_multi_frame(clear_cache):
def test_rename_multi_frame(INPUT_MULTI_CHAIN_SHIFTS_NEF):

path = path_in_test_data(__file__, "multi_chain_shifts.nef")

result = run_and_report(app, [*RENAME_CHAINS_A_E], input=open(path))
result = run_and_report(
app, [*RENAME_CHAINS_A_E], input=INPUT_MULTI_CHAIN_SHIFTS_NEF
)

if result.exit_code != 0:
print("INFO: stdout from failed read:\n", result.stdout)
Expand Down Expand Up @@ -140,12 +146,10 @@ def test_rename_multi_frame(clear_cache):


# noinspection PyUnusedLocal
def test_rename_select_frame_by_name(clear_cache):

path = path_in_test_data(__file__, "multi_chain_shifts.nef")
def test_rename_select_frame_by_name(INPUT_MULTI_CHAIN_SHIFTS_NEF):

result = run_and_report(
app, ["--frame", "test", *RENAME_CHAINS_A_E], input=open(path)
app, ["--frame", "test", *RENAME_CHAINS_A_E], input=INPUT_MULTI_CHAIN_SHIFTS_NEF
)

if result.exit_code != 0:
Expand Down Expand Up @@ -213,14 +217,11 @@ def test_rename_select_frame_by_name(clear_cache):


# noinspection PyUnusedLocal
def test_rename_select_frame_by_category(clear_cache):

path = path_in_test_data(__file__, "multi_chain_shifts.nef")
input = open(path).read()
def test_rename_select_frame_by_category(INPUT_MULTI_CHAIN_SHIFTS_NEF):

command = [*RENAME_CHAINS_A_E, "--frame", "mol", "--selector-type", "category"]

result = run_and_report(app, command, input=input)
result = run_and_report(app, command, input=INPUT_MULTI_CHAIN_SHIFTS_NEF)

if result.exit_code != 0:
print("INFO: stdout from failed read:\n", result.stdout)
Expand Down
22 changes: 0 additions & 22 deletions src/nef_pipelines/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,6 @@ def fixed_seed():
seed(42)


@pytest.fixture
def clear_cache():
"""
clear the lru cache used by lib.util cached_stdin
see https://stackoverflow.com/questions/40273767/clear-all-lru-cache-in-python
"""
import functools
import gc

gc.collect()
wrappers = []
for elem in gc.get_objects():
try:
if isinstance(elem, functools._lru_cache_wrapper):
wrappers.append(elem)
except ReferenceError:
pass

for wrapper in wrappers:
wrapper.cache_clear()


def pytest_configure(config):
from nef_pipelines.main import create_nef_app

Expand Down
21 changes: 11 additions & 10 deletions src/nef_pipelines/tests/csv/test_import_rdcs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import typer
from pytest import fixture

from nef_pipelines.lib.test_lib import (
assert_lines_match,
isolate_frame,
path_in_test_data,
read_test_data,
run_and_report,
)
from nef_pipelines.transcoders.csv.importers.rdcs import rdcs
Expand All @@ -12,15 +14,17 @@
app.command()(rdcs)


@fixture
def INPUT_3A_AB_NEF():
return read_test_data("3a_ab.neff", __file__)


# noinspection PyUnusedLocal
def test_short_csv():
sequence_path = path_in_test_data(__file__, "3a_ab.neff")
def test_short_csv(INPUT_3A_AB_NEF):
csv_path = path_in_test_data(__file__, "short.csv")

nef_sequence = open(sequence_path, "r").read()

args = [csv_path, "--chain-code", "AAAA"]
result = run_and_report(app, args, input=nef_sequence)
result = run_and_report(app, args, input=INPUT_3A_AB_NEF)

EXPECTED = """\
save_nef_rdc_restraint_list_rdcs
Expand Down Expand Up @@ -71,14 +75,11 @@ def test_short_csv():
assert_lines_match(EXPECTED, result)


def test_short_complete_csv():
sequence_path = path_in_test_data(__file__, "3a_ab.neff")
def test_short_complete_csv(INPUT_3A_AB_NEF):
csv_path = path_in_test_data(__file__, "short_complete.csv")

nef_sequence = open(sequence_path, "r").read()

args = [csv_path]
result = run_and_report(app, args, input=nef_sequence)
result = run_and_report(app, args, input=INPUT_3A_AB_NEF)

EXPECTED = """\
save_nef_rdc_restraint_list_rdcs
Expand Down
3 changes: 2 additions & 1 deletion src/nef_pipelines/tests/echidna/test_import_peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
isolate_frame,
isolate_loop,
path_in_test_data,
read_test_data,
run_and_report,
)
from nef_pipelines.transcoders.echidna.importers.peaks import peaks
Expand Down Expand Up @@ -78,7 +79,7 @@ def test_basic():

path = path_in_test_data(__file__, "echidna_peaks.txt")

data_sequence = open(path_in_test_data(__file__, "echidna_sequence.nef")).read()
data_sequence = read_test_data("echidna_sequence.nef", __file__)

result = run_and_report(app, [path], input=data_sequence)

Expand Down
20 changes: 7 additions & 13 deletions src/nef_pipelines/tests/frames/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from nef_pipelines.lib.test_lib import (
assert_lines_match,
path_in_test_data,
read_test_data,
run_and_report,
)
from nef_pipelines.tools.frames.delete import delete
Expand Down Expand Up @@ -44,15 +44,13 @@
save_
"""

INPUT_PALES_TEST_1_NEF = read_test_data("pales_test_1.nef", __file__)

# noinspection PyUnusedLocal
def test_delete_type(clear_cache):

path = path_in_test_data(__file__, "pales_test_1.nef")

input_stream = open(path).read()
# noinspection PyUnusedLocal
def test_delete_type():

result = run_and_report(app, ["-c", "mol"], input=input_stream)
result = run_and_report(app, ["-c", "mol"], input=INPUT_PALES_TEST_1_NEF)

assert_lines_match(EXPECTED_DELETE_CATEGORY, result.stdout)

Expand Down Expand Up @@ -85,12 +83,8 @@ def test_delete_type(clear_cache):


# noinspection PyUnusedLocal
def test_delete_name(clear_cache):

path = path_in_test_data(__file__, "pales_test_1.nef")

input_stream = open(path).read()
def test_delete_name():

result = run_and_report(app, ["test_1"], input=input_stream)
result = run_and_report(app, ["test_1"], input=INPUT_PALES_TEST_1_NEF)

assert_lines_match(EXPECTED_DELETE_NAME, result.stdout)
Loading

0 comments on commit 7b4d46e

Please sign in to comment.