Skip to content

Commit

Permalink
Parametrized reading tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
smelandr committed Sep 22, 2017
1 parent c37f166 commit 296eb7f
Showing 1 changed file with 23 additions and 38 deletions.
61 changes: 23 additions & 38 deletions tests/test_reading.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,39 @@
import pytest
from nmrstarlib import nmrstarlib


def test_from_local_file():
starfile_generator = nmrstarlib.read_files("tests/example_data/NMRSTAR3/bmr18569.str",
"tests/example_data/NMRSTAR2/bmr18569.str")
@pytest.mark.parametrize("source", [
("tests/example_data/NMRSTAR3/bmr18569.str", "tests/example_data/NMRSTAR2/bmr18569.str")
])
def test_from_local_file(source):
starfile_generator = nmrstarlib.read_files(*source)
starfile1 = next(starfile_generator)
starfile2 = next(starfile_generator)
assert starfile1.bmrbid == "18569" and starfile2.bmrbid == "18569"


def test_from_bmrbid():
starfile_generator = nmrstarlib.read_files("18569")
starfile = next(starfile_generator)
assert starfile.bmrbid == "18569"


def test_from_bmrbids():
starfile_generator = nmrstarlib.read_files("15000", "18569")
@pytest.mark.parametrize("source", [
("15000", "18569")
])
def test_from_bmrbid(source):
starfile_generator = nmrstarlib.read_files(*source)
starfile1 = next(starfile_generator)
starfile2 = next(starfile_generator)
assert starfile1.bmrbid in ("15000", "18569") and starfile2.bmrbid in ("15000", "18569")


def test_from_directory():
starfile_generator = nmrstarlib.read_files("tests/example_data/NMRSTAR3/starfiles_directory",
"tests/example_data/NMRSTAR3/starfiles_directory")
starfiles_list = list(starfile_generator)
starfiles_ids_set = set(sf.bmrbid for sf in starfiles_list)
assert starfiles_ids_set == {"15000", "18569"}


def test_from_zip_archive():
starfile_generator = nmrstarlib.read_files("tests/example_data/NMRSTAR3/starfiles_archive.zip",
"tests/example_data/NMRSTAR2/starfiles_archive.zip")
starfiles_list = list(starfile_generator)
starfiles_ids_set = set(sf.bmrbid for sf in starfiles_list)
assert starfiles_ids_set == {"15000", "18569"}


def test_from_tar_gz_archive():
starfile_generator = nmrstarlib.read_files("tests/example_data/NMRSTAR3/starfiles_archive.tar.gz",
"tests/example_data/NMRSTAR2/starfiles_archive.tar.gz")
starfiles_list = list(starfile_generator)
starfiles_ids_set = set(sf.bmrbid for sf in starfiles_list)
assert starfiles_ids_set == {"15000", "18569"}


def test_from_tar_bz2_archive():
starfile_generator = nmrstarlib.read_files("tests/example_data/NMRSTAR3/starfiles_archive.tar.bz2",
"tests/example_data/NMRSTAR2/starfiles_archive.tar.bz2")
@pytest.mark.parametrize("source", [
"tests/example_data/NMRSTAR3/starfiles_directory",
"tests/example_data/NMRSTAR2/starfiles_directory",
"tests/example_data/NMRSTAR3/starfiles_archive.zip",
"tests/example_data/NMRSTAR2/starfiles_archive.zip",
"tests/example_data/NMRSTAR3/starfiles_archive.tar.gz",
"tests/example_data/NMRSTAR2/starfiles_archive.tar.gz",
"tests/example_data/NMRSTAR3/starfiles_archive.tar.bz2",
"tests/example_data/NMRSTAR2/starfiles_archive.tar.bz2"
])
def test_reading(source):
starfile_generator = nmrstarlib.read_files(source)
starfiles_list = list(starfile_generator)
starfiles_ids_set = set(sf.bmrbid for sf in starfiles_list)
assert starfiles_ids_set == {"15000", "18569"}

0 comments on commit 296eb7f

Please sign in to comment.