From 23845c8cbb570a59d0bd7e95dd5533cfe5644212 Mon Sep 17 00:00:00 2001 From: xuzg Date: Thu, 30 Nov 2017 09:23:40 +0800 Subject: [PATCH] Add test for makedirs --- tests/test_file.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/test_file.py diff --git a/tests/test_file.py b/tests/test_file.py new file mode 100644 index 0000000..3f33417 --- /dev/null +++ b/tests/test_file.py @@ -0,0 +1,32 @@ +import os +from pydu.file import makedirs +import pytest + + +class Testmakedirs(): + def test_makedirs(self,tmpdir): + path = str(tmpdir.join('test')) + makedirs(path) + assert os.path.exists(path) + + def test_makedirs_with_exists_path(self,tmpdir): + path = str(tmpdir.join('test')) + makedirs(path) + with pytest.raises(Exception) as e_info: + makedirs(path, exist_ok=True) + + def test_makedirs_with_ignore_error(self, tmpdir): + path = str(tmpdir.join('test')) + makedirs(path) + makedirs(path, ignore_errors=True) + + def test_makedirs_without_ignore_error(self, tmpdir): + path = str(tmpdir.join('test')) + makedirs(path) + with pytest.raises(Exception) as e_info: + makedirs(path, ignore_errors=False) + + def test_makedirs_with_mutl_dirs(self, tmpdir): + path = str(tmpdir.join('test/test')) + makedirs(path) + assert os.path.exists(path)