]> git.phdru.name Git - ppu.git/blob - tests/test_rof.py
TODO: Add options to include/exclude files
[ppu.git] / tests / test_rof.py
1 #! /usr/bin/env python
2
3 import shutil
4 import os
5 from tempfile import mkdtemp
6
7
8 tmp_dir = None
9
10
11 def setup():
12     global tmp_dir
13     tmp_dir = mkdtemp()
14     os.chdir(tmp_dir)
15
16
17 def teardown():
18     os.chdir(os.sep)  # To the root of the FS
19     shutil.rmtree(tmp_dir)
20
21
22 def create_files(files, subdirectory=None):
23     if subdirectory:
24         os.makedirs(subdirectory)
25     else:
26         subdirectory = ''
27     for fname in files:
28         with open(os.path.join(subdirectory, fname), 'w'):
29             pass
30
31
32 def _test_files_exist(files):
33     for fname in files:
34         assert os.path.exists(fname)
35
36
37 def _test_files_not_exist(files):
38     for fname in files:
39         assert not os.path.exists(fname)
40
41
42 def test_rof():
43     create_files(['test1', 'test2'])
44     _test_files_exist(['test1', 'test2'])
45     os.utime('test2', (0, 0))
46     assert os.system("remove-old-files.py --older 100 .") == 0
47     _test_files_exist(['test1'])
48     _test_files_not_exist(['test2'])
49
50
51 def test_recursive():
52     create_files(['test3', 'test4'], 'subdir')
53     test3 = os.path.join('subdir', 'test3')
54     test4 = os.path.join('subdir', 'test4')
55     _test_files_exist([test3, test4])
56     os.utime(test4, (0, 0))
57     assert os.system("remove-old-files.py --older 100 .") == 0
58     _test_files_exist([test3])
59     _test_files_not_exist([test4])