Browse Source

Rework logging/verbosity system (#90)

Looks great, merged! Thanks again for all your hard work here.
floli 3 months ago
parent
commit
7252b8d614

+ 2
- 1
AUTHORS View File

@@ -1,11 +1,12 @@
1 1
 Dan Helfman <witten@torsion.org>: Main developer
2 2
 
3 3
 Alexander Görtz: Python 3 compatibility
4
+Florian Lindner: Logging rewrite
4 5
 Henning Schroeder: Copy editing
5 6
 Johannes Feichtner: Support for user hooks
6 7
 Michele Lazzeri: Custom archive names
8
+Nick Whyte: Support prefix filtering for archive consistency checks
7 9
 newtonne: Read encryption password from external file
8 10
 Robin `ypid` Schneider: Support additional options of Borg
9 11
 Scott Squires: Custom archive names
10 12
 Thomas LÉVEIL: Support for a keep_minutely prune option. Support for the --json option
11
-Nick Whyte: Support prefix filtering for archive consistency checks

+ 2
- 0
NEWS View File

@@ -4,6 +4,8 @@
4 4
  * #88: Fix declared pykwalify compatibility version range in setup.py to prevent use of ancient
5 5
    versions of pykwalify with large version numbers.
6 6
  * #89: Pass --show-rc option to Borg when at highest verbosity level.
7
+ * #90: Rewrite of logging system. Now verbosity flags passed to borg are derived from borgmatic's
8
+   log level. Note that the output of borgmatic might slightly change.
7 9
 
8 10
 1.2.2
9 11
  * #85: Fix compatibility issue between pykwalify and ruamel.yaml 0.15.52, which manifested in

+ 11
- 11
borgmatic/borg/check.py View File

@@ -3,7 +3,6 @@ import os
3 3
 import subprocess
4 4
 
5 5
 from borgmatic.borg import extract
6
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
7 6
 
8 7
 
9 8
 DEFAULT_CHECKS = ('repository', 'archives')
@@ -74,12 +73,10 @@ def _make_check_flags(checks, check_last=None, prefix=None):
74 73
     ) + last_flags + prefix_flags
75 74
 
76 75
 
77
-def check_archives(verbosity, repository, storage_config, consistency_config, local_path='borg',
78
-                   remote_path=None):
76
+def check_archives(repository, storage_config, consistency_config, local_path='borg', remote_path=None):
79 77
     '''
80
-    Given a verbosity flag, a local or remote repository path, a storage config dict, a consistency
81
-    config dict, and a local/remote commands to run, check the contained Borg archives for
82
-    consistency.
78
+    Given a local or remote repository path, a storage config dict, a consistency config dict, 
79
+    and a local/remote commands to run, check the contained Borg archives for consistency.
83 80
 
84 81
     If there are no consistency checks to run, skip running them.
85 82
     '''
@@ -91,10 +88,13 @@ def check_archives(verbosity, repository, storage_config, consistency_config, lo
91 88
         remote_path_flags = ('--remote-path', remote_path) if remote_path else ()
92 89
         lock_wait = storage_config.get('lock_wait', None)
93 90
         lock_wait_flags = ('--lock-wait', str(lock_wait)) if lock_wait else ()
94
-        verbosity_flags = {
95
-            VERBOSITY_SOME: ('--info',),
96
-            VERBOSITY_LOTS: ('--debug', '--show-rc'),
97
-        }.get(verbosity, ())
91
+
92
+        verbosity_flags = ()
93
+        if logger.isEnabledFor(logging.INFO):
94
+            verbosity_flags = ('--info',)
95
+        if logger.isEnabledFor(logging.DEBUG):
96
+            verbosity_flags = ('--debug', '--show-rc')
97
+
98 98
         prefix = consistency_config.get('prefix')
99 99
 
100 100
         full_command = (
@@ -109,4 +109,4 @@ def check_archives(verbosity, repository, storage_config, consistency_config, lo
109 109
         subprocess.check_call(full_command, stdout=stdout, stderr=subprocess.STDOUT)
110 110
 
111 111
     if 'extract' in checks:
112
-        extract.extract_last_archive_dry_run(verbosity, repository, lock_wait, local_path, remote_path)
112
+        extract.extract_last_archive_dry_run(repository, lock_wait, local_path, remote_path)

+ 5
- 7
borgmatic/borg/create.py View File

@@ -5,8 +5,6 @@ import os
5 5
 import subprocess
6 6
 import tempfile
7 7
 
8
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
9
-
10 8
 
11 9
 logger = logging.getLogger(__name__)
12 10
 
@@ -105,7 +103,7 @@ def _make_exclude_flags(location_config, exclude_filename=None):
105 103
 
106 104
 
107 105
 def create_archive(
108
-    verbosity, dry_run, repository, location_config, storage_config, local_path='borg', remote_path=None,
106
+    dry_run, repository, location_config, storage_config, local_path='borg', remote_path=None,
109 107
 ):
110 108
     '''
111 109
     Given vebosity/dry-run flags, a local or remote repository path, a location config dict, and a
@@ -150,10 +148,10 @@ def create_archive(
150 148
         + (('--remote-path', remote_path) if remote_path else ())
151 149
         + (('--umask', str(umask)) if umask else ())
152 150
         + (('--lock-wait', str(lock_wait)) if lock_wait else ())
153
-        + {
154
-            VERBOSITY_SOME: ('--info',) if dry_run else ('--info', '--stats'),
155
-            VERBOSITY_LOTS: ('--debug', '--list', '--show-rc') if dry_run else ('--debug', '--list', '--show-rc', '--stats'),
156
-        }.get(verbosity, ())
151
+        + (('--list', '--filter', 'AME',) if logger.isEnabledFor(logging.INFO) else ())
152
+        + (( '--info',) if logger.getEffectiveLevel() == logging.INFO else ())
153
+        + (('--stats',) if not dry_run and logger.isEnabledFor(logging.INFO) else ())
154
+        + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
157 155
         + (('--dry-run',) if dry_run else ())
158 156
     )
159 157
 

+ 8
- 8
borgmatic/borg/extract.py View File

@@ -2,23 +2,23 @@ import logging
2 2
 import sys
3 3
 import subprocess
4 4
 
5
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
6
-
7 5
 
8 6
 logger = logging.getLogger(__name__)
9 7
 
10 8
 
11
-def extract_last_archive_dry_run(verbosity, repository, lock_wait=None, local_path='borg', remote_path=None):
9
+def extract_last_archive_dry_run(repository, lock_wait=None, local_path='borg', remote_path=None):
12 10
     '''
13 11
     Perform an extraction dry-run of just the most recent archive. If there are no archives, skip
14 12
     the dry-run.
15 13
     '''
16 14
     remote_path_flags = ('--remote-path', remote_path) if remote_path else ()
17 15
     lock_wait_flags = ('--lock-wait', str(lock_wait)) if lock_wait else ()
18
-    verbosity_flags = {
19
-        VERBOSITY_SOME: ('--info',),
20
-        VERBOSITY_LOTS: ('--debug', '--show-rc'),
21
-    }.get(verbosity, ())
16
+    verbosity_flags = ()
17
+    if logger.isEnabledFor(logging.DEBUG):
18
+        verbosity_flags = ('--debug', '--show-rc')
19
+    elif logger.isEnabledFor(logging.INFO):
20
+        verbosity_flags = ('--info',)
21
+    
22 22
 
23 23
     full_list_command = (
24 24
         local_path, 'list',
@@ -32,7 +32,7 @@ def extract_last_archive_dry_run(verbosity, repository, lock_wait=None, local_pa
32 32
     if not last_archive_name:
33 33
         return
34 34
 
35
-    list_flag = ('--list',) if verbosity == VERBOSITY_LOTS else ()
35
+    list_flag = ('--list',) if logger.isEnabledFor(logging.DEBUG) else ()
36 36
     full_extract_command = (
37 37
         local_path, 'extract',
38 38
         '--dry-run',

+ 4
- 10
borgmatic/borg/info.py View File

@@ -1,17 +1,13 @@
1 1
 import logging
2 2
 import subprocess
3 3
 
4
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
5
-
6 4
 
7 5
 logger = logging.getLogger(__name__)
8 6
 
9 7
 
10
-def display_archives_info(
11
-    verbosity, repository, storage_config, local_path='borg', remote_path=None, json=False
12
-):
8
+def display_archives_info(repository, storage_config, local_path='borg', remote_path=None, json=False):
13 9
     '''
14
-    Given a verbosity flag, a local or remote repository path, and a storage config dict,
10
+    Given a local or remote repository path, and a storage config dict,
15 11
     display summary information for Borg archives in the repository.
16 12
     '''
17 13
     lock_wait = storage_config.get('lock_wait', None)
@@ -20,11 +16,9 @@ def display_archives_info(
20 16
         (local_path, 'info', repository)
21 17
         + (('--remote-path', remote_path) if remote_path else ())
22 18
         + (('--lock-wait', str(lock_wait)) if lock_wait else ())
19
+        + (('--info',)  if logger.getEffectiveLevel() == logging.INFO else ())
20
+        + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
23 21
         + (('--json',) if json else ())
24
-        + {
25
-            VERBOSITY_SOME: ('--info',),
26
-            VERBOSITY_LOTS: ('--debug', '--show-rc'),
27
-        }.get(verbosity, ())
28 22
     )
29 23
 
30 24
     logger.debug(' '.join(full_command))

+ 4
- 11
borgmatic/borg/list.py View File

@@ -1,17 +1,13 @@
1 1
 import logging
2 2
 import subprocess
3 3
 
4
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
5
-
6 4
 
7 5
 logger = logging.getLogger(__name__)
8 6
 
9 7
 
10
-def list_archives(
11
-    verbosity, repository, storage_config, local_path='borg', remote_path=None, json=False
12
-):
8
+def list_archives(repository, storage_config, local_path='borg', remote_path=None, json=False):
13 9
     '''
14
-    Given a verbosity flag, a local or remote repository path, and a storage config dict,
10
+    Given a local or remote repository path, and a storage config dict,
15 11
     list Borg archives in the repository.
16 12
     '''
17 13
     lock_wait = storage_config.get('lock_wait', None)
@@ -20,13 +16,10 @@ def list_archives(
20 16
         (local_path, 'list', repository)
21 17
         + (('--remote-path', remote_path) if remote_path else ())
22 18
         + (('--lock-wait', str(lock_wait)) if lock_wait else ())
19
+        + (('--info',)  if logger.getEffectiveLevel() == logging.INFO  else ())
20
+        + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
23 21
         + (('--json',) if json else ())
24
-        + {
25
-            VERBOSITY_SOME: ('--info',),
26
-            VERBOSITY_LOTS: ('--debug', '--show-rc'),
27
-        }.get(verbosity, ())
28 22
     )
29
-
30 23
     logger.debug(' '.join(full_command))
31 24
 
32 25
     output = subprocess.check_output(full_command)

+ 5
- 8
borgmatic/borg/prune.py View File

@@ -1,7 +1,6 @@
1 1
 import logging
2 2
 import subprocess
3 3
 
4
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
5 4
 
6 5
 
7 6
 logger = logging.getLogger(__name__)
@@ -32,10 +31,9 @@ def _make_prune_flags(retention_config):
32 31
     )
33 32
 
34 33
 
35
-def prune_archives(verbosity, dry_run, repository, storage_config, retention_config,
36
-                   local_path='borg', remote_path=None):
34
+def prune_archives(dry_run, repository, storage_config, retention_config, local_path='borg', remote_path=None):
37 35
     '''
38
-    Given verbosity/dry-run flags, a local or remote repository path, a storage config dict, and a
36
+    Given dry-run flag, a local or remote repository path, a storage config dict, and a
39 37
     retention config dict, prune Borg archives according to the retention policy specified in that
40 38
     configuration.
41 39
     '''
@@ -54,10 +52,9 @@ def prune_archives(verbosity, dry_run, repository, storage_config, retention_con
54 52
         + (('--remote-path', remote_path) if remote_path else ())
55 53
         + (('--umask', str(umask)) if umask else ())
56 54
         + (('--lock-wait', str(lock_wait)) if lock_wait else ())
57
-        + {
58
-            VERBOSITY_SOME: ('--info', '--stats',),
59
-            VERBOSITY_LOTS: ('--debug', '--stats', '--list', '--show-rc'),
60
-        }.get(verbosity, ())
55
+        + (('--stats',) if not dry_run and logger.isEnabledFor(logging.INFO) else ())
56
+        + (( '--info',) if logger.getEffectiveLevel() == logging.INFO else ())
57
+        + (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
61 58
         + (('--dry-run',) if dry_run else ())
62 59
     )
63 60
 

+ 1
- 6
borgmatic/commands/borgmatic.py View File

@@ -10,7 +10,7 @@ from borgmatic.borg import check as borg_check, create as borg_create, prune as
10 10
 from borgmatic.commands import hook
11 11
 from borgmatic.config import collect, convert, validate
12 12
 from borgmatic.signals import configure_signals
13
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS, verbosity_to_log_level
13
+from borgmatic.verbosity import verbosity_to_log_level
14 14
 
15 15
 
16 16
 logger = logging.getLogger(__name__)
@@ -165,7 +165,6 @@ def _run_commands_on_repository(
165 165
     if args.prune:
166 166
         logger.info('{}: Pruning archives{}'.format(repository, dry_run_label))
167 167
         borg_prune.prune_archives(
168
-            args.verbosity,
169 168
             args.dry_run,
170 169
             repository,
171 170
             storage,
@@ -176,7 +175,6 @@ def _run_commands_on_repository(
176 175
     if args.create:
177 176
         logger.info('{}: Creating archive{}'.format(repository, dry_run_label))
178 177
         borg_create.create_archive(
179
-            args.verbosity,
180 178
             args.dry_run,
181 179
             repository,
182 180
             location,
@@ -187,7 +185,6 @@ def _run_commands_on_repository(
187 185
     if args.check:
188 186
         logger.info('{}: Running consistency checks'.format(repository))
189 187
         borg_check.check_archives(
190
-            args.verbosity,
191 188
             repository,
192 189
             storage,
193 190
             consistency,
@@ -197,7 +194,6 @@ def _run_commands_on_repository(
197 194
     if args.list:
198 195
         logger.info('{}: Listing archives'.format(repository))
199 196
         output = borg_list.list_archives(
200
-            args.verbosity,
201 197
             repository,
202 198
             storage,
203 199
             local_path=local_path,
@@ -211,7 +207,6 @@ def _run_commands_on_repository(
211 207
     if args.info:
212 208
         logger.info('{}: Displaying summary info for archives'.format(repository))
213 209
         output = borg_info.display_archives_info(
214
-            args.verbosity,
215 210
             repository,
216 211
             storage,
217 212
             local_path=local_path,

+ 6
- 14
borgmatic/tests/unit/borg/test_check.py View File

@@ -1,12 +1,11 @@
1 1
 from subprocess import STDOUT
2
-import sys
2
+import logging, sys
3 3
 
4 4
 from flexmock import flexmock
5 5
 import pytest
6 6
 
7 7
 from borgmatic.borg import check as module
8
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
9
-
8
+from borgmatic.tests.unit.test_verbosity import insert_logging_mock
10 9
 
11 10
 def insert_subprocess_mock(check_call_command, **kwargs):
12 11
     subprocess = flexmock(module.subprocess)
@@ -125,7 +124,6 @@ def test_check_archives_calls_borg_with_parameters(checks):
125 124
     flexmock(module.os).should_receive('devnull')
126 125
 
127 126
     module.check_archives(
128
-        verbosity=None,
129 127
         repository='repo',
130 128
         storage_config={},
131 129
         consistency_config=consistency_config,
@@ -142,43 +140,42 @@ def test_check_archives_with_extract_check_calls_extract_only():
142 140
     insert_subprocess_never()
143 141
 
144 142
     module.check_archives(
145
-        verbosity=None,
146 143
         repository='repo',
147 144
         storage_config={},
148 145
         consistency_config=consistency_config,
149 146
     )
150 147
 
151 148
 
152
-def test_check_archives_with_verbosity_some_calls_borg_with_info_parameter():
149
+def test_check_archives_with_log_info_calls_borg_with_info_parameter():
153 150
     checks = ('repository',)
154 151
     consistency_config = {'check_last': None}
155 152
     flexmock(module).should_receive('_parse_checks').and_return(checks)
156 153
     flexmock(module).should_receive('_make_check_flags').and_return(())
154
+    insert_logging_mock(logging.INFO)
157 155
     insert_subprocess_mock(
158 156
         ('borg', 'check', 'repo', '--info'),
159 157
         stdout=None, stderr=STDOUT,
160 158
     )
161 159
 
162 160
     module.check_archives(
163
-        verbosity=VERBOSITY_SOME,
164 161
         repository='repo',
165 162
         storage_config={},
166 163
         consistency_config=consistency_config,
167 164
     )
168 165
 
169 166
 
170
-def test_check_archives_with_verbosity_lots_calls_borg_with_debug_parameter():
167
+def test_check_archives_with_log_debug_calls_borg_with_debug_parameter():
171 168
     checks = ('repository',)
172 169
     consistency_config = {'check_last': None}
173 170
     flexmock(module).should_receive('_parse_checks').and_return(checks)
174 171
     flexmock(module).should_receive('_make_check_flags').and_return(())
172
+    insert_logging_mock(logging.DEBUG)
175 173
     insert_subprocess_mock(
176 174
         ('borg', 'check', 'repo', '--debug', '--show-rc'),
177 175
         stdout=None, stderr=STDOUT,
178 176
     )
179 177
 
180 178
     module.check_archives(
181
-        verbosity=VERBOSITY_LOTS,
182 179
         repository='repo',
183 180
         storage_config={},
184 181
         consistency_config=consistency_config,
@@ -191,7 +188,6 @@ def test_check_archives_without_any_checks_bails():
191 188
     insert_subprocess_never()
192 189
 
193 190
     module.check_archives(
194
-        verbosity=None,
195 191
         repository='repo',
196 192
         storage_config={},
197 193
         consistency_config=consistency_config,
@@ -213,7 +209,6 @@ def test_check_archives_with_local_path_calls_borg_via_local_path():
213 209
     flexmock(module.os).should_receive('devnull')
214 210
 
215 211
     module.check_archives(
216
-        verbosity=None,
217 212
         repository='repo',
218 213
         storage_config={},
219 214
         consistency_config=consistency_config,
@@ -236,7 +231,6 @@ def test_check_archives_with_remote_path_calls_borg_with_remote_path_parameters(
236 231
     flexmock(module.os).should_receive('devnull')
237 232
 
238 233
     module.check_archives(
239
-        verbosity=None,
240 234
         repository='repo',
241 235
         storage_config={},
242 236
         consistency_config=consistency_config,
@@ -259,7 +253,6 @@ def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
259 253
     flexmock(module.os).should_receive('devnull')
260 254
 
261 255
     module.check_archives(
262
-        verbosity=None,
263 256
         repository='repo',
264 257
         storage_config={'lock_wait': 5},
265 258
         consistency_config=consistency_config,
@@ -283,7 +276,6 @@ def test_check_archives_with_retention_prefix():
283 276
     flexmock(module.os).should_receive('devnull')
284 277
 
285 278
     module.check_archives(
286
-        verbosity=None,
287 279
         repository='repo',
288 280
         storage_config={},
289 281
         consistency_config=consistency_config,

+ 19
- 35
borgmatic/tests/unit/borg/test_create.py View File

@@ -1,9 +1,9 @@
1
-import os
1
+import logging, os
2 2
 
3 3
 from flexmock import flexmock
4 4
 
5 5
 from borgmatic.borg import create as module
6
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
6
+from borgmatic.tests.unit.test_verbosity import insert_logging_mock
7 7
 
8 8
 
9 9
 def test_initialize_environment_with_passcommand_should_set_environment():
@@ -216,7 +216,6 @@ def test_create_archive_calls_borg_with_parameters():
216 216
     insert_subprocess_mock(CREATE_COMMAND)
217 217
 
218 218
     module.create_archive(
219
-        verbosity=None,
220 219
         dry_run=False,
221 220
         repository='repo',
222 221
         location_config={
@@ -237,7 +236,6 @@ def test_create_archive_with_patterns_calls_borg_with_patterns():
237 236
     insert_subprocess_mock(CREATE_COMMAND + pattern_flags)
238 237
 
239 238
     module.create_archive(
240
-        verbosity=None,
241 239
         dry_run=False,
242 240
         repository='repo',
243 241
         location_config={
@@ -258,7 +256,6 @@ def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
258 256
     insert_subprocess_mock(CREATE_COMMAND + exclude_flags)
259 257
 
260 258
     module.create_archive(
261
-        verbosity=None,
262 259
         dry_run=False,
263 260
         repository='repo',
264 261
         location_config={
@@ -270,16 +267,16 @@ def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
270 267
     )
271 268
 
272 269
 
273
-def test_create_archive_with_verbosity_some_calls_borg_with_info_parameter():
270
+def test_create_archive_with_log_info_calls_borg_with_info_parameter():
274 271
     flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
275 272
     flexmock(module).should_receive('_write_pattern_file').and_return(None)
276 273
     flexmock(module).should_receive('_make_pattern_flags').and_return(())
277 274
     flexmock(module).should_receive('_make_pattern_flags').and_return(())
278 275
     flexmock(module).should_receive('_make_exclude_flags').and_return(())
279
-    insert_subprocess_mock(CREATE_COMMAND + ('--info', '--stats',))
280
-
276
+    insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--stats',))
277
+    insert_logging_mock(logging.INFO)
278
+    
281 279
     module.create_archive(
282
-        verbosity=VERBOSITY_SOME,
283 280
         dry_run=False,
284 281
         repository='repo',
285 282
         location_config={
@@ -291,15 +288,15 @@ def test_create_archive_with_verbosity_some_calls_borg_with_info_parameter():
291 288
     )
292 289
 
293 290
 
294
-def test_create_archive_with_verbosity_lots_calls_borg_with_debug_parameter():
291
+def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
295 292
     flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
296 293
     flexmock(module).should_receive('_write_pattern_file').and_return(None)
297 294
     flexmock(module).should_receive('_make_pattern_flags').and_return(())
298 295
     flexmock(module).should_receive('_make_exclude_flags').and_return(())
299
-    insert_subprocess_mock(CREATE_COMMAND + ('--debug', '--list', '--show-rc', '--stats'))
296
+    insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME','--stats', '--debug', '--show-rc'))
297
+    insert_logging_mock(logging.DEBUG)
300 298
 
301 299
     module.create_archive(
302
-        verbosity=VERBOSITY_LOTS,
303 300
         dry_run=False,
304 301
         repository='repo',
305 302
         location_config={
@@ -320,7 +317,6 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
320 317
     insert_subprocess_mock(CREATE_COMMAND + ('--dry-run',))
321 318
 
322 319
     module.create_archive(
323
-        verbosity=None,
324 320
         dry_run=True,
325 321
         repository='repo',
326 322
         location_config={
@@ -332,16 +328,18 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
332 328
     )
333 329
 
334 330
 
335
-def test_create_archive_with_dry_run_and_verbosity_some_calls_borg_without_stats_parameter():
331
+def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_parameter():
332
+    """ --dry-run and --stats are mutually exclusive, see:
333
+    https://borgbackup.readthedocs.io/en/stable/usage/create.html#description """
336 334
     flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
337 335
     flexmock(module).should_receive('_write_pattern_file').and_return(None)
338 336
     flexmock(module).should_receive('_make_pattern_flags').and_return(())
339 337
     flexmock(module).should_receive('_make_pattern_flags').and_return(())
340 338
     flexmock(module).should_receive('_make_exclude_flags').and_return(())
341
-    insert_subprocess_mock(CREATE_COMMAND + ('--info', '--dry-run'))
339
+    insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--dry-run'))
340
+    insert_logging_mock(logging.INFO)
342 341
 
343 342
     module.create_archive(
344
-        verbosity=VERBOSITY_SOME,
345 343
         dry_run=True,
346 344
         repository='repo',
347 345
         location_config={
@@ -353,16 +351,18 @@ def test_create_archive_with_dry_run_and_verbosity_some_calls_borg_without_stats
353 351
     )
354 352
 
355 353
 
356
-def test_create_archive_with_dry_run_and_verbosity_lots_calls_borg_without_stats_parameter():
354
+def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_parameter():
355
+    """ --dry-run and --stats are mutually exclusive, see:
356
+    https://borgbackup.readthedocs.io/en/stable/usage/create.html#description """
357 357
     flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
358 358
     flexmock(module).should_receive('_write_pattern_file').and_return(None)
359 359
     flexmock(module).should_receive('_make_pattern_flags').and_return(())
360 360
     flexmock(module).should_receive('_make_pattern_flags').and_return(())
361 361
     flexmock(module).should_receive('_make_exclude_flags').and_return(())
362
-    insert_subprocess_mock(CREATE_COMMAND + ('--debug', '--list', '--show-rc', '--dry-run'))
362
+    insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--debug', '--show-rc', '--dry-run'))
363
+    insert_logging_mock(logging.DEBUG)
363 364
 
364 365
     module.create_archive(
365
-        verbosity=VERBOSITY_LOTS,
366 366
         dry_run=True,
367 367
         repository='repo',
368 368
         location_config={
@@ -382,7 +382,6 @@ def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_inte
382 382
     insert_subprocess_mock(CREATE_COMMAND + ('--checkpoint-interval', '600'))
383 383
 
384 384
     module.create_archive(
385
-        verbosity=None,
386 385
         dry_run=False,
387 386
         repository='repo',
388 387
         location_config={
@@ -402,7 +401,6 @@ def test_create_archive_with_compression_calls_borg_with_compression_parameters(
402 401
     insert_subprocess_mock(CREATE_COMMAND + ('--compression', 'rle'))
403 402
 
404 403
     module.create_archive(
405
-        verbosity=None,
406 404
         dry_run=False,
407 405
         repository='repo',
408 406
         location_config={
@@ -422,7 +420,6 @@ def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_
422 420
     insert_subprocess_mock(CREATE_COMMAND + ('--remote-ratelimit', '100'))
423 421
 
424 422
     module.create_archive(
425
-        verbosity=None,
426 423
         dry_run=False,
427 424
         repository='repo',
428 425
         location_config={
@@ -442,7 +439,6 @@ def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_par
442 439
     insert_subprocess_mock(CREATE_COMMAND + ('--one-file-system',))
443 440
 
444 441
     module.create_archive(
445
-        verbosity=None,
446 442
         dry_run=False,
447 443
         repository='repo',
448 444
         location_config={
@@ -463,7 +459,6 @@ def test_create_archive_with_bsd_flags_true_calls_borg_without_nobsdflags_parame
463 459
     insert_subprocess_mock(CREATE_COMMAND)
464 460
 
465 461
     module.create_archive(
466
-        verbosity=None,
467 462
         dry_run=False,
468 463
         repository='repo',
469 464
         location_config={
@@ -484,7 +479,6 @@ def test_create_archive_with_bsd_flags_false_calls_borg_with_nobsdflags_paramete
484 479
     insert_subprocess_mock(CREATE_COMMAND + ('--nobsdflags',))
485 480
 
486 481
     module.create_archive(
487
-        verbosity=None,
488 482
         dry_run=False,
489 483
         repository='repo',
490 484
         location_config={
@@ -505,7 +499,6 @@ def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters(
505 499
     insert_subprocess_mock(CREATE_COMMAND + ('--files-cache', 'ctime,size'))
506 500
 
507 501
     module.create_archive(
508
-        verbosity=None,
509 502
         dry_run=False,
510 503
         repository='repo',
511 504
         location_config={
@@ -526,7 +519,6 @@ def test_create_archive_with_local_path_calls_borg_via_local_path():
526 519
     insert_subprocess_mock(('borg1',) + CREATE_COMMAND[1:])
527 520
 
528 521
     module.create_archive(
529
-        verbosity=None,
530 522
         dry_run=False,
531 523
         repository='repo',
532 524
         location_config={
@@ -547,7 +539,6 @@ def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters(
547 539
     insert_subprocess_mock(CREATE_COMMAND + ('--remote-path', 'borg1'))
548 540
 
549 541
     module.create_archive(
550
-        verbosity=None,
551 542
         dry_run=False,
552 543
         repository='repo',
553 544
         location_config={
@@ -568,7 +559,6 @@ def test_create_archive_with_umask_calls_borg_with_umask_parameters():
568 559
     insert_subprocess_mock(CREATE_COMMAND + ('--umask', '740'))
569 560
 
570 561
     module.create_archive(
571
-        verbosity=None,
572 562
         dry_run=False,
573 563
         repository='repo',
574 564
         location_config={
@@ -588,7 +578,6 @@ def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
588 578
     insert_subprocess_mock(CREATE_COMMAND + ('--lock-wait', '5'))
589 579
 
590 580
     module.create_archive(
591
-        verbosity=None,
592 581
         dry_run=False,
593 582
         repository='repo',
594 583
         location_config={
@@ -609,7 +598,6 @@ def test_create_archive_with_source_directories_glob_expands():
609 598
     flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
610 599
 
611 600
     module.create_archive(
612
-        verbosity=None,
613 601
         dry_run=False,
614 602
         repository='repo',
615 603
         location_config={
@@ -630,7 +618,6 @@ def test_create_archive_with_non_matching_source_directories_glob_passes_through
630 618
     flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
631 619
 
632 620
     module.create_archive(
633
-        verbosity=None,
634 621
         dry_run=False,
635 622
         repository='repo',
636 623
         location_config={
@@ -650,7 +637,6 @@ def test_create_archive_with_glob_calls_borg_with_expanded_directories():
650 637
     insert_subprocess_mock(('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'))
651 638
 
652 639
     module.create_archive(
653
-        verbosity=None,
654 640
         dry_run=False,
655 641
         repository='repo',
656 642
         location_config={
@@ -670,7 +656,6 @@ def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
670 656
     insert_subprocess_mock(('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'))
671 657
 
672 658
     module.create_archive(
673
-        verbosity=None,
674 659
         dry_run=False,
675 660
         repository='repo',
676 661
         location_config={
@@ -692,7 +677,6 @@ def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
692 677
     insert_subprocess_mock(('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'))
693 678
 
694 679
     module.create_archive(
695
-        verbosity=None,
696 680
         dry_run=False,
697 681
         repository='repo',
698 682
         location_config={

+ 6
- 10
borgmatic/tests/unit/borg/test_extract.py View File

@@ -1,9 +1,10 @@
1
-import sys
1
+import logging, sys
2 2
 
3 3
 from flexmock import flexmock
4 4
 
5 5
 from borgmatic.borg import extract as module
6 6
 from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
7
+from borgmatic.tests.unit.test_verbosity import insert_logging_mock
7 8
 
8 9
 
9 10
 def insert_subprocess_mock(check_call_command, **kwargs):
@@ -32,7 +33,6 @@ def test_extract_last_archive_dry_run_should_call_borg_with_last_archive():
32 33
     )
33 34
 
34 35
     module.extract_last_archive_dry_run(
35
-        verbosity=None,
36 36
         repository='repo',
37 37
         lock_wait=None,
38 38
     )
@@ -47,13 +47,12 @@ def test_extract_last_archive_dry_run_without_any_archives_should_bail():
47 47
     insert_subprocess_never()
48 48
 
49 49
     module.extract_last_archive_dry_run(
50
-        verbosity=None,
51 50
         repository='repo',
52 51
         lock_wait=None,
53 52
     )
54 53
 
55 54
 
56
-def test_extract_last_archive_dry_run_with_verbosity_some_should_call_borg_with_info_parameter():
55
+def test_extract_last_archive_dry_run_with_log_info_should_call_borg_with_info_parameter():
57 56
     flexmock(sys.stdout).encoding = 'utf-8'
58 57
     insert_subprocess_check_output_mock(
59 58
         ('borg', 'list', '--short', 'repo', '--info'),
@@ -62,15 +61,15 @@ def test_extract_last_archive_dry_run_with_verbosity_some_should_call_borg_with_
62 61
     insert_subprocess_mock(
63 62
         ('borg', 'extract', '--dry-run', 'repo::archive2', '--info'),
64 63
     )
64
+    insert_logging_mock(logging.INFO)
65 65
 
66 66
     module.extract_last_archive_dry_run(
67
-        verbosity=VERBOSITY_SOME,
68 67
         repository='repo',
69 68
         lock_wait=None,
70 69
     )
71 70
 
72 71
 
73
-def test_extract_last_archive_dry_run_with_verbosity_lots_should_call_borg_with_debug_parameter():
72
+def test_extract_last_archive_dry_run_with_log_debug_should_call_borg_with_debug_parameter():
74 73
     flexmock(sys.stdout).encoding = 'utf-8'
75 74
     insert_subprocess_check_output_mock(
76 75
         ('borg', 'list', '--short', 'repo', '--debug', '--show-rc'),
@@ -79,9 +78,9 @@ def test_extract_last_archive_dry_run_with_verbosity_lots_should_call_borg_with_
79 78
     insert_subprocess_mock(
80 79
         ('borg', 'extract', '--dry-run', 'repo::archive2', '--debug', '--show-rc', '--list'),
81 80
     )
81
+    insert_logging_mock(logging.DEBUG)
82 82
 
83 83
     module.extract_last_archive_dry_run(
84
-        verbosity=VERBOSITY_LOTS,
85 84
         repository='repo',
86 85
         lock_wait=None,
87 86
     )
@@ -98,7 +97,6 @@ def test_extract_last_archive_dry_run_should_call_borg_via_local_path():
98 97
     )
99 98
 
100 99
     module.extract_last_archive_dry_run(
101
-        verbosity=None,
102 100
         repository='repo',
103 101
         lock_wait=None,
104 102
         local_path='borg1',
@@ -116,7 +114,6 @@ def test_extract_last_archive_dry_run_should_call_borg_with_remote_path_paramete
116 114
     )
117 115
 
118 116
     module.extract_last_archive_dry_run(
119
-        verbosity=None,
120 117
         repository='repo',
121 118
         lock_wait=None,
122 119
         remote_path='borg1',
@@ -134,7 +131,6 @@ def test_extract_last_archive_dry_run_should_call_borg_with_lock_wait_parameters
134 131
     )
135 132
 
136 133
     module.extract_last_archive_dry_run(
137
-        verbosity=None,
138 134
         repository='repo',
139 135
         lock_wait=5,
140 136
     )

+ 6
- 11
borgmatic/tests/unit/borg/test_info.py View File

@@ -1,9 +1,10 @@
1
+import logging
1 2
 from collections import OrderedDict
2 3
 
3 4
 from flexmock import flexmock
4 5
 
5 6
 from borgmatic.borg import info as module
6
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
7
+from borgmatic.tests.unit.test_verbosity import insert_logging_mock
7 8
 
8 9
 
9 10
 def insert_subprocess_mock(check_call_command, **kwargs):
@@ -18,29 +19,27 @@ def test_display_archives_info_calls_borg_with_parameters():
18 19
     insert_subprocess_mock(INFO_COMMAND)
19 20
 
20 21
     module.display_archives_info(
21
-        verbosity=None,
22 22
         repository='repo',
23 23
         storage_config={},
24 24
     )
25 25
 
26 26
 
27
-def test_display_archives_info_with_verbosity_some_calls_borg_with_info_parameter():
27
+def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
28 28
     insert_subprocess_mock(INFO_COMMAND + ('--info',))
29
-
29
+    insert_logging_mock(logging.INFO)
30 30
     module.display_archives_info(
31 31
         repository='repo',
32 32
         storage_config={},
33
-        verbosity=VERBOSITY_SOME,
34 33
     )
35 34
 
36 35
 
37
-def test_display_archives_info_with_verbosity_lots_calls_borg_with_debug_parameter():
36
+def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
38 37
     insert_subprocess_mock(INFO_COMMAND + ('--debug', '--show-rc'))
38
+    insert_logging_mock(logging.DEBUG)
39 39
 
40 40
     module.display_archives_info(
41 41
         repository='repo',
42 42
         storage_config={},
43
-        verbosity=VERBOSITY_LOTS,
44 43
     )
45 44
 
46 45
 
@@ -48,7 +47,6 @@ def test_display_archives_info_with_json_calls_borg_with_json_parameter():
48 47
     insert_subprocess_mock(INFO_COMMAND + ('--json',))
49 48
 
50 49
     module.display_archives_info(
51
-        verbosity=None,
52 50
         repository='repo',
53 51
         storage_config={},
54 52
         json=True,
@@ -59,7 +57,6 @@ def test_display_archives_info_with_local_path_calls_borg_via_local_path():
59 57
     insert_subprocess_mock(('borg1',) + INFO_COMMAND[1:])
60 58
 
61 59
     module.display_archives_info(
62
-        verbosity=None,
63 60
         repository='repo',
64 61
         storage_config={},
65 62
         local_path='borg1',
@@ -70,7 +67,6 @@ def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_para
70 67
     insert_subprocess_mock(INFO_COMMAND + ('--remote-path', 'borg1'))
71 68
 
72 69
     module.display_archives_info(
73
-        verbosity=None,
74 70
         repository='repo',
75 71
         storage_config={},
76 72
         remote_path='borg1',
@@ -82,7 +78,6 @@ def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_paramete
82 78
     insert_subprocess_mock(INFO_COMMAND + ('--lock-wait', '5'))
83 79
 
84 80
     module.display_archives_info(
85
-        verbosity=None,
86 81
         repository='repo',
87 82
         storage_config=storage_config,
88 83
     )

+ 6
- 10
borgmatic/tests/unit/borg/test_list.py View File

@@ -1,9 +1,10 @@
1
+import logging
1 2
 from collections import OrderedDict
2 3
 
3 4
 from flexmock import flexmock
4 5
 
5 6
 from borgmatic.borg import list as module
6
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
7
+from borgmatic.tests.unit.test_verbosity import insert_logging_mock
7 8
 
8 9
 
9 10
 def insert_subprocess_mock(check_call_command, **kwargs):
@@ -18,29 +19,28 @@ def test_list_archives_calls_borg_with_parameters():
18 19
     insert_subprocess_mock(LIST_COMMAND)
19 20
 
20 21
     module.list_archives(
21
-        verbosity=None,
22 22
         repository='repo',
23 23
         storage_config={},
24 24
     )
25 25
 
26 26
 
27
-def test_list_archives_with_verbosity_some_calls_borg_with_info_parameter():
27
+def test_list_archives_with_log_info_calls_borg_with_info_parameter():
28 28
     insert_subprocess_mock(LIST_COMMAND + ('--info',))
29
+    insert_logging_mock(logging.INFO)
29 30
 
30 31
     module.list_archives(
31 32
         repository='repo',
32 33
         storage_config={},
33
-        verbosity=VERBOSITY_SOME,
34 34
     )
35 35
 
36 36
 
37
-def test_list_archives_with_verbosity_lots_calls_borg_with_debug_parameter():
37
+def test_list_archives_with_log_debug_calls_borg_with_debug_parameter():
38 38
     insert_subprocess_mock(LIST_COMMAND + ('--debug', '--show-rc'))
39
+    insert_logging_mock(logging.DEBUG)
39 40
 
40 41
     module.list_archives(
41 42
         repository='repo',
42 43
         storage_config={},
43
-        verbosity=VERBOSITY_LOTS,
44 44
     )
45 45
 
46 46
 
@@ -48,7 +48,6 @@ def test_list_archives_with_json_calls_borg_with_json_parameter():
48 48
     insert_subprocess_mock(LIST_COMMAND + ('--json',))
49 49
 
50 50
     module.list_archives(
51
-        verbosity=None,
52 51
         repository='repo',
53 52
         storage_config={},
54 53
         json=True,
@@ -59,7 +58,6 @@ def test_list_archives_with_local_path_calls_borg_via_local_path():
59 58
     insert_subprocess_mock(('borg1',) + LIST_COMMAND[1:])
60 59
 
61 60
     module.list_archives(
62
-        verbosity=None,
63 61
         repository='repo',
64 62
         storage_config={},
65 63
         local_path='borg1',
@@ -70,7 +68,6 @@ def test_list_archives_with_remote_path_calls_borg_with_remote_path_parameters()
70 68
     insert_subprocess_mock(LIST_COMMAND + ('--remote-path', 'borg1'))
71 69
 
72 70
     module.list_archives(
73
-        verbosity=None,
74 71
         repository='repo',
75 72
         storage_config={},
76 73
         remote_path='borg1',
@@ -82,7 +79,6 @@ def test_list_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
82 79
     insert_subprocess_mock(LIST_COMMAND + ('--lock-wait', '5'))
83 80
 
84 81
     module.list_archives(
85
-        verbosity=None,
86 82
         repository='repo',
87 83
         storage_config=storage_config,
88 84
     )

+ 9
- 13
borgmatic/tests/unit/borg/test_prune.py View File

@@ -1,9 +1,10 @@
1
+import logging
1 2
 from collections import OrderedDict
2 3
 
3 4
 from flexmock import flexmock
4 5
 
5 6
 from borgmatic.borg import prune as module
6
-from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
7
+from borgmatic.tests.unit.test_verbosity import insert_logging_mock
7 8
 
8 9
 
9 10
 def insert_subprocess_mock(check_call_command, **kwargs):
@@ -11,6 +12,7 @@ def insert_subprocess_mock(check_call_command, **kwargs):
11 12
     subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
12 13
 
13 14
 
15
+
14 16
 BASE_PRUNE_FLAGS = (
15 17
     ('--keep-daily', '1'),
16 18
     ('--keep-weekly', '2'),
@@ -63,7 +65,6 @@ def test_prune_archives_calls_borg_with_parameters():
63 65
     insert_subprocess_mock(PRUNE_COMMAND)
64 66
 
65 67
     module.prune_archives(
66
-        verbosity=None,
67 68
         dry_run=False,
68 69
         repository='repo',
69 70
         storage_config={},
@@ -71,33 +72,33 @@ def test_prune_archives_calls_borg_with_parameters():
71 72
     )
72 73
 
73 74
 
74
-def test_prune_archives_with_verbosity_some_calls_borg_with_info_parameter():
75
+def test_prune_archives_with_log_info_calls_borg_with_info_parameter():
75 76
     retention_config = flexmock()
76 77
     flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
77 78
         BASE_PRUNE_FLAGS,
78 79
     )
79
-    insert_subprocess_mock(PRUNE_COMMAND + ('--info', '--stats',))
80
+    insert_subprocess_mock(PRUNE_COMMAND + ('--stats', '--info',))
81
+    insert_logging_mock(logging.INFO)
80 82
 
81 83
     module.prune_archives(
82 84
         repository='repo',
83 85
         storage_config={},
84
-        verbosity=VERBOSITY_SOME,
85 86
         dry_run=False,
86 87
         retention_config=retention_config,
87 88
     )
88 89
 
89 90
 
90
-def test_prune_archives_with_verbosity_lots_calls_borg_with_debug_parameter():
91
+def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
91 92
     retention_config = flexmock()
92 93
     flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
93 94
         BASE_PRUNE_FLAGS,
94 95
     )
95
-    insert_subprocess_mock(PRUNE_COMMAND + ('--debug', '--stats', '--list', '--show-rc'))
96
+    insert_subprocess_mock(PRUNE_COMMAND + ('--stats', '--debug', '--list', '--show-rc'))
97
+    insert_logging_mock(logging.DEBUG)
96 98
 
97 99
     module.prune_archives(
98 100
         repository='repo',
99 101
         storage_config={},
100
-        verbosity=VERBOSITY_LOTS,
101 102
         dry_run=False,
102 103
         retention_config=retention_config,
103 104
     )
@@ -113,7 +114,6 @@ def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter():
113 114
     module.prune_archives(
114 115
         repository='repo',
115 116
         storage_config={},
116
-        verbosity=None,
117 117
         dry_run=True,
118 118
         retention_config=retention_config,
119 119
     )
@@ -127,7 +127,6 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path():
127 127
     insert_subprocess_mock(('borg1',) + PRUNE_COMMAND[1:])
128 128
 
129 129
     module.prune_archives(
130
-        verbosity=None,
131 130
         dry_run=False,
132 131
         repository='repo',
133 132
         storage_config={},
@@ -144,7 +143,6 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters(
144 143
     insert_subprocess_mock(PRUNE_COMMAND + ('--remote-path', 'borg1'))
145 144
 
146 145
     module.prune_archives(
147
-        verbosity=None,
148 146
         dry_run=False,
149 147
         repository='repo',
150 148
         storage_config={},
@@ -162,7 +160,6 @@ def test_prune_archives_with_umask_calls_borg_with_umask_parameters():
162 160
     insert_subprocess_mock(PRUNE_COMMAND + ('--umask', '077'))
163 161
 
164 162
     module.prune_archives(
165
-        verbosity=None,
166 163
         dry_run=False,
167 164
         repository='repo',
168 165
         storage_config=storage_config,
@@ -179,7 +176,6 @@ def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
179 176
     insert_subprocess_mock(PRUNE_COMMAND + ('--lock-wait', '5'))
180 177
 
181 178
     module.prune_archives(
182
-        verbosity=None,
183 179
         dry_run=False,
184 180
         repository='repo',
185 181
         storage_config=storage_config,

+ 9
- 0
borgmatic/tests/unit/test_verbosity.py View File

@@ -1,10 +1,19 @@
1 1
 import logging
2 2
 
3
+from flexmock import flexmock
4
+
3 5
 from borgmatic import verbosity as module
4 6
 
7
+def insert_logging_mock(log_level):
8
+    """ Mocks the isEnabledFor from python logging. """
9
+    logging = flexmock(module.logging.Logger)
10
+    logging.should_receive('isEnabledFor').replace_with(lambda lvl : lvl >= log_level)
11
+    logging.should_receive('getEffectiveLevel').replace_with(lambda: log_level)
12
+
5 13
 
6 14
 def test_verbosity_to_log_level_maps_known_verbosity_to_log_level():
7 15
     assert module.verbosity_to_log_level(module.VERBOSITY_SOME) == logging.INFO
16
+    assert module.verbosity_to_log_level(module.VERBOSITY_LOTS) == logging.DEBUG
8 17
 
9 18
 
10 19
 def test_verbosity_to_log_level_maps_unknown_verbosity_to_warning_level():

Loading…
Cancel
Save