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():
45 create_files(['test3', 'test4'], 'subdir')
46 test3 = os.path.join('subdir', 'test3')
47 test4 = os.path.join('subdir', 'test4')
48 assert_files_exist([test3, test4])
49 os.utime(test3, (old_time, old_time))
50 os.utime(test4, (old_time, old_time))
51 assert subprocess.call(
52 [sys.executable, test_prog_path, "--older", "100", "."]) == 0
53 assert_files_exist('subdir')
54 assert_files_not_exist([test3, test4])
55 assert subprocess.call(
56 [sys.executable, test_prog_path, "-e", "--older", "100", "."]) == 0
57 assert_files_not_exist('subdir')