def test_is_file_empty(): assert not is_file_empty("LICENSE") assert not is_file_exist("__check_a_file_not_exists__") assert not is_file_empty("tests") assert not is_file_empty(join_path("tests", "resources")) assert not is_file_empty(join_path("tests", "resources", "sample.json")) assert is_file_empty(join_path("tests", "resources", "empty.file"))
def test_join_path(): assert join_path("") == "" assert join_path("hello") == "hello" assert join_path("hello", "world") == "hello/world" assert join_path("a", "b", "c") == "a/b/c" with pytest.raises(TypeError): assert join_path()
def test_is_dir_empty(): assert not is_dir_empty("LICENSE") assert not is_dir_empty("tests") assert not is_dir_empty(join_path("tests", "resources")) assert not is_dir_empty("__check_a_directory_not_exists__") with TemporaryDirectory() as tmp_dir: assert is_dir_empty(tmp_dir) dir_path = join_path(tmp_dir, "nested-empty") make_dir(dir_path) assert is_dir_empty(dir_path) assert not is_dir_empty(join_path(dir_path, "__nested_not_exists__"))
def test_make_dir(): assert make_dir("tests") == "tests" with TemporaryDirectory() as tmp_dir: target_dir = join_path(tmp_dir, "py-put-test-make") assert make_dir(target_dir) == target_dir assert is_dir_exist(target_dir) target_dir = join_path(tmp_dir, "py-put-test-makeq", "123", "456", "789") assert make_dir(target_dir) == target_dir assert is_dir_exist(target_dir) with pytest.raises(FileExistsError): assert make_dir("LICENSE") == "LICENSE"
def test_save_json(): sample = { "time": datetime.now(), "integer": 123, "float": 456.789, "bool": True } with TemporaryDirectory() as tmp_dir: assert save_json(join_path(tmp_dir, "py-put-test-file.json"), sample) is None assert save_json(join_path(tmp_dir, "py-put-test-file2.json"), sample, False) is None with pytest.raises(IsADirectoryError): assert save_json("tests", sample)
def test_remove_dir(): assert remove_dir("__remove_a_directory_no_exists__") is None target_file = "LICENSE" assert is_file_exist(target_file) assert remove_dir(target_file) is None assert is_file_exist(target_file) with TemporaryDirectory() as tmp_dir: target_dir = join_path(tmp_dir, "py-put-test-remove") assert make_dir(target_dir) == target_dir assert is_dir_exist(target_dir) assert remove_dir(target_dir) is None assert not is_dir_exist(target_dir)
def test_is_dir_exist(): assert not is_dir_exist("LICENSE") assert is_dir_exist("tests") assert not is_dir_exist("__check_a_directory_not_exists__") assert is_dir_exist(join_path("tests", "resources")) assert not is_dir_exist(join_path("tests", "resources", "sample.json"))