Skip to content

Commit

Permalink
Merge pull request #8 from vistalab-technion/pytest8-fix-fixtures
Browse files Browse the repository at this point in the history
Pytest8 fix fixtures
  • Loading branch information
avivrosenberg authored Jun 2, 2024
2 parents 59be0e0 + 0544004 commit 9e9d018
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
6 changes: 4 additions & 2 deletions tests/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def _random_pdb_id(id_type="plain", min_chain_len=1, max_chain_len=3) -> str:


class TestSplitID:
def setup(self):
@pytest.fixture(autouse=True)
def setup_fixture(self):
self.n = 100

def test_split_no_chain(self):
Expand Down Expand Up @@ -77,7 +78,8 @@ def test_split_id_when_entity_given(self):


class TestSplitIDWithEntity:
def setup(self):
@pytest.fixture(autouse=True)
def setup_fixture(self):
self.n = 100

def test_split_base_only(self):
Expand Down
28 changes: 15 additions & 13 deletions tests/test_unp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,33 @@
@pytest.mark.skipif(NO_INTERNET, reason="Needs internet")
class TestUNPDownload:
@classmethod
def setup_class(cls):
cls.TEMP_PATH = tests.get_tmp_path("data/unp")
@pytest.fixture(scope="class")
def unp_dir(cls):
return tests.get_tmp_path("data/unp")

def test_unp_record(self):
def test_unp_record(self, unp_dir):
test_id = "P00720"
unp_rec = unp.unp_record(test_id, unp_dir=self.TEMP_PATH)
unp_rec = unp.unp_record(test_id, unp_dir=unp_dir)
assert unp_rec.sequence_length == 164

def test_unp_download(self):
def test_unp_download(self, unp_dir):
test_id = "P42212"
path = unp.unp_download(test_id, unp_dir=self.TEMP_PATH)
assert path == self.TEMP_PATH.joinpath(f"{test_id}.txt")
path = unp.unp_download(test_id, unp_dir=unp_dir)
assert path == unp_dir.joinpath(f"{test_id}.txt")

def test_unp_download_with_redirect(self):
def test_unp_download_with_redirect(self, unp_dir):
# This UNP id causes a redirect to a few replacement ids.
test_id = "P31217"
replacement_id = unp.unp_replacement_ids(test_id)[0]
assert replacement_id in ["P62707", "P62708", "P62709", "P62710"]

path = unp.unp_download(test_id, unp_dir=self.TEMP_PATH)
path = unp.unp_download(test_id, unp_dir=unp_dir)

assert path == self.TEMP_PATH.joinpath(f"{replacement_id}.txt")
assert path == unp_dir.joinpath(f"{replacement_id}.txt")

def test_unp_download_with_invalid_id(self):
def test_unp_download_with_invalid_id(self, unp_dir):
with pytest.raises(IOError, match="400"):
path = unp.unp_download("P000000", unp_dir=self.TEMP_PATH)
path = unp.unp_download("P000000", unp_dir=unp_dir)


class TestUNPRecord:
Expand Down Expand Up @@ -86,7 +87,8 @@ def test_ena_single_type(self):

@pytest.mark.skipif(NO_INTERNET, reason="Needs internet")
class TestPDBXRefs:
def setup(self):
@pytest.fixture(autouse=True)
def setup_fixture(self):
self.xrefs = unp.find_pdb_xrefs("P00720", method="x-ray")

def test_single_chain(self):
Expand Down

0 comments on commit 9e9d018

Please sign in to comment.