Skip to content

Commit

Permalink
moved duplicate code in testing files to common import
Browse files Browse the repository at this point in the history
  • Loading branch information
gould-arthur committed Feb 23, 2024
1 parent 4f78f7a commit 263b139
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 47 deletions.
9 changes: 1 addition & 8 deletions pepmatch/tests/test_discontinuous_search.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
#!/usr/bin/env python3

import pytest
import pandas as pd
import pandas.testing as pdt
from pathlib import Path

from common_features import *
from pepmatch import Matcher


@pytest.fixture
def proteome_path() -> Path:
return Path(__file__).parent / 'data' / 'proteome.fasta'


@pytest.fixture
def expected_path() -> Path:
return Path(__file__).parent / 'data' / 'discontinuous_expected.csv'
Expand Down
19 changes: 1 addition & 18 deletions pepmatch/tests/test_mismatching.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
#!/usr/bin/env python3

import os
import pytest
import pandas as pd
import pandas.testing as pdt
from pathlib import Path

from common_features import *
from pepmatch import Preprocessor, Matcher


@pytest.fixture
def proteome_path() -> Path:
return Path(__file__).parent / 'data' / 'proteome.fasta'


@pytest.fixture
def query_path() -> Path:
return Path(__file__).parent / 'data' / 'mismatching_query.fasta'


@pytest.fixture
def expected_path() -> Path:
return Path(__file__).parent / 'data' / 'mismatching_expected.csv'


def test_mismatching(proteome_path, query_path, expected_path):
"""Test mismatching of query peptides to a proteome. The query is various peptides
with different mismatches searched in the Dugbe virus proteome (isolate ArD44313)."""
Expand Down
15 changes: 12 additions & 3 deletions pepmatch/tests/test_ouptput_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pepmatch.matcher import VALID_OUTPUT_FORMATS

@pytest.fixture
def match(proteome_path, query_path, expected_path):
def match(proteome_path, query_path):
return Matcher(
query=query_path,
proteome_file=proteome_path,
Expand All @@ -18,6 +18,8 @@ def match(proteome_path, query_path, expected_path):
output_format='csv'
)


# fixtures and supporting
@pytest.fixture
def simple_dataframe():
return DF(data={"col1" : [1, 2], "col2": [3, 4]})
Expand All @@ -29,7 +31,10 @@ def _creation_calls(_matcher, _path, _df):
_matcher.output_name = _path
_matcher._output_matches(_df)


# Actual tests
def test_local_creation(match, simple_dataframe):
"""Test creation given the local path"""
local_location = Path("local_result.csv")

_creation_calls(match, local_location, simple_dataframe)
Expand All @@ -39,6 +44,7 @@ def test_local_creation(match, simple_dataframe):


def test_relative_creation(match, simple_dataframe):
"""Tests for creation given a relative path"""
relative_location = Path(f"../PEPMatch/relative.csv")

_creation_calls(match, relative_location, simple_dataframe)
Expand All @@ -48,16 +54,19 @@ def test_relative_creation(match, simple_dataframe):


def test_absolute_creation(match, simple_dataframe):
"""Tests creation given an absolute path"""
absolute_location = Path("absolute.csv").absolute()

_creation_calls(match, absolute_location, simple_dataframe)

assert absolute_location.exists()
remove(absolute_location.__str__())

def test_type_creation(match, simple_dataframe):

# tests .csv, .tsv, and xlsx
def test_type_creation(match, simple_dataframe):
"""Tests Matcher's ability to convert all supported types
into the expected file's output and format
"""
for accepted_type in VALID_OUTPUT_FORMATS[1:]:
location = Path(f"test_output.{accepted_type}")
if location.exists():
Expand Down
19 changes: 1 addition & 18 deletions pepmatch/tests/test_parallel_match.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
#!/usr/bin/env python3

import os
import pytest
import pandas as pd
import pandas.testing as pdt
from pathlib import Path

from common_features import *
from pepmatch import Preprocessor, ParallelMatcher


@pytest.fixture
def proteome_path() -> Path:
return Path(__file__).parent / 'data' / 'proteome.fasta'


@pytest.fixture
def query_path() -> Path:
return Path(__file__).parent / 'data' / 'mismatching_query.fasta'


@pytest.fixture
def expected_path() -> Path:
return Path(__file__).parent / 'data' / 'mismatching_expected.csv'


def test_mismatching(proteome_path, query_path, expected_path):
"""Test mismatching of query peptides to a proteome. The query is various peptides
Expand Down

0 comments on commit 263b139

Please sign in to comment.