1
1
import os .path
2
2
3
+
4
+
5
+
6
+
3
7
from boltons import fileutils
4
8
from boltons .fileutils import FilePerms , iter_find_files
5
9
@@ -33,4 +37,56 @@ def _to_baseless_list(paths):
33
37
34
38
boltons_parent = os .path .dirname (BOLTONS_PATH )
35
39
assert 'fileutils.py' in _to_baseless_list (iter_find_files (boltons_parent , patterns = ['*.py' ]))
36
- assert 'fileutils.py' not in _to_baseless_list (iter_find_files (boltons_parent , patterns = ['*.py' ], max_depth = 0 ))
40
+ assert 'fileutils.py' not in _to_baseless_list (iter_find_files (boltons_parent , patterns = ['*.py' ], max_depth = 0 ))
41
+
42
+
43
+ def test_rotate_file_no_rotation (tmp_path ):
44
+ file_path = tmp_path / 'test_file.txt'
45
+ fileutils .rotate_file (file_path )
46
+ assert not file_path .exists ()
47
+
48
+
49
+ def test_rotate_file_one_rotation (tmp_path ):
50
+ file_path = tmp_path / 'test_file.txt'
51
+ file_path .write_text ('test content' )
52
+ assert file_path .exists ()
53
+
54
+ fileutils .rotate_file (file_path )
55
+ assert not file_path .exists ()
56
+ assert (tmp_path / 'test_file.1.txt' ).exists ()
57
+
58
+
59
+ def test_rotate_file_full_rotation (tmp_path ):
60
+ file_path = tmp_path / 'test_file.txt'
61
+ file_path .write_text ('test content 0' )
62
+ for i in range (1 , 5 ):
63
+ cur_path = tmp_path / f'test_file.{ i } .txt'
64
+ cur_path .write_text (f'test content { i } ' )
65
+ assert cur_path .exists ()
66
+
67
+ fileutils .rotate_file (file_path , keep = 5 )
68
+ assert not file_path .exists ()
69
+
70
+ for i in range (1 , 5 ):
71
+ cur_path = tmp_path / f'test_file.{ i } .txt'
72
+ assert cur_path .read_text () == f'test content { i - 1 } '
73
+
74
+ assert not (tmp_path / 'test_file.5.txt' ).exists ()
75
+
76
+ def test_rotate_file_full_rotation_no_ext (tmp_path ):
77
+ file_path = tmp_path / 'test_file'
78
+ file_path .write_text ('test content 0' )
79
+ for i in range (1 , 5 ):
80
+ cur_path = tmp_path / f'test_file.{ i } '
81
+ cur_path .write_text (f'test content { i } ' )
82
+ assert cur_path .exists ()
83
+
84
+ fileutils .rotate_file (file_path , keep = 5 )
85
+ assert not file_path .exists ()
86
+
87
+ for i in range (1 , 5 ):
88
+ cur_path = tmp_path / f'test_file.{ i } '
89
+ assert cur_path .read_text () == f'test content { i - 1 } '
90
+
91
+ assert not (tmp_path / 'test_file.5' ).exists ()
92
+
0 commit comments