mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
change test to use direct import of file module
This commit is contained in:
parent
a373e7ebd0
commit
ff8c666e3b
1 changed files with 13 additions and 19 deletions
|
@ -2,17 +2,13 @@ import os
|
|||
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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -127,7 +121,7 @@ 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"]
|
||||
|
@ -135,7 +129,7 @@ def test_rmdir_verbose_failure(file, 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
|
||||
|
@ -143,7 +137,7 @@ def test_rmdir_nested_empty_dirs_recurse_older_than(file, nested_empty_dirs):
|
|||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue