def test_unlink(): target = os.path.join("xxx", "symlink") os.symlink(os.path.realpath(file_1_path), target) assert path(target).exists path(target).unlink() assert not path(target).exists
def test_base_methods(): path_1 = path("/tmp/file with spaces").replace(" ", "-") assert isinstance(path_1, path) assert path_1 == "/tmp/file-with-spaces" path_2 = path("smallfile").upper() assert isinstance(path_2, path) assert path_2 == "SMALLFILE" path_3 = path("/tmp/file.txt")[:5] assert isinstance(path_3, path) assert path_3 == "/tmp/"
def test_ls_dirs(): dir_content = path(root).ls_dirs() names_only = [a.basename for a in dir_content] assert len(dir_content) == len(dir_list) assert set(dir_list).issubset(names_only) assert not set(file_list).issubset(names_only)
def test__div__(): joined_path = path(root) / path(file_1) assert joined_path.exists joined_path = path(root) / file_1 assert joined_path.exists joined_path = path(root) / path(file_1) / path("xxx") assert not joined_path.exists joined_path = path(root) / path(file_1) / "xxx" assert not joined_path.exists
def test_rm(): path(file_1_path).rm() assert not os.path.exists(file_1_path) path(dir_1_path).rm() assert not os.path.exists(dir_1_path) file_location = os.path.join(dir_2_path, "xxx") open(file_location, "w") with pytest.raises(OSError): path(dir_2_path).rm() assert os.path.exists(dir_2_path) path(dir_2_path).rm(r=True) assert not os.path.exists(dir_2_path)
def test_ln_hard(): symlink = path(file_1_path).ln(os.path.join("xxx", "symlink"), s=False) assert symlink.exists assert not symlink.is_link()
def test_ln_s(): symlink = path(file_1_path).ln(os.path.join("xxx", "symlink")) assert symlink.exists assert symlink.is_link()
def test_is_file(): assert path(file_1_path).is_file() assert path(file_2_path).is_file() assert not path(dir_1_path).is_file() assert not path(dir_2_path).is_file()
def test_absolute(): assert os.path.abspath(file_1_path) == path(file_1_path).absolute
def test_exists(): assert path(dir_1_path).exists assert path(file_1_path).exists
def test_split(): path_1 = path("/tmp/directory/file") assert all([isinstance(p, path) for p in path_1.split()])
def test_iter(): dir_content = path(root) assert len([e for e in dir_content]) == len(dir_list + file_list)
def test_touch(): path_string = os.path.join(root, "test") path(path_string).touch() assert os.path.exists(path_string) assert os.path.isfile(path_string)
def test_cp(): file_copy = path(file_1_path).cp(os.path.join(root, "file_copy")) assert os.path.exists(file_copy) dir_copy = path(dir_1_path).cp(os.path.join(root, "dir_copy")) assert os.path.exists(dir_copy)
def test_mkdir(): path_string = os.path.join(root, "test") path(path_string).mkdir() assert os.path.exists(path_string) assert os.path.isdir(path_string)
def test_path(): assert path(root, file_1).exists assert not path(root, file_1, "xxxss").exists
errno = subprocess.call([sys.executable, "runtests.py", "tests.py"]) raise SystemExit(errno) setup( name="os.path2", version=path2.__version__, data_files=[(get_python_lib(), [pth_file])], packages=find_packages(), author="Sebastian Pawluś", author_email="*****@*****.**", url="https://github.com/xando/osome", description="The os.path module replacement, with simple API.", keywords="os path ", license=path2.path("LICENSE").open("r").read(), long_description=path2.path("README.rst").open("r").read(), include_package_data=True, zip_safe=False, platforms=["any"], classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: Implementation :: PyPy", ],
def test_mkdir_p(): path_string = os.path.join(root, "level1", "level2") path(path_string).mkdir(p=True) assert os.path.exists(path_string) assert os.path.isdir(path_string)