Create and auto-destroy temp dir. This is designed to be used with testing modules. Instances should be defined inside test functions. Instances defined at module level can not guarantee proper destruction of the temporary directory. When used at module level, the current use of th
| 34 | |
| 35 | |
| 36 | class _TempDir(str): |
| 37 | """Create and auto-destroy temp dir. |
| 38 | |
| 39 | This is designed to be used with testing modules. Instances should be |
| 40 | defined inside test functions. Instances defined at module level can not |
| 41 | guarantee proper destruction of the temporary directory. |
| 42 | |
| 43 | When used at module level, the current use of the __del__() method for |
| 44 | cleanup can fail because the rmtree function may be cleaned up before this |
| 45 | object (an alternative could be using the atexit module instead). |
| 46 | """ |
| 47 | |
| 48 | def __new__(self): # noqa: D105 |
| 49 | new = str.__new__(self, tempfile.mkdtemp(prefix="tmp_mne_tempdir_")) |
| 50 | return new |
| 51 | |
| 52 | def __init__(self): |
| 53 | self._path = self.__str__() |
| 54 | |
| 55 | def __del__(self): # noqa: D105 |
| 56 | rmtree(self._path, ignore_errors=True) |
| 57 | |
| 58 | |
| 59 | def requires_mne(func): |
no outgoing calls