diff --git a/pysaliency/external_datasets/__init__.py b/pysaliency/external_datasets/__init__.py index 4ddeaee..d9bb825 100644 --- a/pysaliency/external_datasets/__init__.py +++ b/pysaliency/external_datasets/__init__.py @@ -10,7 +10,6 @@ from ..datasets import FixationTrains from ..utils import ( - TemporaryDirectory, download_and_check, atomic_directory_setup, ) diff --git a/pysaliency/external_datasets/cat2000.py b/pysaliency/external_datasets/cat2000.py index 7e405d1..b045c73 100644 --- a/pysaliency/external_datasets/cat2000.py +++ b/pysaliency/external_datasets/cat2000.py @@ -1,25 +1,20 @@ -from __future__ import absolute_import, print_function, division +from __future__ import absolute_import, division, print_function -import zipfile +import glob import os import warnings -import glob +import zipfile +from tempfile import TemporaryDirectory import numpy as np -from scipy.io import loadmat from natsort import natsorted from pkg_resources import resource_string +from scipy.io import loadmat from tqdm import tqdm from ..datasets import FixationTrains -from ..utils import ( - TemporaryDirectory, - filter_files, - run_matlab_cmd, - download_and_check, - atomic_directory_setup) - -from .utils import create_stimuli, _load +from ..utils import atomic_directory_setup, download_and_check, filter_files, run_matlab_cmd +from .utils import _load, create_stimuli def get_cat2000_test(location=None): @@ -47,7 +42,7 @@ def get_cat2000_test(location=None): return stimuli os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: download_and_check('http://saliency.mit.edu/testSet.zip', os.path.join(temp_dir, 'testSet.zip'), '903ec668df2e5a8470aef9d8654e7985') @@ -170,7 +165,7 @@ def _get_cat2000_train(name, location): return stimuli, fixations os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: download_and_check('http://saliency.mit.edu/trainSet.zip', os.path.join(temp_dir, 'trainSet.zip'), '56ad5c77e6c8f72ed9ef2901628d6e48') @@ -298,7 +293,7 @@ def _get_cat2000_train_v1_1(name, location): return stimuli, fixations os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: download_and_check('http://saliency.mit.edu/trainSet.zip', os.path.join(temp_dir, 'trainSet.zip'), '56ad5c77e6c8f72ed9ef2901628d6e48') diff --git a/pysaliency/external_datasets/coco_freeview.py b/pysaliency/external_datasets/coco_freeview.py index 4a7fcdc..d3d243a 100644 --- a/pysaliency/external_datasets/coco_freeview.py +++ b/pysaliency/external_datasets/coco_freeview.py @@ -1,12 +1,13 @@ import json import os import zipfile +from tempfile import TemporaryDirectory import numpy as np from tqdm import tqdm from ..datasets import ScanpathFixations, Scanpaths, create_subset -from ..utils import TemporaryDirectory, atomic_directory_setup, download_and_check, filter_files +from ..utils import atomic_directory_setup, download_and_check, filter_files from .coco_search18 import _prepare_stimuli from .utils import _load, create_stimuli @@ -159,7 +160,7 @@ def get_COCO_Freeview(location=None, test_data=None): os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: download_and_check('http://vision.cs.stonybrook.edu/~cvlab_download/COCOSearch18-images-TP.zip', os.path.join(temp_dir, 'COCOSearch18-images-TP.zip'), '4a815bb591cb463ab77e5ba0c68fedfb') diff --git a/pysaliency/external_datasets/coco_search18.py b/pysaliency/external_datasets/coco_search18.py index 963279d..b09a18c 100644 --- a/pysaliency/external_datasets/coco_search18.py +++ b/pysaliency/external_datasets/coco_search18.py @@ -4,13 +4,14 @@ import shutil import zipfile from hashlib import md5 +from tempfile import TemporaryDirectory import numpy as np from PIL import Image from tqdm import tqdm from ..datasets import ScanpathFixations, Scanpaths, create_subset -from ..utils import TemporaryDirectory, atomic_directory_setup, download_and_check, filter_files +from ..utils import atomic_directory_setup, download_and_check, filter_files from .utils import _load, create_stimuli condition_mapping = { @@ -80,7 +81,7 @@ def get_COCO_Search18(location=None, split=1, merge_tasks=True, unique_images=Tr os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: download_and_check('http://vision.cs.stonybrook.edu/~cvlab_download/COCOSearch18-images-TP.zip', os.path.join(temp_dir, 'COCOSearch18-images-TP.zip'), '4a815bb591cb463ab77e5ba0c68fedfb') diff --git a/pysaliency/external_datasets/dut_omrom.py b/pysaliency/external_datasets/dut_omrom.py index e363488..c260753 100644 --- a/pysaliency/external_datasets/dut_omrom.py +++ b/pysaliency/external_datasets/dut_omrom.py @@ -3,6 +3,7 @@ import glob import os import zipfile +from tempfile import TemporaryDirectory from typing import Tuple import numpy as np @@ -11,7 +12,6 @@ from ..datasets import ScanpathFixations, Scanpaths, Stimuli from ..utils import ( - TemporaryDirectory, atomic_directory_setup, download_and_check, ) @@ -53,7 +53,7 @@ def get_DUT_OMRON(location=None) -> Tuple[Stimuli, ScanpathFixations]: n_fixations = 0 with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: download_and_check('http://saliencydetection.net/dut-omron/download/DUT-OMRON-image.zip', os.path.join(temp_dir, 'DUT-OMRON-image.zip'), diff --git a/pysaliency/external_datasets/figrim.py b/pysaliency/external_datasets/figrim.py index a1cd60a..a1a73ef 100644 --- a/pysaliency/external_datasets/figrim.py +++ b/pysaliency/external_datasets/figrim.py @@ -1,22 +1,21 @@ -from __future__ import absolute_import, print_function, division +from __future__ import absolute_import, division, print_function -import zipfile -import os import glob +import os +import zipfile +from tempfile import TemporaryDirectory import numpy as np -from scipy.io import loadmat -from natsort import natsorted from boltons.fileutils import mkdir_p +from natsort import natsorted +from scipy.io import loadmat from ..datasets import FixationTrains from ..utils import ( - TemporaryDirectory, - download_and_check, atomic_directory_setup, + download_and_check, ) - -from .utils import create_stimuli, _load +from .utils import _load, create_stimuli def _load_FIGRIM_data(filename, stimuli_indices, stimulus_type): @@ -94,7 +93,7 @@ def get_FIGRIM(location=None): return stimuli, fixations os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: download_and_check('http://figrim.mit.edu/Fillers.zip', os.path.join(temp_dir, 'Fillers.zip'), 'dc0bc9561b5bc90e158ec32074dd1060') diff --git a/pysaliency/external_datasets/isun.py b/pysaliency/external_datasets/isun.py index 8a99561..31b8c6e 100644 --- a/pysaliency/external_datasets/isun.py +++ b/pysaliency/external_datasets/isun.py @@ -1,18 +1,14 @@ -from __future__ import absolute_import, print_function, division +from __future__ import absolute_import, division, print_function -import zipfile import os +import zipfile +from tempfile import TemporaryDirectory from scipy.io import loadmat from ..datasets import FixationTrains -from ..utils import ( - TemporaryDirectory, - filter_files, - download_and_check, - atomic_directory_setup) - -from .utils import create_stimuli, _load +from ..utils import atomic_directory_setup, download_and_check, filter_files +from .utils import _load, create_stimuli # TODO: Add test @@ -44,7 +40,7 @@ def get_iSUN(location=None): return stimuli_training, stimuli_validation, stimuli_testing, fixations_training, fixations_validation os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: download_and_check('http://lsun.cs.princeton.edu/challenge/2015/eyetracking/data/training.mat', os.path.join(temp_dir, 'training.mat'), '5a8b15134b17c7a3f69b087845db1363') diff --git a/pysaliency/external_datasets/koehler.py b/pysaliency/external_datasets/koehler.py index 632fd0d..ebc19a2 100644 --- a/pysaliency/external_datasets/koehler.py +++ b/pysaliency/external_datasets/koehler.py @@ -1,23 +1,21 @@ -from __future__ import absolute_import, print_function, division +from __future__ import absolute_import, division, print_function -import zipfile +import itertools import os +import zipfile +from tempfile import TemporaryDirectory -import itertools import numpy as np from scipy.io import loadmat - -from boltons.fileutils import mkdir_p from tqdm import tqdm from ..datasets import FixationTrains from ..utils import ( - TemporaryDirectory, atomic_directory_setup, check_file_hash, - ) +) +from .utils import _load, create_stimuli -from .utils import create_stimuli, _load def _get_koehler_fixations(data, task, n_stimuli): tasks = {'freeviewing': 'freeview', diff --git a/pysaliency/external_datasets/mit.py b/pysaliency/external_datasets/mit.py index e3e433a..56d1e13 100644 --- a/pysaliency/external_datasets/mit.py +++ b/pysaliency/external_datasets/mit.py @@ -3,6 +3,7 @@ import glob import os import zipfile +from tempfile import TemporaryDirectory import numpy as np from natsort import natsorted @@ -11,7 +12,7 @@ from scipy.io import loadmat from ..datasets import ScanpathFixations, Scanpaths -from ..utils import TemporaryDirectory, atomic_directory_setup, build_padded_2d_array, download_and_check, filter_files, run_matlab_cmd +from ..utils import atomic_directory_setup, download_and_check, filter_files, run_matlab_cmd from .utils import _load, create_stimuli @@ -37,7 +38,7 @@ def _get_mit1003(dataset_name, location=None, include_initial_fixation=False, on return stimuli, fixations os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: download_and_check('http://people.csail.mit.edu/tjudd/WherePeopleLook/ALLSTIMULI.zip', os.path.join(temp_dir, 'ALLSTIMULI.zip'), '0d7df8b954ecba69b6796e77b9afe4b6') @@ -389,7 +390,7 @@ def get_mit300(location=None): return stimuli os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: download_and_check('http://saliency.mit.edu/BenchmarkIMAGES.zip', os.path.join(temp_dir, 'BenchmarkIMAGES.zip'), '03ed32bdf5e4289950cd28df89451260') diff --git a/pysaliency/external_datasets/nusef.py b/pysaliency/external_datasets/nusef.py index 07c4c9e..3ca64a4 100644 --- a/pysaliency/external_datasets/nusef.py +++ b/pysaliency/external_datasets/nusef.py @@ -3,19 +3,18 @@ import glob import os import zipfile -from datetime import datetime, timedelta +from datetime import datetime +from tempfile import TemporaryDirectory from tqdm import tqdm from ..datasets import FixationTrains from ..utils import ( - TemporaryDirectory, atomic_directory_setup, download_and_check, ) from .utils import _load, create_stimuli - IMAGE_TYPOS = { '3005_0.jpg': '3005.1.jpg', '3005_2.jpg': '3005.2.jpg', @@ -92,7 +91,7 @@ def get_NUSEF_public(location=None): return stimuli, fixations os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: source_directory = os.path.join(location, 'src') os.makedirs(source_directory) diff --git a/pysaliency/external_datasets/osie.py b/pysaliency/external_datasets/osie.py index 50f3d3f..8ed42c3 100644 --- a/pysaliency/external_datasets/osie.py +++ b/pysaliency/external_datasets/osie.py @@ -1,21 +1,20 @@ -from __future__ import absolute_import, print_function, division +from __future__ import absolute_import, division, print_function import os import urllib +from tempfile import TemporaryDirectory import numpy as np -from scipy.io import loadmat from boltons.fileutils import mkdir_p +from scipy.io import loadmat from tqdm import tqdm from ..datasets import FixationTrains from ..utils import ( - TemporaryDirectory, - download_and_check, atomic_directory_setup, + download_and_check, ) - -from .utils import create_stimuli, _load +from .utils import _load, create_stimuli def get_OSIE(location=None): @@ -45,7 +44,7 @@ def get_OSIE(location=None): return stimuli, fixations os.makedirs(location) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: stimuli_src_location = os.path.join(temp_dir, 'stimuli') mkdir_p(stimuli_src_location) images = [] diff --git a/pysaliency/external_datasets/pascal_s.py b/pysaliency/external_datasets/pascal_s.py index da28c6e..74164df 100644 --- a/pysaliency/external_datasets/pascal_s.py +++ b/pysaliency/external_datasets/pascal_s.py @@ -2,13 +2,13 @@ import os import zipfile +from tempfile import TemporaryDirectory import numpy as np import requests from ..datasets import ScanpathFixations, Scanpaths from ..utils import ( - TemporaryDirectory, atomic_directory_setup, download_and_check, ) @@ -50,7 +50,7 @@ def get_PASCAL_S(location=None): n_stimuli = 850 with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: try: download_and_check('http://cbs.ic.gatech.edu/salobj/download/salObj.zip', diff --git a/pysaliency/external_datasets/salicon.py b/pysaliency/external_datasets/salicon.py index 8387e0f..d7d0d25 100644 --- a/pysaliency/external_datasets/salicon.py +++ b/pysaliency/external_datasets/salicon.py @@ -1,22 +1,17 @@ -from __future__ import absolute_import, print_function, division +from __future__ import absolute_import, division, print_function -import zipfile -import os import glob +import os +import zipfile +from tempfile import TemporaryDirectory import numpy as np from scipy.io import loadmat from tqdm import tqdm -from ..datasets import Fixations, read_hdf5, clip_out_of_stimulus_fixations -from ..utils import ( - TemporaryDirectory, - download_file_from_google_drive, - check_file_hash, - atomic_directory_setup) - -from .utils import create_stimuli, _load - +from ..datasets import Fixations, clip_out_of_stimulus_fixations, read_hdf5 +from ..utils import atomic_directory_setup, check_file_hash, download_file_from_google_drive +from .utils import _load, create_stimuli def get_SALICON(edition='2015', fixation_type='mouse', location=None): @@ -102,7 +97,7 @@ def _get_SALICON_stimuli(location, name, edition='2015', fixation_type='mouse'): os.makedirs(location, exist_ok=True) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: stimuli_file = os.path.join(temp_dir, 'stimuli.zip') download_file_from_google_drive('1g8j-hTT-51IG1UFwP0xTGhLdgIUCW5e5', stimuli_file) @@ -156,7 +151,7 @@ def _get_SALICON_fixations(location, name, edition='2015', fixation_type='mouse' os.makedirs(location, exist_ok=True) with atomic_directory_setup(location): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: fixations_file = os.path.join(temp_dir, 'fixations.zip') if edition == '2015': diff --git a/pysaliency/external_datasets/toronto.py b/pysaliency/external_datasets/toronto.py index 2ebc5d5..49904a8 100644 --- a/pysaliency/external_datasets/toronto.py +++ b/pysaliency/external_datasets/toronto.py @@ -1,20 +1,16 @@ -from __future__ import absolute_import, print_function, division +from __future__ import absolute_import, division, print_function import os import warnings import zipfile - +from tempfile import TemporaryDirectory import numpy as np from scipy.io import loadmat -from ..datasets import FixationTrains, Fixations -from ..utils import ( - TemporaryDirectory, - download_and_check, - atomic_directory_setup) - -from .utils import create_stimuli, _load +from ..datasets import Fixations, FixationTrains +from ..utils import atomic_directory_setup, download_and_check +from .utils import _load, create_stimuli def get_toronto(location=None): diff --git a/pysaliency/external_models/matlab_models.py b/pysaliency/external_models/matlab_models.py index e9da44a..3f7f24b 100644 --- a/pysaliency/external_models/matlab_models.py +++ b/pysaliency/external_models/matlab_models.py @@ -1,13 +1,14 @@ -from __future__ import absolute_import, print_function, division, unicode_literals +from __future__ import absolute_import, division, print_function, unicode_literals import os import zipfile +from tempfile import TemporaryDirectory + from pkg_resources import resource_string -from ..utils import TemporaryDirectory, download_and_check, run_matlab_cmd from ..saliency_map_models import MatlabSaliencyMapModel - -from .utils import extract_zipfile, apply_quilt, download_extract_patch, ExternalModelMixin +from ..utils import download_and_check, run_matlab_cmd +from .utils import ExternalModelMixin, apply_quilt, download_extract_patch, extract_zipfile class AIM(ExternalModelMixin, MatlabSaliencyMapModel): diff --git a/pysaliency/external_models/models.py b/pysaliency/external_models/models.py index 6833f42..919fac1 100644 --- a/pysaliency/external_models/models.py +++ b/pysaliency/external_models/models.py @@ -10,7 +10,7 @@ import numpy as np from scipy.ndimage import zoom -from ..utils import TemporaryDirectory, download_and_check, run_matlab_cmd +from ..utils import download_and_check, run_matlab_cmd from ..quilt import QuiltSeries from ..saliency_map_models import MatlabSaliencyMapModel, SaliencyMapModel diff --git a/pysaliency/external_models/utils.py b/pysaliency/external_models/utils.py index 1ff8178..8647546 100644 --- a/pysaliency/external_models/utils.py +++ b/pysaliency/external_models/utils.py @@ -1,13 +1,15 @@ -from __future__ import absolute_import, print_function, division, unicode_literals +from __future__ import absolute_import, division, print_function, unicode_literals import os +import tarfile import tempfile import zipfile -import tarfile -from pkg_resources import resource_string, resource_listdir +from tempfile import TemporaryDirectory + +from pkg_resources import resource_listdir, resource_string -from ..utils import TemporaryDirectory, download_and_check from ..quilt import QuiltSeries +from ..utils import download_and_check def write_file(filename, contents): diff --git a/pysaliency/saliency_map_models.py b/pysaliency/saliency_map_models.py index 2488582..882a78a 100644 --- a/pysaliency/saliency_map_models.py +++ b/pysaliency/saliency_map_models.py @@ -1,24 +1,23 @@ -from __future__ import absolute_import, print_function, division, unicode_literals -from itertools import combinations +from __future__ import absolute_import, division, print_function, unicode_literals import os from abc import ABCMeta, abstractmethod +from itertools import combinations +from tempfile import TemporaryDirectory import numpy as np -from scipy.io import loadmat +from boltons.cacheutils import LRU, cached from imageio import imsave +from scipy.io import loadmat from scipy.ndimage import gaussian_filter, zoom - from tqdm import tqdm -from boltons.cacheutils import cached, LRU - -from .roc import general_roc, general_rocs_per_positive -from .numba_utils import fill_fixation_map, auc_for_one_positive -from .utils import TemporaryDirectory, run_matlab_cmd, Cache, average_values, deprecated_class, remove_trailing_nans -from .datasets import Stimulus, Fixations, check_prediction_shape, get_image_hash +from .datasets import Fixations, Stimulus, check_prediction_shape, get_image_hash from .metrics import CC, NSS, SIM +from .numba_utils import auc_for_one_positive, fill_fixation_map +from .roc import general_roc, general_rocs_per_positive from .sampling_models import SamplingModelMixin +from .utils import Cache, average_values, deprecated_class, remove_trailing_nans, run_matlab_cmd def handle_stimulus(stimulus): @@ -796,7 +795,7 @@ def matlab_command(self, stimulus): return "{command}('{{stimulus}}', '{{saliency_map}}');".format(command=self.command) def _saliency_map(self, stimulus): - with TemporaryDirectory(cleanup=True) as temp_dir: + with TemporaryDirectory() as temp_dir: stimulus_file = os.path.join(temp_dir, 'stimulus'+self.stimulus_ext) if self.only_color_stimuli: if stimulus.ndim == 2: diff --git a/pysaliency/utils/__init__.py b/pysaliency/utils/__init__.py index 38a202e..ab494dd 100644 --- a/pysaliency/utils/__init__.py +++ b/pysaliency/utils/__init__.py @@ -185,92 +185,6 @@ def cache(self, value): self._cache.clear() -class TemporaryDirectory(object): - """Create and return a temporary directory. This has the same - behavior as mkdtemp but can be used as a context manager. For - example: - - with TemporaryDirectory() as tmpdir: - ... - - Upon exiting the context, the directory and everything contained - in it are removed. - - From http://stackoverflow.com/a/19299884 - """ - - def __init__(self, suffix="", prefix="tmp", dir=None, cleanup=True): - self._closed = False - self.name = None # Handle mkdtemp raising an exception - self.name = mkdtemp(suffix, prefix, dir) - self.do_cleanup = cleanup - - def __repr__(self): - return "<{} {!r}>".format(self.__class__.__name__, self.name) - - def __enter__(self): - return self.name - - def cleanup(self, _warn=False): - if not self.do_cleanup: - return - if self.name and not self._closed: - try: - self._rmtree(self.name) - except (TypeError, AttributeError) as ex: - # Issue #10188: Emit a warning on stderr - # if the directory could not be cleaned - # up due to missing globals - if "None" not in str(ex): - raise - print("ERROR: {!r} while cleaning up {!r}".format(ex, self,), - file=_sys.stderr) - return - self._closed = True - if _warn: - self._warn("Implicitly cleaning up {!r}".format(self)) - - def __exit__(self, exc, value, tb): - self.cleanup() - - def __del__(self): - # Issue a ResourceWarning if implicit cleanup needed - self.cleanup(_warn=True) - - # XXX (ncoghlan): The following code attempts to make - # this class tolerant of the module nulling out process - # that happens during CPython interpreter shutdown - # Alas, it doesn't actually manage it. See issue #10188 - _listdir = staticmethod(_os.listdir) - _path_join = staticmethod(_os.path.join) - _isdir = staticmethod(_os.path.isdir) - _islink = staticmethod(_os.path.islink) - _remove = staticmethod(_os.remove) - _rmdir = staticmethod(_os.rmdir) - _warn = _warnings.warn - - def _rmtree(self, path): - # Essentially a stripped down version of shutil.rmtree. We can't - # use globals because they may be None'ed out at shutdown. - for name in self._listdir(path): - fullname = self._path_join(path, name) - try: - isdir = self._isdir(fullname) and not self._islink(fullname) - except OSError: - isdir = False - if isdir: - self._rmtree(fullname) - else: - try: - self._remove(fullname) - except OSError: - pass - try: - self._rmdir(path) - except OSError: - pass - - @contextmanager def atomic_directory_setup(directory): """ context manager that makes sure that directory is deleted in case of exceptions. """ diff --git a/tests/test_utils.py b/tests/test_utils.py index c3c5269..86de96e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -7,7 +7,7 @@ import numpy as np -from pysaliency.utils import LazyList, TemporaryDirectory, Cache, get_minimal_unique_filenames, atomic_directory_setup, build_padded_2d_array +from pysaliency.utils import LazyList, Cache, get_minimal_unique_filenames, atomic_directory_setup, build_padded_2d_array from test_helpers import TestWithData @@ -74,15 +74,6 @@ def gen(i): self.assertEqual(list(lazy_list), [i**2 for i in range(length)]) -class TestTemporaryDirectory(unittest.TestCase): - def test_temporary_directory(self): - with TemporaryDirectory() as tmp_dir: - self.assertTrue(os.path.isdir(tmp_dir)) - - self.assertFalse(os.path.isdir(tmp_dir)) - self.assertFalse(os.path.exists(tmp_dir)) - - def test_atomic_directory_setup_success(tmp_path): directory = tmp_path / 'testdirectory' assert not directory.exists()