From e6e7be1579a9513145c284da83dcec3c097dc426 Mon Sep 17 00:00:00 2001 From: agnewee Date: Sat, 23 Dec 2017 17:30:04 +0800 Subject: [PATCH] add test case --- tests/test_system.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/test_system.py b/tests/test_system.py index 043f4b3..c934851 100644 --- a/tests/test_system.py +++ b/tests/test_system.py @@ -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) == '' 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' +