diff --git a/pydu/file.py b/pydu/file.py index 2c72e5b..d648cae 100644 --- a/pydu/file.py +++ b/pydu/file.py @@ -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: diff --git a/tests/test_file.py b/tests/test_file.py index 714ad66..4afc240 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -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)