]> git.phdru.name Git - ppu.git/blob - tests/test_remove_old_files.py
Refactor tests: move common functions to ppu_tu.py
[ppu.git] / tests / test_remove_old_files.py
1 #! /usr/bin/env python
2
3 from time import time
4 import os
5 import subprocess
6 import sys
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
9
10
11 tmp_dir = None
12 old_time = time() - 1000 * 24 * 3600  # 1000 days ago
13
14 test_prog_path = find_in_path('remove-old-files.py')
15 if not test_prog_path:
16     sys.exit("Cannot find remove-old-files.py in %s" % os.environ["PATH"])
17
18
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')
27
28
29 def test_recursive():
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)
39
40
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')