Skip to content

Commit

Permalink
Filesystem test: use tmp_path for writing files
Browse files Browse the repository at this point in the history
  • Loading branch information
dvicini authored and njroussel committed Aug 19, 2024
1 parent 780074d commit 20266a6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/core/tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def test02_path_to_string(variant_scalar_rgb):
path_here.__str__() + sep + "dir 1" + sep + "dir 2"


def test03_create_and_remove_directory(variant_scalar_rgb):
new_dir = path_here / fs.path("my_shiny_new_directory")
def test03_create_and_remove_directory(variant_scalar_rgb, tmp_path):
new_dir = fs.path(str(tmp_path)) / "my_shiny_new_directory"
assert fs.create_directory(new_dir)
assert fs.exists(new_dir)
assert fs.is_directory(new_dir)
Expand Down Expand Up @@ -131,11 +131,13 @@ def test09_system_specific_tests(variant_scalar_rgb):
assert fs.path('./hello').is_relative()


def test10_equivalence(variant_scalar_rgb):
p1 = fs.path('../my_directory')
def test10_equivalence(variant_scalar_rgb, tmp_path):
base_dir = fs.path(str(tmp_path)) / 'base_directory'
assert fs.create_directory(base_dir)
p1 = base_dir / fs.path('../my_directory')
assert fs.create_directory(p1)

p2 = fs.path('././../././my_directory')
p2 = base_dir / fs.path('././../././my_directory')
assert not p1 == p2
assert fs.equivalent(p1, p2)

Expand All @@ -146,8 +148,8 @@ def test11_implicit_string_cast(variant_scalar_rgb):
assert not fs.exists("some random" + sep + "path")


def test12_truncate_and_file_size(variant_scalar_rgb):
p = path_here / 'test_file_for_resize.txt'
def test12_truncate_and_file_size(variant_scalar_rgb, tmp_path):
p = fs.path(str(tmp_path)) / 'test_file_for_resize.txt'
open(str(p), 'a').close()
assert fs.resize_file(p, 42)
assert fs.file_size(p) == 42
Expand Down

0 comments on commit 20266a6

Please sign in to comment.