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')
12 if not test_prog_path:
13 sys.exit("Cannot find remove-old-files.py in %s" % os.environ["PATH"])
16 old_time = time() - 1000 * 24 * 3600 # 1000 days ago
19 def test_remove_old_files():
20 create_files(['test1', 'test2'])
21 assert_files_exist(['test1', 'test2'])
22 os.utime('test2', (old_time, old_time))
23 assert subprocess.call(
24 [sys.executable, test_prog_path, "--older", "100", "."]) == 0
25 assert_files_exist('test1')
26 assert_files_not_exist('test2')
30 create_files(['test3', 'test4'], 'subdir')
31 test3 = os.path.join('subdir', 'test3')
32 test4 = os.path.join('subdir', 'test4')
33 assert_files_exist([test3, test4])
34 os.utime(test4, (old_time, old_time))
35 assert subprocess.call(
36 [sys.executable, test_prog_path, "--older", "100", "."]) == 0
37 assert_files_exist(test3)
38 assert_files_not_exist(test4)
41 def test_remove_empty_directory():
42 create_files(['test3', 'test4'], 'subdir')
43 test3 = os.path.join('subdir', 'test3')
44 test4 = os.path.join('subdir', 'test4')
45 assert_files_exist([test3, test4])
46 os.utime(test3, (old_time, old_time))
47 os.utime(test4, (old_time, old_time))
48 assert subprocess.call(
49 [sys.executable, test_prog_path, "--older", "100", "."]) == 0
50 assert_files_exist('subdir')
51 assert_files_not_exist([test3, test4])
52 assert subprocess.call(
53 [sys.executable, test_prog_path, "-e", "--older", "100", "."]) == 0
54 assert_files_not_exist('subdir')