]> git.phdru.name Git - ppu.git/blob - tests/test_remove_old_files.py
Build(GHActions): Use `checkout@v4` instead of outdated `v2`
[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     create_files(['test3', 'test4'], 'subdir')
41     test3 = os.path.join('subdir', 'test3')
42     test4 = os.path.join('subdir', 'test4')
43     assert_files_exist([test3, test4])
44     os.utime(test3, (old_time, old_time))
45     os.utime(test4, (old_time, old_time))
46     assert subprocess.call(
47         [sys.executable, test_prog_path, "--older", "100", "."]) == 0
48     assert_files_exist('subdir')
49     assert_files_not_exist([test3, test4])
50     assert subprocess.call(
51         [sys.executable, test_prog_path, "-e", "--older", "100", "."]) == 0
52     assert_files_not_exist('subdir')