# Path: caput/misc.py
# def vectorize(**base_kwargs):
#         def __init__(self, func):
#         def __call__(self, *args, **kwargs):
#         def __get__(self, obj, objtype=None):
# def scalarize(dtype=np.float64):
#         def __init__(self, func):
#         def __call__(self, *args, **kwargs):
#         def _make_array(x):
#         def __get__(self, obj, objtype=None):
# def listize(**_):
#         def __init__(self, func):
#         def __call__(self, *args, **kwargs):
#         def __get__(self, obj, objtype=None):
# def open_h5py_mpi(f, mode, use_mpi=True, comm=None):
#     def __init__(self, name, preserve=False, comm=None):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_val, exc_tb):
#     def tmpfile(self):
#     def lockfile(self):
# def getfullargspec(*args, **kwargs):
# def import_class(class_path):
#     class _vectorize_desc:
#     class _scalarize_desc:
#     class _listize_desc:
# class lock_file:


import unittest
import tempfile
import os
import pytest
import shutil
from caput import misc

        base = "newfile.dat"
        newfile_name = os.path.join(self.dir, base)
        lockfile_name = os.path.join(self.dir, "." + base + ".lock")

        with misc.lock_file(newfile_name) as fname:

            # Check lock file has been created
            self.assertTrue(os.path.exists(lockfile_name))

            # Create a stub file
            with open(fname, "w+") as fh:
                fh.write("hello")

            # Check the file exists only at the temporary path
            self.assertTrue(os.path.exists(fname))
            self.assertFalse(os.path.exists(newfile_name))

        # Check the file exists at the final path and the lock file removed
        self.assertTrue(os.path.exists(newfile_name))
        self.assertFalse(os.path.exists(lockfile_name))

    def test_lock_exception(self):
        """Check what happens in an exception"""

        base = "newfile2.dat"
        newfile_name = os.path.join(self.dir, base)
        lockfile_name = os.path.join(self.dir, "." + base + ".lock")

        with pytest.raises(RuntimeError):

# Path: caput/misc.py
# def vectorize(**base_kwargs):
#         def __init__(self, func):
#         def __call__(self, *args, **kwargs):
#         def __get__(self, obj, objtype=None):
# def scalarize(dtype=np.float64):
#         def __init__(self, func):
#         def __call__(self, *args, **kwargs):
#         def _make_array(x):
#         def __get__(self, obj, objtype=None):
# def listize(**_):
#         def __init__(self, func):
#         def __call__(self, *args, **kwargs):
#         def __get__(self, obj, objtype=None):
# def open_h5py_mpi(f, mode, use_mpi=True, comm=None):
#     def __init__(self, name, preserve=False, comm=None):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_val, exc_tb):
#     def tmpfile(self):
#     def lockfile(self):
# def getfullargspec(*args, **kwargs):
# def import_class(class_path):
#     class _vectorize_desc:
#     class _scalarize_desc:
#     class _listize_desc:
# class lock_file:


# Path: caput/tests/test_misc.py
import unittest
import tempfile
import os
import pytest
import shutil
from caput import misc


        base = "newfile.dat"
        newfile_name = os.path.join(self.dir, base)
        lockfile_name = os.path.join(self.dir, "." + base + ".lock")

        with misc.lock_file(newfile_name) as fname:

            # Check lock file has been created
            self.assertTrue(os.path.exists(lockfile_name))

            # Create a stub file
            with open(fname, "w+") as fh:
                fh.write("hello")

            # Check the file exists only at the temporary path
            self.assertTrue(os.path.exists(fname))
            self.assertFalse(os.path.exists(newfile_name))

        # Check the file exists at the final path and the lock file removed
        self.assertTrue(os.path.exists(newfile_name))
        self.assertFalse(os.path.exists(lockfile_name))

    def test_lock_exception(self):
        """Check what happens in an exception"""

        base = "newfile2.dat"
        newfile_name = os.path.join(self.dir, base)
        lockfile_name = os.path.join(self.dir, "." + base + ".lock")

        with pytest.raises(RuntimeError):

            with misc.lock_file(newfile_name) as fname: