add test case

This commit is contained in:
agnewee 2017-12-23 17:30:04 +08:00
parent 354b2af680
commit e6e7be1579
1 changed files with 24 additions and 1 deletions

View File

@ -1,12 +1,15 @@
import os
import stat
import time
import tempfile
import pytest
from pydu.platform import WINDOWS
from pydu.system import makedirs, remove, removes, open_file, copy, touch, which
if not WINDOWS:
from pydu.system import link, symlink
from pydu.system import link, symlink, chmod
class TestMakeDirs:
@ -350,3 +353,23 @@ def test_chcp():
assert str(cp) == '<active code page number: 437>'
finally:
windll.kernel32.SetConsoleOutputCP(origin_code)
@pytest.mark.skipif(WINDOWS, reason='Not support on windows')
class TestChmod:
def test_chmod_file(self):
_, t_file = tempfile.mkstemp()
chmod(t_file, 755)
assert oct(os.stat(t_file).st_mode)[-3:] == '755'
def test_chmod_dir(self):
t_dir = tempfile.mkdtemp()
for _ in range(5):
tempfile.mkstemp(dir=t_dir)
chmod(t_dir, 755)
for root, _, files in os.walk(t_dir):
root_path = os.path.abspath(root)
assert oct(os.stat(root_path).st_mode)[-3:0] == '755'
for file_ in files:
assert oct(os.stat(os.path.join(root_path, file_)).st_mode)[-3:0] == '755'