Skip to content

Commit

Permalink
tests: try to restructure tests so that windows won't fail
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-- committed Jul 29, 2020
1 parent f7d3535 commit 1951a56
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
9 changes: 6 additions & 3 deletions paquo/tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
@pytest.fixture(scope='module')
def image_entry(svs_small):
with tempfile.TemporaryDirectory(prefix='paquo-') as tmpdir:
qp = QuPathProject(tmpdir)
entry = qp.add_image(svs_small)
yield entry
with QuPathProject(tmpdir) as qp:
entry = qp.add_image(svs_small)
qp.save()
yield entry
del entry
del qp


def test_image_entry_return_hierarchy(image_entry):
Expand Down
36 changes: 27 additions & 9 deletions paquo/tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@
# noinspection PyPackageRequirements
import pytest

from paquo.classes import QuPathPathClass
from paquo.images import ImageProvider
from paquo.projects import QuPathProject


@pytest.fixture(scope='function')
def new_project():
def new_project_with_tmpdir():
with tempfile.TemporaryDirectory(prefix='paquo-') as tmpdir:
yield QuPathProject(tmpdir)
qp = QuPathProject(tmpdir)
yield qp, tmpdir
del qp


@pytest.fixture(scope='function')
def new_project(new_project_with_tmpdir):
yield new_project_with_tmpdir[0]


def test_project_instance():
Expand All @@ -31,11 +39,14 @@ def test_project_create_no_dir():
q.save()


def test_project_open_with_filename(new_project):
new_project.save()
# this points to path/project.qpproj
proj_fn = new_project.path
QuPathProject(proj_fn, create=False)
def test_project_open_with_filename():
with tempfile.TemporaryDirectory(prefix='paquo-') as tmpdir:
with QuPathProject(tmpdir, create=True) as qp:
qp.path_classes = [QuPathPathClass.create('abc')]
proj_fn = qp.path
del qp

QuPathProject(proj_fn, create=False)


def test_project_uri(new_project):
Expand Down Expand Up @@ -94,7 +105,9 @@ def test_project_save_image_data(new_project, svs_small):
assert (entry.entry_path / "data.qpdata").is_file()


def test_project_image_uri_update(new_project, svs_small):
def test_project_image_uri_update(new_project_with_tmpdir, svs_small):

new_project, tmpdir = new_project_with_tmpdir

with tempfile.TemporaryDirectory(prefix="paquo-") as tmp:
new_svs_small = Path(tmp) / svs_small.name
Expand All @@ -105,17 +118,22 @@ def test_project_image_uri_update(new_project, svs_small):
# test that entry can be read
assert entry.is_readable()
assert all(new_project.is_readable().values())
del entry

entry = new_project.images[0]
# tempdir is cleanup up, entry is not readable anymore
assert not entry.is_readable()
assert not any(new_project.is_readable().values())
old_uri = entry.uri
del entry

# mapping for uris
uri2uri = {
entry.uri: ImageProvider.uri_from_path(svs_small)
old_uri: ImageProvider.uri_from_path(svs_small)
}
new_project.update_image_paths(uri2uri=uri2uri)

entry = new_project.images[0]
# test that entry can be read
assert entry.is_readable()
assert all(new_project.is_readable().values())

0 comments on commit 1951a56

Please sign in to comment.