Skip to content

Commit

Permalink
chore: adding snapshot tests (#117)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Holtgrewe <manuel.holtgrewe@bih-charite.de>
  • Loading branch information
sellth and holtgrewe authored Jan 15, 2024
1 parent 57fb63d commit dcb8942
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
2 changes: 2 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ flake8 >=3.5.0
isort

pyright

syrupy
65 changes: 65 additions & 0 deletions tests/__snapshots__/test_apps.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# serializer version: 1
# name: test_isatab2isatab
list([
'''
Investigation with only one study contains metadata:
ID: i_minimal
Title: Minimal Investigation
Path: i_minimal.txt
Submission Date:
Public Release Date: None
Prefer recording metadata in the study section.
''',
'''
Assay without platform:
Path: a_minimal.txt
Measurement Type: exome sequencing assay
Technology Type: nucleotide sequencing
Technology Platform:
''',
'No reference headers available for section INVESTIGATION PUBLICATIONS. Applying default order.',
'No reference headers available for section INVESTIGATION CONTACTS. Applying default order.',
'No reference headers available for section STUDY DESIGN DESCRIPTORS. Applying default order.',
'No reference headers available for section STUDY PUBLICATIONS. Applying default order.',
'No reference headers available for section STUDY FACTORS. Applying default order.',
'No reference headers available for section STUDY CONTACTS. Applying default order.',
])
# ---
# name: test_isatab2isatab_input_is_output
'<Result IsaException("Can\'t output ISA-tab files to same directory as as input: /home/runner/work/altamisa/tests/data/i_minimal == /home/runner/work/altamisa/tests/data/i_minimal")>'
# ---
# name: test_isatab_validate
list([
'Incomplete ontology source; found: , Incomplete 1, 1, Incomplete 1, ()',
'Incomplete ontology source; found: Incomplete 2, , 2, Incomplete 2, ()',
'Ontology source name including whitespace(s); found: Incomplete 2, , 2, Incomplete 2, ()',
'Incomplete ontology source; found: Incomplete 3, Incomplete 3, , Incomplete 3, ()',
'Ontology source name including whitespace(s); found: Incomplete 3, Incomplete 3, , Incomplete 3, ()',
'Incomplete ontology source; found: Incomplete 4, Incomplete 4, 4, , ()',
'Ontology source name including whitespace(s); found: Incomplete 4, Incomplete 4, 4, , ()',
'''
Investigation with only one study contains metadata:
ID: i_warnings
Title: Investigation with Warnings
Path: i_warnings.txt
Submission Date:
Public Release Date: None
Prefer recording metadata in the study section.
''',
'Invalid mail address: invalid_mail',
'Invalid phone/fax number: CALL-ME',
'Invalid phone/fax number: FAX-ME',
'Invalid pubmed_id string: not-pubmed',
'Invalid doi string: not-a-doi',
'''
Assay without platform:
Path: a_warnings.txt
Measurement Type: exome sequencing assay
Technology Type: nucleotide sequencing
Technology Platform:
''',
'Assay path used more than once: a_warnings.txt',
"Found samples in assay 'a_warnings.txt' but not in parent study 's_warnings.txt':\\n0815-N2",
"Found samples in assay 'a_warnings.txt' but not in parent study 's_warnings.txt':\\n0815-N2",
])
# ---
15 changes: 9 additions & 6 deletions tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os.path

import pytest
from syrupy.assertion import SnapshotAssertion
from typer.testing import CliRunner

from altamisa.apps import isatab2dot, isatab2isatab, isatab_validate
Expand All @@ -12,18 +13,18 @@
runner = CliRunner()


def test_isatab_validate():
def test_isatab_validate(snapshot: SnapshotAssertion):
i_file = os.path.join(os.path.dirname(__file__), "data", "i_warnings", "i_warnings.txt")
argv = ["--input-investigation-file", i_file, "--show-duplicate-warnings"]

with pytest.warns(IsaWarning) as record:
result = runner.invoke(isatab_validate.app, argv)
assert result.exit_code == 0

assert 17 == len(record)
assert snapshot == [str(r.message) for r in record]


def test_isatab2isatab(tmpdir):
def test_isatab2isatab(tmpdir, snapshot: SnapshotAssertion):
i_file = os.path.join(os.path.dirname(__file__), "data", "i_minimal", "i_minimal.txt")
argv = [
"--input-investigation-file",
Expand All @@ -38,10 +39,10 @@ def test_isatab2isatab(tmpdir):
result = runner.invoke(isatab2isatab.app, argv)
assert result.exit_code == 0

assert 8 == len(record)
assert snapshot == [str(r.message) for r in record]


def test_isatab2isatab_input_is_output(tmpdir):
def test_isatab2isatab_input_is_output(tmpdir, snapshot: SnapshotAssertion):
i_file = os.path.join(os.path.dirname(__file__), "data", "i_minimal", "i_minimal.txt")
argv = [
"--input-investigation-file",
Expand All @@ -54,7 +55,9 @@ def test_isatab2isatab_input_is_output(tmpdir):

result = runner.invoke(isatab2isatab.app, argv)
assert result.exit_code == 1
assert "Can't output ISA-tab files to same directory as as input" in str(result)
assert snapshot == str(result).replace(
os.path.dirname(__file__), "/home/runner/work/altamisa/tests"
)


def test_isatab2dot(tmpdir):
Expand Down

0 comments on commit dcb8942

Please sign in to comment.