-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_modtime_pecker.py
More file actions
71 lines (57 loc) · 2.36 KB
/
test_modtime_pecker.py
File metadata and controls
71 lines (57 loc) · 2.36 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import unittest
from modtime_pecker import *
class TestCli(unittest.TestCase):
def test_path_noargs(self):
sys.argv = ['modtime_pecker.py']
self.assertEqual(cli(), None)
def test_path_onearg(self):
sys.argv = ['modtime_pecker.py', '-p', 'C:\\']
self.assertEqual(cli(), None)
def test_path_multiargs(self):
sys.argv = ['modtime_pecker.py', '-p', 'C:\\', 'D:\\', 'E:\\']
self.assertEqual(cli(), None)
def test_path_novalue(self):
sys.argv = ['modtime_pecker.py', '-p']
with self.assertRaises(SystemExit):
cli()
# def test_gui(self):
# sys.argv = ['modtime_pecker.py', '-g']
# self.assertEqual(cli(), None)
#
# def test_gui_with_other_args(self):
# sys.argv = ['modtime_pecker.py', '-g', '-p', 'C:\\']
# self.assertEqual(cli(), None)
def test_import(self):
# 在脚本所在文件夹下创建一个txt文件,写入路径
paths = "C:\\Users\nC:\\Program Files"
with open('paths.txt', 'w') as f:
f.write(paths)
sys.argv = ['modtime_pecker.py', '-i', 'paths.txt',
'-p', 'C:\\', 'C:\\', 'D:\\']
self.assertEqual(cli(), None)
def test_multiimport(self):
paths1 = "C:\\Users\nC:\\Program Files"
paths2 = "C:\\Windows\nC:\\Program Files"
with open('paths1.txt', 'w') as f:
f.write(paths1)
with open('paths2.txt', 'w') as f:
f.write(paths2)
sys.argv = ['modtime_pecker.py', '-i', 'paths1.txt', 'paths2.txt',
'-p', 'C:\\', 'C:\\', 'E:\\']
self.assertEqual(cli(), None)
def test_invalid_import(self):
sys.argv = ['modtime_pecker.py', '-i', 'paths.txt', 'invalid.txt']
with self.assertRaises(FileNotFoundError):
cli()
def test_current(self):
sys.argv = ['modtime_pecker.py', '-c', '-p', 'C:\\']
self.assertEqual(cli(), None)
class TestGetLatestModificationTime(unittest.TestCase):
def test_valid_path(self):
print(get_latest_modification_time('C:\\Program Files\\Windows Defender')[0])
self.assertTrue(True)
def test_invalid_path(self):
with self.assertRaises(FileNotFoundError):
print(get_latest_modification_time('C:\\Progr4m Files\\Wind0ws Defender')[0])
if __name__ == '__main__':
unittest.main()