Skip to content

Commit

Permalink
change test to use direct import of file module
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasmhughes committed Jun 29, 2022
1 parent a373e7e commit ff8c666
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions tests/pytests/functional/modules/file/test_rmdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
import time

import pytest
import salt.modules.file as file

pytestmark = [
pytest.mark.windows_whitelisted,
]


@pytest.fixture(scope="module")
def file(modules):
return modules.file


@pytest.fixture(scope="function")
def single_empty_dir(tmp_path):
yield str(tmp_path)
Expand Down Expand Up @@ -68,48 +64,46 @@ def nested_dirs_with_files(tmp_path):
yield str(tmp_path)


def test_rmdir_success_with_default_options(file, single_empty_dir):
def test_rmdir_success_with_default_options(single_empty_dir):
assert file.rmdir(single_empty_dir) is True
assert not os.path.isdir(single_empty_dir)
assert not os.path.exists(single_empty_dir)


def test_rmdir_failure_with_default_options(file, single_dir_with_file):
def test_rmdir_failure_with_default_options(single_dir_with_file):
assert file.rmdir(single_dir_with_file) is False
assert os.path.isdir(single_dir_with_file)


def test_rmdir_single_dir_success_with_recurse(file, single_empty_dir):
def test_rmdir_single_dir_success_with_recurse(single_empty_dir):
assert file.rmdir(single_empty_dir, recurse=True) is True
assert not os.path.isdir(single_empty_dir)
assert not os.path.exists(single_empty_dir)


def test_rmdir_single_dir_failure_with_recurse(file, single_dir_with_file):
def test_rmdir_single_dir_failure_with_recurse(single_dir_with_file):
assert file.rmdir(single_dir_with_file, recurse=True) is False
assert os.path.isdir(single_dir_with_file)


def test_rmdir_nested_empty_dirs_failure_with_default_options(file, nested_empty_dirs):
def test_rmdir_nested_empty_dirs_failure_with_default_options(nested_empty_dirs):
assert file.rmdir(nested_empty_dirs) is False
assert os.path.isdir(nested_empty_dirs)


def test_rmdir_nested_empty_dirs_success_with_recurse(file, nested_empty_dirs):
def test_rmdir_nested_empty_dirs_success_with_recurse(nested_empty_dirs):
assert file.rmdir(nested_empty_dirs, recurse=True) is True
assert not os.path.isdir(nested_empty_dirs)
assert not os.path.exists(nested_empty_dirs)


def test_rmdir_nested_dirs_with_files_failure_with_recurse(
file, nested_dirs_with_files
):
def test_rmdir_nested_dirs_with_files_failure_with_recurse(nested_dirs_with_files):
assert file.rmdir(nested_dirs_with_files, recurse=True) is False
assert os.path.isdir(nested_dirs_with_files)


def test_rmdir_verbose_nested_dirs_with_files_failure_with_recurse(
file, nested_dirs_with_files
nested_dirs_with_files,
):
ret = file.rmdir(nested_dirs_with_files, recurse=True, verbose=True)
assert ret["result"] is False
Expand All @@ -118,7 +112,7 @@ def test_rmdir_verbose_nested_dirs_with_files_failure_with_recurse(
assert os.path.isdir(nested_dirs_with_files)


def test_rmdir_verbose_success(file, single_empty_dir):
def test_rmdir_verbose_success(single_empty_dir):
ret = file.rmdir(single_empty_dir, verbose=True)
assert ret["result"] is True
assert ret["deleted"][0] == single_empty_dir
Expand All @@ -127,23 +121,23 @@ def test_rmdir_verbose_success(file, single_empty_dir):
assert not os.path.exists(single_empty_dir)


def test_rmdir_verbose_failure(file, single_dir_with_file):
def test_rmdir_verbose_failure(single_dir_with_file):
ret = file.rmdir(single_dir_with_file, verbose=True)
assert ret["result"] is False
assert not ret["deleted"]
assert ret["errors"][0][0] == single_dir_with_file
assert os.path.isdir(single_dir_with_file)


def test_rmdir_nested_empty_dirs_recurse_older_than(file, nested_empty_dirs):
def test_rmdir_nested_empty_dirs_recurse_older_than(nested_empty_dirs):
ret = file.rmdir(nested_empty_dirs, recurse=True, verbose=True, older_than=1)
assert ret["result"] is True
assert len(ret["deleted"]) == 8
assert len(ret["errors"]) == 0
assert os.path.isdir(nested_empty_dirs)


def test_rmdir_nested_empty_dirs_recurse_not_older_than(file, nested_empty_dirs):
def test_rmdir_nested_empty_dirs_recurse_not_older_than(nested_empty_dirs):
ret = file.rmdir(nested_empty_dirs, recurse=True, verbose=True, older_than=3)
assert ret["result"] is True
assert len(ret["deleted"]) == 0
Expand Down

0 comments on commit ff8c666

Please sign in to comment.