add test for file.link

This commit is contained in:
Prodesire 2017-12-02 11:09:05 +08:00
parent afe7fa6bdc
commit d60bc2e3b8
2 changed files with 24 additions and 1 deletions

View File

@ -92,6 +92,11 @@ def copy(src, dst, ignore_errors=False, follow_symlinks=True):
raise OSError('Copy {} to {} error'.format(src, dst))
def touch(path):
with open(path, 'w'):
pass
if not WINDOWS:
def link(src, dst, overwrite=False, ignore_errors=False):
try:

View File

@ -1,6 +1,10 @@
import os
import pytest
from pydu.file import makedirs
from pydu.platform import WINDOWS
from pydu.file import makedirs, remove, removes, open_file, copy, touch
if not WINDOWS:
from pydu.file import link
class TestMakeDirs:
@ -35,3 +39,17 @@ class TestMakeDirs:
assert os.path.exists(path)
def test_touch(tmpdir):
path = str(tmpdir.join('test'))
touch(path)
assert os.path.isfile(path)
@pytest.mark.skipIf(WINDOWS)
class TestLink:
def test_link(self, tmpdir):
src = str(tmpdir.join('src'))
dst = str(tmpdir.join('dst'))
touch(src)
link(src, dst)
assert os.path.exists(dst)