11
22from pathlib import Path
3+ from unittest .mock import patch
34
45import pytest
56from PyStemmusScope import utils
67
78# TODO add test for convert_to_lsm_coordinates
89
10+
911def test_to_absolute_path ():
1012 input_path = "~/nonexistent_file.txt"
1113 parsed = utils .to_absolute_path (input_path )
1214 expected = Path .home () / "nonexistent_file.txt"
1315 assert parsed == expected
1416
15-
16- def test_to_absolute_path_must_exist ():
17+ @ patch ( "PyStemmusScope.utils.os_name" )
18+ def test_to_absolute_path_must_exist (mocked_osname ):
1719 input_path = "~/nonexistent_file.txt"
20+ mocked_osname .return_value = "nt"
1821 with pytest .raises (FileNotFoundError ):
19- utils .to_absolute_path (input_path , must_exist = True )
22+ utils .to_absolute_path (input_path )
2023
2124
2225def test_to_absolute_path_with_absolute_input_and_parent (tmp_path ):
@@ -33,16 +36,24 @@ def test_to_absolute_path_with_relative_input_and_parent(tmp_path):
3336
3437
3538def test_to_absolute_path_with_relative_input_and_no_parent ():
36- input_path = "nonexistent_file.txt"
39+ input_path = "./input_dir"
40+
41+ # care for windows, see issue 22
42+ Path (input_path ).mkdir (exist_ok = True )
43+
3744 parsed = utils .to_absolute_path (input_path )
38- expected = Path .cwd () / "nonexistent_file.txt "
45+ expected = Path .cwd () / "input_dir "
3946 assert parsed == expected
4047
4148
4249def test_to_absolute_path_with_relative_input_and_relative_parent ():
43- input_path = "nonexistent_file.txt"
50+ input_path = "./input_dir"
51+
52+ # care for windows, see issue 22
53+ Path (input_path ).mkdir (exist_ok = True )
54+
4455 parsed = utils .to_absolute_path (input_path , parent = Path ("." ))
45- expected = Path .cwd () / "nonexistent_file.txt "
56+ expected = Path .cwd () / "input_dir "
4657 assert parsed == expected
4758
4859
0 commit comments