MCPcopy Index your code
hub / github.com/apache/tvm / test_tempdir

Function test_tempdir

tests/python/support/test_util.py:36–86  ·  view source on GitHub ↗

Tests for temporary dir

()

Source from the content-addressed store, hash-verified

34
35
36def test_tempdir():
37 """Tests for temporary dir"""
38 assert utils.TempDirectory._KEEP_FOR_DEBUG is False, "don't submit with KEEP_FOR_DEBUG == True"
39
40 temp_dir = utils.tempdir()
41 assert os.path.exists(temp_dir.temp_dir)
42
43 old_debug_mode = utils.TempDirectory._KEEP_FOR_DEBUG
44 old_tempdirs = utils.TempDirectory.TEMPDIRS
45 try:
46 for temp_dir_number in range(0, 3):
47 with utils.TempDirectory.set_keep_for_debug():
48 debug_temp_dir = utils.tempdir()
49 try:
50 validate_debug_dir_path(debug_temp_dir, "0000" + str(temp_dir_number))
51 finally:
52 shutil.rmtree(debug_temp_dir.temp_dir)
53
54 with utils.TempDirectory.set_keep_for_debug():
55 # Create 2 temp_dir within the same session.
56 debug_temp_dir = utils.tempdir()
57 try:
58 validate_debug_dir_path(debug_temp_dir, "00003")
59 finally:
60 shutil.rmtree(debug_temp_dir.temp_dir)
61
62 debug_temp_dir = utils.tempdir()
63 try:
64 validate_debug_dir_path(debug_temp_dir, "00004")
65 finally:
66 shutil.rmtree(debug_temp_dir.temp_dir)
67
68 with utils.TempDirectory.set_keep_for_debug(False):
69 debug_temp_dir = utils.tempdir() # This one should get deleted.
70
71 # Simulate atexit hook
72 utils.TempDirectory.remove_tempdirs()
73
74 # Calling twice should be a no-op.
75 utils.TempDirectory.remove_tempdirs()
76
77 # Creating a new TempDirectory should fail now
78 try:
79 utils.tempdir()
80 assert False, "creation should fail"
81 except utils.DirectoryCreatedPastAtExit:
82 pass
83
84 finally:
85 utils.TempDirectory.DEBUG_MODE = old_debug_mode
86 utils.TempDirectory.TEMPDIRS = old_tempdirs
87
88
89if __name__ == "__main__":

Callers 1

test_util.pyFile · 0.85

Calls 4

validate_debug_dir_pathFunction · 0.85
strFunction · 0.85
set_keep_for_debugMethod · 0.80
remove_tempdirsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…