7 from ppu_tu import setup, teardown, find_in_path # noqa
8 from ppu_tu import create_files, assert_files_exist, assert_files_not_exist
11 test_prog_path = find_in_path('remove-old-files.py')
14 old_time = time() - 1000 * 24 * 3600 # 1000 days ago
17 def test_remove_old_files():
18 create_files(['test1', 'test2'])
19 assert_files_exist(['test1', 'test2'])
20 os.utime('test2', (old_time, old_time))
21 assert subprocess.call(
22 [sys.executable, test_prog_path, "--older", "100", "."]) == 0
23 assert_files_exist('test1')
24 assert_files_not_exist('test2')
28 create_files(['test3', 'test4'], 'subdir')
29 test3 = os.path.join('subdir', 'test3')
30 test4 = os.path.join('subdir', 'test4')
31 assert_files_exist([test3, test4])
32 os.utime(test4, (old_time, old_time))
33 assert subprocess.call(
34 [sys.executable, test_prog_path, "--older", "100", "."]) == 0
35 assert_files_exist(test3)
36 assert_files_not_exist(test4)
39 def test_remove_empty_directory():
40 create_files(['test3', 'test4'], 'subdir')
41 test3 = os.path.join('subdir', 'test3')
42 test4 = os.path.join('subdir', 'test4')
43 assert_files_exist([test3, test4])
44 os.utime(test3, (old_time, old_time))
45 os.utime(test4, (old_time, old_time))
46 assert subprocess.call(
47 [sys.executable, test_prog_path, "--older", "100", "."]) == 0
48 assert_files_exist('subdir')
49 assert_files_not_exist([test3, test4])
50 assert subprocess.call(
51 [sys.executable, test_prog_path, "-e", "--older", "100", "."]) == 0
52 assert_files_not_exist('subdir')