Esempio n. 1
0
def TemporaryDirectory(*args, **kwargs):
    import warnings
    from tempfile import TemporaryDirectory as TmpDir
    warnings.warn(
        "This function is deprecated. Please use `tempfile.TemporaryDirectory`",
        DeprecationWarning,
        stacklevel=2)
    return TmpDir(*args, **kwargs)
Esempio n. 2
0
def TemporaryDirectory(*args, **kwargs):  # pylint: disable=invalid-name
    """This function is deprecated. Please use `tempfile.TemporaryDirectory`"""
    import warnings
    from tempfile import TemporaryDirectory as TmpDir
    warnings.warn(
        "This function is deprecated. Please use `tempfile.TemporaryDirectory`",
        DeprecationWarning, stacklevel=2
    )
    return TmpDir(*args, **kwargs)
Esempio n. 3
0
    def __init__(self,
                 job_dir=None,
                 out_dir=None,
                 timeout=600.0,
                 verbose=False):
        self._proc = None
        self._job_dir = TmpDir() if job_dir is None else ntpl(name=job_dir)
        self._out_dir = TmpDir() if out_dir is None else ntpl(name=out_dir)
        self._timeout = timeout
        self._verbose = verbose

        # Make sure that the output directories exist, and that only the current
        # user has access to these directories
        def mk_secure_dir(dir):
            if not os.path.isdir(dir):
                os.makedirs(dir, exist_ok=True, mode=0o700)
            os.chmod(dir, 0o700)

        mk_secure_dir(self._job_dir.name)
        mk_secure_dir(self._out_dir.name)
 def test_csv_rounder(self, input_path, answer_path, has_total_col):
     """Test case for the method `csv_rounder()`."""
     with TmpDir() as tmp_dir:
         # generate the output file in a temporary directory
         tmp_input_path = copy(input_path, tmp_dir)
         tmp_output_path = csv_rounder(tmp_input_path, has_total_col)
         # compare output file and answer file one line by one line
         with open(tmp_output_path, newline='') as output, \
                 open(answer_path, newline='') as answer:
             output_reader = csv.reader(output)
             answer_reader = csv.reader(answer)
             for o, a in zip(output_reader, answer_reader):
                 assert o == a