MCPcopy Index your code
hub / github.com/hyperopt/hyperopt / test_temp_dir_sentinel

Function test_temp_dir_sentinel

hyperopt/tests/unit/test_utils.py:119–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

117
118
119def test_temp_dir_sentinel():
120 from os.path import join, isdir, exists
121
122 basedir = "test_temp_dir_sentinel"
123 fn = join(basedir, "foo", "bar")
124 if exists(basedir):
125 print("Path %s exists, not running test_temp_dir_sentinel()" % basedir)
126 return
127 os.makedirs(basedir)
128 eq_(get_closest_dir(fn)[0], basedir)
129 eq_(get_closest_dir(fn)[1], "foo")
130 sentinel = join(basedir, "foo.inuse")
131 try:
132 with temp_dir(fn, erase_after=True, with_sentinel=True):
133 assert isdir(fn)
134 assert exists(sentinel)
135 # simulate work
136 open(join(fn, "dummy.txt"), "w").close()
137 # work file should be deleted together with directory
138 assert not exists(fn)
139 assert not exists(join(basedir, "foo"))
140 # basedir should still exist, though!
141 assert isdir(basedir)
142 finally:
143 if isdir(basedir):
144 shutil.rmtree(basedir)
145
146
147def test_workdir():

Callers

nothing calls this directly

Calls 3

get_closest_dirFunction · 0.90
temp_dirFunction · 0.90
closeMethod · 0.80

Tested by

no test coverage detected