def _test_rmtree(self, *args, **kwargs): testdir = tempfile.mkdtemp() with open(os.path.join(testdir, 'foo.txt'), 'w') as fp: fp.write('hello\n') os_ext.rmtree(testdir, *args, **kwargs) assert not os.path.exists(testdir)
def _makedir(self, *dirs, wipeout=False): ret = os.path.join(*dirs) if wipeout: os_ext.rmtree(ret, ignore_errors=True) os.makedirs(ret, exist_ok=True) return ret
def test_rmtree_error(tmp_path): # Try to remove an inexistent directory testdir = tmp_path / 'tmp' testdir.mkdir() os.rmdir(str(testdir)) with pytest.raises(OSError): os_ext.rmtree(testdir)
def safe_rmtree(path, **kwargs): '''Do some safety checks before removing path to protect against silly, but catastrophic bugs, during development. Do not allow removing any subdirectory of reframe or any directory containing reframe. Also do not allow removing the user's $HOME directory. ''' path = os.path.abspath(path) common_path = os.path.commonpath([reframe.INSTALL_PREFIX, path]) assert common_path != reframe.INSTALL_PREFIX assert common_path != path assert path != os.environ['HOME'] os_ext.rmtree(path, **kwargs)
def cleanup(self, remove_files=False, unload_env=True): """The cleanup phase of the regression test pipeline. :arg remove_files: If :class:`True`, the stage directory associated with this test will be removed. :arg unload_env: If :class:`True`, the environment that was used to run this test will be unloaded. """ aliased = os.path.samefile(self._stagedir, self._outputdir) if aliased: self.logger.debug('skipping copy to output dir ' 'since they alias each other') else: self._copy_to_outputdir() if remove_files: self.logger.debug('removing stage directory') os_ext.rmtree(self._stagedir) if unload_env: self.logger.debug("unloading test's environment") self._user_environ.unload() self._current_environ.unload() self._current_partition.local_env.unload()
def tearDown(self): os_ext.rmtree(self.prefix) os_ext.rmtree(self.perflogdir, ignore_errors=True) os_ext.force_remove_file(self.logfile)
def tearDown(self): self.perf_file.close() self.output_file.close() os.remove(self.perf_file.name) os.remove(self.output_file.name) os_ext.rmtree(self.resourcesdir)
def tearDown(self): os_ext.rmtree(rt.runtime().resources.prefix) os_ext.rmtree('.rfm_testing', ignore_errors=True)
def tearDown(self): os_ext.rmtree(rt.runtime().resources.prefix)
def tearDown(self): os_ext.rmtree(self.workdir)
def test_rmtree_error(self): # Try to remove an inexistent directory testdir = tempfile.mkdtemp() os.rmdir(testdir) with pytest.raises(OSError): os_ext.rmtree(testdir)
def _rmtree(*args, **kwargs): os_ext.rmtree(testdir, *args, **kwargs) assert not os.path.exists(testdir)