-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf73822
commit 9aa0d91
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |