Skip to content

Commit

Permalink
test test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianegli committed Sep 12, 2022
1 parent cf73822 commit 9aa0d91
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/test_test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import tempfile
from pathlib import Path

import pytest

from .utils import set_wd, with_temporary_file, with_temporary_folder


def test_with_temporary_file():
@with_temporary_file
def tmp_file_exists(tmp_file):
assert Path(tmp_file.name).exists()

tmp_file_exists()


def test_does_not_exist_after():
tmp_file = with_temporary_file(lambda x: x.name)()
assert not Path(tmp_file).exists()


def test_with_temporary_folder():
@with_temporary_folder
def tmp_folder_exists(tmp_folder):
assert Path(tmp_folder).exists()

tmp_folder_exists()


def test_tmp_folder_does_not_exist_after():
tmp_folder = with_temporary_folder(lambda x: x)()
assert not Path(tmp_folder).exists()


def test_set_wd():

with tempfile.TemporaryDirectory() as tmpdirname:
with set_wd(tmpdirname):
context_wd = Path().resolve()
assert context_wd == Path(tmpdirname).resolve()
assert context_wd != Path().resolve()


def test_set_wd_revert_on_raise():
wd_before_context = Path().resolve()
with tempfile.TemporaryDirectory() as tmpdirname:
with pytest.raises(Exception):
with set_wd(tmpdirname):
raise Exception
assert wd_before_context == Path().resolve()

0 comments on commit 9aa0d91

Please sign in to comment.