-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from astrofrog/path-args
- Loading branch information
Showing
2 changed files
with
34 additions
and
24 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
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 |
---|---|---|
@@ -1,26 +1,34 @@ | ||
import os | ||
import time | ||
|
||
import pytest | ||
|
||
from .._utils import import_file, write_if_different | ||
|
||
|
||
def test_import_file(tmp_path): | ||
filename = str(tmp_path / "spam.py") | ||
with open(filename, "w") as f: | ||
@pytest.mark.parametrize("path_type", ("str", "path")) | ||
def test_import_file(tmp_path, path_type): | ||
filepath = tmp_path / "spam.py" | ||
if path_type == "str": | ||
filepath = str(filepath) | ||
with open(filepath, "w") as f: | ||
f.write("magic = 12345") | ||
module = import_file(filename) | ||
module = import_file(filepath) | ||
assert module.magic == 12345 | ||
|
||
|
||
def test_write_if_different(tmp_path): | ||
filename = str(tmp_path / "test.txt") | ||
write_if_different(filename, b"abc") | ||
time1 = os.path.getmtime(filename) | ||
@pytest.mark.parametrize("path_type", ("str", "path")) | ||
def test_write_if_different(tmp_path, path_type): | ||
filepath = tmp_path / "test.txt" | ||
if path_type == "str": | ||
filepath = str(filepath) | ||
write_if_different(filepath, b"abc") | ||
time1 = os.path.getmtime(filepath) | ||
time.sleep(0.01) | ||
write_if_different(filename, b"abc") | ||
time2 = os.path.getmtime(filename) | ||
write_if_different(filepath, b"abc") | ||
time2 = os.path.getmtime(filepath) | ||
assert time2 == time1 | ||
time.sleep(0.01) | ||
write_if_different(filename, b"abcd") | ||
time3 = os.path.getmtime(filename) | ||
write_if_different(filepath, b"abcd") | ||
time3 = os.path.getmtime(filepath) | ||
assert time3 > time1 |