Skip to content

Commit

Permalink
added snapshot warning checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sellth committed Jan 16, 2024
1 parent 2cefe18 commit 5bdf735
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 9 deletions.
86 changes: 86 additions & 0 deletions tests/__snapshots__/test_parse_study.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# serializer version: 1
# name: test_study_reader_minimal_study
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:
''',
])
# ---
# name: test_study_reader_minimal_study_iostring
list([
'''
Investigation with only one study contains metadata:
ID: i_minimal
Title: Minimal Investigation
Path: <no file>
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:
''',
])
# ---
# name: test_study_reader_minimal_study_iostring2
list([
'''
Investigation with only one study contains metadata:
ID: i_minimal
Title: Minimal Investigation
Path: <no file>
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:
''',
])
# ---
# name: test_study_reader_small_study
list([
'''
Investigation with only one study contains metadata:
ID: i_small
Title: Small Investigation
Path: i_small.txt
Submission Date:
Public Release Date: None
Prefer recording metadata in the study section.
''',
'''
Assay without platform:
Path: a_small.txt
Measurement Type: exome sequencing assay
Technology Type: nucleotide sequencing
Technology Platform:
''',
])
# ---
# name: test_study_reader_small_study.1
list([
"Found annotated material/file without name: Material(type='Sample Name', unique_name='S1-Empty Sample Name-13-5', name='', extract_label=None, characteristics=(Characteristics(name='status', value=['1'], unit=None),), comments=(), factor_values=(FactorValue(name='treatment', value=[''], unit=None),), material_type=None, headers=['Sample Name', 'Characteristics[status]', 'Factor Value[treatment]'])",
])
# ---
20 changes: 11 additions & 9 deletions tests/test_parse_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import os

import pytest
from syrupy.assertion import SnapshotAssertion
from typing import Iterator, TextIO

from altamisa.constants import table_headers
from altamisa.exceptions import IsaWarning
Expand Down Expand Up @@ -69,7 +71,7 @@ def test_study_row_reader_minimal_study(minimal_investigation_file, minimal_stud
assert expected == first_row[2]


def test_study_reader_minimal_study(minimal_investigation_file, minimal_study_file):
def test_study_reader_minimal_study(minimal_investigation_file, minimal_study_file, snapshot: SnapshotAssertion):
"""Use ``StudyReader`` to read in minimal study file.
Using the ``StudyReader`` instead of the ``StudyRowReader`` gives us
Expand All @@ -81,7 +83,7 @@ def test_study_reader_minimal_study(minimal_investigation_file, minimal_study_fi
InvestigationValidator(investigation).validate()

# Check warnings
assert 2 == len(record)
assert snapshot == [str(r.message) for r in record]

# Create new row reader and check read headers
reader = StudyReader.from_stream("S1", minimal_study_file)
Expand Down Expand Up @@ -318,15 +320,15 @@ def test_study_row_reader_small_study(small_investigation_file, small_study_file
assert expected == third_row[2]


def test_study_reader_small_study(small_investigation_file, small_study_file):
def test_study_reader_small_study(small_investigation_file, small_study_file, snapshot: SnapshotAssertion):
"""Use ``StudyReader`` to read in small study file."""
# Load investigation (tested elsewhere)
with pytest.warns(IsaWarning) as record:
investigation = InvestigationReader.from_stream(small_investigation_file).read()
InvestigationValidator(investigation).validate()

# Check warnings
assert 2 == len(record)
assert snapshot == [str(r.message) for r in record]

# Create new row reader and check read headers
reader = StudyReader.from_stream("S1", small_study_file)
Expand All @@ -337,7 +339,7 @@ def test_study_reader_small_study(small_investigation_file, small_study_file):
with pytest.warns(IsaWarning) as record:
StudyValidator(investigation, investigation.studies[0], study).validate()
# Check warnings
assert 1 == len(record)
assert snapshot == [str(r.message) for r in record]

# Check results
assert os.path.normpath(str(study.file)).endswith(os.path.normpath("data/i_small/s_small.txt"))
Expand Down Expand Up @@ -559,15 +561,15 @@ def test_study_reader_small_study(small_investigation_file, small_study_file):
assert expected == study.arcs


def test_study_reader_minimal_study_iostring(minimal_investigation_file, minimal_study_file):
def test_study_reader_minimal_study_iostring(minimal_investigation_file, minimal_study_file, snapshot: SnapshotAssertion):
# Load investigation (tested elsewhere)
stringio = io.StringIO(minimal_investigation_file.read())
investigation = InvestigationReader.from_stream(stringio).read()
with pytest.warns(IsaWarning) as record:
InvestigationValidator(investigation).validate()

# Check warnings
assert 2 == len(record)
assert snapshot == [str(r.message) for r in record]

# Create new study reader and read from StringIO with original filename indicated
stringio = io.StringIO(minimal_study_file.read())
Expand All @@ -588,15 +590,15 @@ def test_study_reader_minimal_study_iostring(minimal_investigation_file, minimal
assert 2 == len(study.arcs)


def test_study_reader_minimal_study_iostring2(minimal_investigation_file, minimal_study_file):
def test_study_reader_minimal_study_iostring2(minimal_investigation_file, minimal_study_file, snapshot: SnapshotAssertion):
# Load investigation (tested elsewhere)
stringio = io.StringIO(minimal_investigation_file.read())
investigation = InvestigationReader.from_stream(stringio).read()
with pytest.warns(IsaWarning) as record:
InvestigationValidator(investigation).validate()

# Check warnings
assert 2 == len(record)
assert snapshot == [str(r.message) for r in record]

# Create new study reader and read from StringIO with no filename indicated
stringio = io.StringIO(minimal_study_file.read())
Expand Down

0 comments on commit 5bdf735

Please sign in to comment.