Пример #1
0
def test_create_temp_dir__creation_preempted(temp_folder):
    unwrapped, preempted_once = os.makedirs, []
    def _wrap_os_makedirs(*args, **kwargs):
        # Simulate somebody else creating the directory first
        if not preempted_once:
            unwrapped(*args, **kwargs)
            preempted_once.append(True)
        unwrapped(*args, **kwargs)

    with Monkeypatch("os.makedirs", _wrap_os_makedirs):
        assert not os.listdir(temp_folder)
        work_dir = create_temp_dir(temp_folder)
        assert os.path.exists(temp_folder)
        dirs = os.listdir(temp_folder)
        assert_equal(len(dirs), 2)
        assert_in(os.path.basename(work_dir), dirs)
        assert bool(preempted_once)
Пример #2
0
def test_create_temp_dir__creation_preempted(temp_folder):
    unwrapped, preempted_once = os.makedirs, []

    def _wrap_os_makedirs(*args, **kwargs):
        # Simulate somebody else creating the directory first
        if not preempted_once:
            unwrapped(*args, **kwargs)
            preempted_once.append(True)
        unwrapped(*args, **kwargs)

    with Monkeypatch("os.makedirs", _wrap_os_makedirs):
        assert not os.listdir(temp_folder)
        work_dir = create_temp_dir(temp_folder)
        assert os.path.exists(temp_folder)
        dirs = os.listdir(temp_folder)
        assert_equal(len(dirs), 2)
        assert_in(os.path.basename(work_dir), dirs)
        assert bool(preempted_once)
Пример #3
0
    def run(self, config):
        """Runs the node, by calling _setup, _run, and _teardown in that order.
        Prior to calling these functions, a temporary dir is created using the
        'temp_root' prefix from the config object. Both the config object and
        the temporary dir are passed to the above functions. The temporary
        dir is removed after _teardown is called, and all expected files
        should have been removed/renamed at that point.

        Any non-NodeError exception raised in this function is wrapped in a
        NodeUnhandledException, which includes a full backtrace. This is needed
        to allow showing these in the main process."""

        try:
            temp = None
            temp = fileutils.create_temp_dir(config.temp_root)

            self._setup(config, temp)
            self._run(config, temp)
            self._teardown(config, temp)

            os.rmdir(temp)
        except NodeError, error:
            self._write_error_log(temp, error)
            raise error
Пример #4
0
    def run(self, config):
        """Runs the node, by calling _setup, _run, and _teardown in that order.
        Prior to calling these functions, a temporary dir is created using the
        'temp_root' prefix from the config object. Both the config object and
        the temporary dir are passed to the above functions. The temporary
        dir is removed after _teardown is called, and all expected files
        should have been removed/renamed at that point.

        Any non-NodeError exception raised in this function is wrapped in a
        NodeUnhandledException, which includes a full backtrace. This is needed
        to allow showing these in the main process."""

        try:
            temp = None
            temp = fileutils.create_temp_dir(config.temp_root)

            self._setup(config, temp)
            self._run(config, temp)
            self._teardown(config, temp)

            os.rmdir(temp)
        except NodeError, error:
            self._write_error_log(temp, error)
            raise error
Пример #5
0
    def _create_temp_dir(self, config):
        """Called by 'run' in order to create a temporary folder.

        'config' is expected to have a property .temp_root under
        which the temporary folder is created."""
        return fileutils.create_temp_dir(config.temp_root)
Пример #6
0
def test_create_temp_dir__permissions(temp_folder):
    tmp_dir = create_temp_dir(temp_folder)
    stats = os.stat(tmp_dir)
    assert_equal(stats.st_mode & 0777, 0700)
Пример #7
0
def test_create_temp_dir__empty(temp_folder):
    tmp_dir = create_temp_dir(temp_folder)
    contents = os.listdir(tmp_dir)
    assert not contents
Пример #8
0
def test_create_temp_dir__create(temp_folder):
    tmp_dir_1 = create_temp_dir(temp_folder)
    tmp_dir_2 = create_temp_dir(temp_folder)
    assert os.path.exists(tmp_dir_1)
    assert os.path.exists(tmp_dir_2)
Пример #9
0
    def _create_temp_dir(self, config):
        """Called by 'run' in order to create a temporary folder.

        'config' is expected to have a property .temp_root under
        which the temporary folder is created."""
        return fileutils.create_temp_dir(config.temp_root)
Пример #10
0
def test_create_temp_dir__permissions(temp_folder):
    tmp_dir = create_temp_dir(temp_folder)
    stats   = os.stat(tmp_dir)
    assert_equal(stats.st_mode & 0777, 0700)
Пример #11
0
def test_create_temp_dir__empty(temp_folder):
    tmp_dir  = create_temp_dir(temp_folder)
    contents = os.listdir(tmp_dir)
    assert not contents
Пример #12
0
def test_create_temp_dir__create(temp_folder):
    tmp_dir_1 = create_temp_dir(temp_folder)
    tmp_dir_2 = create_temp_dir(temp_folder)
    assert os.path.exists(tmp_dir_1)
    assert os.path.exists(tmp_dir_2)