MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / test_convert_utilities

Function test_convert_utilities

tests_python/test_convert_utilities.py:76–130  ·  view source on GitHub ↗
(tmpdir)

Source from the content-addressed store, hash-verified

74
75
76def test_convert_utilities(tmpdir):
77 import pydevd_file_utils
78
79 test_dir = str(tmpdir.mkdir("Test_Convert_Utilities"))
80
81 if IS_WINDOWS:
82 normalized = pydevd_file_utils.normcase(test_dir)
83 assert isinstance(normalized, str)
84 assert normalized.lower() == normalized
85
86 upper_version = os.path.join(test_dir, "ÁÉÍÓÚ")
87 with open(upper_version, "w") as stream:
88 stream.write("test")
89
90 with open(upper_version, "r") as stream:
91 assert stream.read() == "test"
92
93 with open(pydevd_file_utils.normcase(upper_version), "r") as stream:
94 assert stream.read() == "test"
95
96 assert "~" not in normalized
97
98 for i in range(3): # Check if cache is ok.
99 if i == 2:
100 pydevd_file_utils._listdir_cache.clear()
101
102 assert pydevd_file_utils.get_path_with_real_case("<does not EXIST>") == "<does not EXIST>"
103 real_case = pydevd_file_utils.get_path_with_real_case(normalized)
104 assert isinstance(real_case, str)
105 # Note test_dir itself cannot be compared with because pytest may
106 # have passed the case normalized.
107 assert real_case.endswith("Test_Convert_Utilities")
108
109 if i == 2:
110 # Check that we have the expected paths in the cache.
111 assert pydevd_file_utils._listdir_cache[os.path.dirname(normalized).lower()] == ["Test_Convert_Utilities"]
112 assert (
113 pydevd_file_utils._listdir_cache[(os.path.dirname(normalized).lower(), "Test_Convert_Utilities".lower())] == real_case
114 )
115
116 # Check that it works with a shortened path.
117 shortened = pydevd_file_utils.convert_to_short_pathname(normalized)
118 assert "~" in shortened
119 with_real_case = pydevd_file_utils.get_path_with_real_case(shortened)
120 assert with_real_case.endswith("Test_Convert_Utilities")
121 assert "~" not in with_real_case
122
123 elif IS_MAC:
124 assert pydevd_file_utils.normcase(test_dir) == test_dir.lower()
125 assert pydevd_file_utils.get_path_with_real_case(test_dir) == test_dir
126
127 else:
128 # On Linux, nothing should change
129 assert pydevd_file_utils.normcase(test_dir) == test_dir
130 assert pydevd_file_utils.get_path_with_real_case(test_dir) == test_dir
131
132
133def test_source_reference(tmpdir):

Callers

nothing calls this directly

Calls 4

joinMethod · 0.45
writeMethod · 0.45
readMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected