]> git.phdru.name Git - ppu.git/blob - tests/test_remove_old_files.py
CI(GHActions): Teardown harder
[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 test_prog_path = find_in_path('remove-old-files.py')
12
13
14 old_time = time() - 1000 * 24 * 3600  # 1000 days ago
15
16
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')
25
26
27 def test_recursive():
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)
37
38
39 def test_remove_empty_directory():
40     teardown()
41     try:
42         setup()
43     except OSError:
44         pass
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')