Skip to content

Commit 84df0f7

Browse files
TST: add test for find_file utility function
1 parent ce38737 commit 84df0f7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

pydm/tests/utilities/test_utilities.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from qtpy import QtWidgets
77

8-
from ...utilities import find_display_in_path, is_pydm_app, is_qt_designer, log_failures, path_info, which
8+
from ...utilities import find_display_in_path, find_file, is_pydm_app, is_qt_designer, log_failures, path_info, which
99

1010
logger = logging.getLogger(__name__)
1111

@@ -51,6 +51,27 @@ def test_find_display_in_path():
5151
assert disp_path == expected
5252

5353

54+
def test_find_file():
55+
parent_lvl1 = tempfile.mkdtemp()
56+
parent_lvl2 = tempfile.mkdtemp(dir=parent_lvl1)
57+
temp, file_path = tempfile.mkstemp(suffix=".ui", prefix="display_", dir=parent_lvl2)
58+
direc, fname, _ = path_info(file_path)
59+
# Try to find the file as is... it should not find it.
60+
assert find_file(fname) is None
61+
62+
# Try to find the file under base_path
63+
disp_path = find_file(fname, base_path=direc)
64+
assert disp_path == file_path
65+
66+
# Try to find the file under the parent folder without recursion (fail)
67+
disp_path = find_file(fname, base_path=parent_lvl1)
68+
assert disp_path == None
69+
70+
# Try to find the file under the parent folder with recursion (succeed)
71+
disp_path = find_file(fname, base_path=parent_lvl1, subdir_scan_enabled=True)
72+
assert disp_path == file_path
73+
74+
5475
def test_which():
5576
if platform.system() == "Windows":
5677
out = which("ping")

0 commit comments

Comments
 (0)