-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
56 lines (44 loc) · 1.65 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import shutil
import tempfile
import unittest
from win_auto import *
class TestSysFolder(unittest.TestCase):
def setUp(self):
"""Creates a temporary directory before every test."""
self.test_dir = tempfile.mkdtemp()
def tearDown(self):
"""Removes the directory after the test"""
shutil.rmtree(self.test_dir)
def test_create_when_the_folder_doesnt_exist_creates_it(self):
path = os.path.join(self.test_dir, 'some_folder')
assert(not os.path.exists(path))
SysFolder(path).create()
self.assertTrue(os.path.exists(path))
def test_create_when_the_folder_exist_raises_FileExistsError(self):
path = os.path.join(self.test_dir, 'some_folder')
os.makedirs(path)
assert(os.path.exists(path))
with self.assertRaises(FileExistsError):
SysFolder(path).create()
def test_create_folder_when_the_folder_doesnt_exist_creates_it(self):
SysFolder(self.test_dir).create_folder('some_folder')
new_path = os.path.join(self.test_dir, 'some_folder')
self.assertTrue(os.path.exists(new_path))
def test_create_folder_when_the_folder_exists_does_nothing(self):
path = os.path.join(self.test_dir, 'some_folder')
os.makedirs(path)
SysFolder(self.test_dir).create_folder('some_folder')
self.assertTrue(os.path.exists(path))
def test_clear_clears_files(self):
file_ = os.path.join(self.test_dir, 'file.txt')
open(file_, 'w').close()
SysFolder(self.test_dir).clear()
self.assertFalse(os.path.exists(file_))
def test_clear_clears_folders(self):
path = os.path.join(self.test_dir, 'some_folder')
os.makedirs(path)
SysFolder(self.test_dir).clear()
self.assertFalse(os.path.exists(path))
if __name__ == '__main__':
unittest.main()