test_prune.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic.borg import prune as module
  4. from ..test_verbosity import insert_logging_mock
  5. def insert_execute_command_mock(
  6. prune_command, output_log_level, working_directory=None, borg_exit_codes=None
  7. ):
  8. flexmock(module.environment).should_receive('make_environment')
  9. flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
  10. working_directory,
  11. )
  12. flexmock(module).should_receive('execute_command').with_args(
  13. prune_command,
  14. output_log_level=output_log_level,
  15. environment=None,
  16. working_directory=working_directory,
  17. borg_local_path=prune_command[0],
  18. borg_exit_codes=borg_exit_codes,
  19. ).once()
  20. BASE_PRUNE_FLAGS = ('--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3')
  21. def test_make_prune_flags_returns_flags_from_config():
  22. config = {
  23. 'keep_daily': 1,
  24. 'keep_weekly': 2,
  25. 'keep_monthly': 3,
  26. }
  27. flexmock(module.feature).should_receive('available').and_return(True)
  28. flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
  29. result = module.make_prune_flags(
  30. config, flexmock(match_archives=None), local_borg_version='1.2.3'
  31. )
  32. assert result == BASE_PRUNE_FLAGS
  33. def test_make_prune_flags_accepts_prefix_with_placeholders():
  34. config = {
  35. 'keep_daily': 1,
  36. 'prefix': 'Documents_{hostname}-{now}', # noqa: FS003
  37. }
  38. flexmock(module.feature).should_receive('available').and_return(True)
  39. flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
  40. result = module.make_prune_flags(
  41. config, flexmock(match_archives=None), local_borg_version='1.2.3'
  42. )
  43. expected = (
  44. '--keep-daily',
  45. '1',
  46. '--match-archives',
  47. 'sh:Documents_{hostname}-{now}*', # noqa: FS003
  48. )
  49. assert result == expected
  50. def test_make_prune_flags_with_prefix_without_borg_features_uses_glob_archives():
  51. config = {
  52. 'keep_daily': 1,
  53. 'prefix': 'Documents_{hostname}-{now}', # noqa: FS003
  54. }
  55. flexmock(module.feature).should_receive('available').and_return(False)
  56. flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
  57. result = module.make_prune_flags(
  58. config, flexmock(match_archives=None), local_borg_version='1.2.3'
  59. )
  60. expected = (
  61. '--keep-daily',
  62. '1',
  63. '--glob-archives',
  64. 'Documents_{hostname}-{now}*', # noqa: FS003
  65. )
  66. assert result == expected
  67. def test_make_prune_flags_prefers_prefix_to_archive_name_format():
  68. config = {
  69. 'archive_name_format': 'bar-{now}', # noqa: FS003
  70. 'keep_daily': 1,
  71. 'prefix': 'bar-',
  72. }
  73. flexmock(module.feature).should_receive('available').and_return(True)
  74. flexmock(module.flags).should_receive('make_match_archives_flags').never()
  75. result = module.make_prune_flags(
  76. config, flexmock(match_archives=None), local_borg_version='1.2.3'
  77. )
  78. expected = (
  79. '--keep-daily',
  80. '1',
  81. '--match-archives',
  82. 'sh:bar-*', # noqa: FS003
  83. )
  84. assert result == expected
  85. def test_make_prune_flags_without_prefix_uses_archive_name_format_instead():
  86. config = {
  87. 'archive_name_format': 'bar-{now}', # noqa: FS003
  88. 'keep_daily': 1,
  89. 'prefix': None,
  90. }
  91. flexmock(module.feature).should_receive('available').and_return(True)
  92. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  93. None, 'bar-{now}', '1.2.3' # noqa: FS003
  94. ).and_return(('--match-archives', 'sh:bar-*')).once()
  95. result = module.make_prune_flags(
  96. config, flexmock(match_archives=None), local_borg_version='1.2.3'
  97. )
  98. expected = (
  99. '--keep-daily',
  100. '1',
  101. '--match-archives',
  102. 'sh:bar-*', # noqa: FS003
  103. )
  104. assert result == expected
  105. def test_make_prune_flags_without_prefix_uses_match_archives_option():
  106. config = {
  107. 'archive_name_format': 'bar-{now}', # noqa: FS003
  108. 'match_archives': 'foo*',
  109. 'keep_daily': 1,
  110. 'prefix': None,
  111. }
  112. flexmock(module.feature).should_receive('available').and_return(True)
  113. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  114. 'foo*', 'bar-{now}', '1.2.3' # noqa: FS003
  115. ).and_return(('--match-archives', 'sh:bar-*')).once()
  116. result = module.make_prune_flags(
  117. config, flexmock(match_archives=None), local_borg_version='1.2.3'
  118. )
  119. expected = (
  120. '--keep-daily',
  121. '1',
  122. '--match-archives',
  123. 'sh:bar-*', # noqa: FS003
  124. )
  125. assert result == expected
  126. def test_make_prune_flags_ignores_keep_exclude_tags_in_config():
  127. config = {
  128. 'keep_daily': 1,
  129. 'keep_exclude_tags': True,
  130. }
  131. flexmock(module.feature).should_receive('available').and_return(True)
  132. flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
  133. result = module.make_prune_flags(
  134. config, flexmock(match_archives=None), local_borg_version='1.2.3'
  135. )
  136. assert result == ('--keep-daily', '1')
  137. PRUNE_COMMAND = ('borg', 'prune', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3')
  138. def test_prune_archives_calls_borg_with_flags():
  139. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  140. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  141. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  142. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  143. flexmock(module.feature).should_receive('available').with_args(
  144. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  145. ).and_return(False)
  146. insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO)
  147. prune_arguments = flexmock(statistics=False, list_details=False)
  148. module.prune_archives(
  149. dry_run=False,
  150. repository_path='repo',
  151. config={},
  152. local_borg_version='1.2.3',
  153. global_arguments=flexmock(),
  154. prune_arguments=prune_arguments,
  155. )
  156. def test_prune_archives_with_log_info_calls_borg_with_info_flag():
  157. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  158. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  159. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  160. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  161. flexmock(module.feature).should_receive('available').with_args(
  162. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  163. ).and_return(False)
  164. insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO)
  165. insert_logging_mock(logging.INFO)
  166. prune_arguments = flexmock(statistics=False, list_details=False)
  167. module.prune_archives(
  168. repository_path='repo',
  169. config={},
  170. dry_run=False,
  171. local_borg_version='1.2.3',
  172. global_arguments=flexmock(),
  173. prune_arguments=prune_arguments,
  174. )
  175. def test_prune_archives_with_log_debug_calls_borg_with_debug_flag():
  176. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  177. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  178. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  179. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  180. flexmock(module.feature).should_receive('available').with_args(
  181. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  182. ).and_return(False)
  183. insert_execute_command_mock(PRUNE_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO)
  184. insert_logging_mock(logging.DEBUG)
  185. prune_arguments = flexmock(statistics=False, list_details=False)
  186. module.prune_archives(
  187. repository_path='repo',
  188. config={},
  189. dry_run=False,
  190. local_borg_version='1.2.3',
  191. global_arguments=flexmock(),
  192. prune_arguments=prune_arguments,
  193. )
  194. def test_prune_archives_with_dry_run_calls_borg_with_dry_run_flag():
  195. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  196. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  197. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  198. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  199. flexmock(module.feature).should_receive('available').with_args(
  200. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  201. ).and_return(False)
  202. insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO)
  203. prune_arguments = flexmock(statistics=False, list_details=False)
  204. module.prune_archives(
  205. repository_path='repo',
  206. config={},
  207. dry_run=True,
  208. local_borg_version='1.2.3',
  209. global_arguments=flexmock(),
  210. prune_arguments=prune_arguments,
  211. )
  212. def test_prune_archives_with_local_path_calls_borg_via_local_path():
  213. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  214. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  215. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  216. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  217. flexmock(module.feature).should_receive('available').with_args(
  218. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  219. ).and_return(False)
  220. insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO)
  221. prune_arguments = flexmock(statistics=False, list_details=False)
  222. module.prune_archives(
  223. dry_run=False,
  224. repository_path='repo',
  225. config={},
  226. local_borg_version='1.2.3',
  227. global_arguments=flexmock(),
  228. local_path='borg1',
  229. prune_arguments=prune_arguments,
  230. )
  231. def test_prune_archives_with_exit_codes_calls_borg_using_them():
  232. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  233. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  234. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  235. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  236. flexmock(module.feature).should_receive('available').with_args(
  237. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  238. ).and_return(False)
  239. borg_exit_codes = flexmock()
  240. insert_execute_command_mock(
  241. ('borg',) + PRUNE_COMMAND[1:] + ('repo',),
  242. logging.INFO,
  243. borg_exit_codes=borg_exit_codes,
  244. )
  245. prune_arguments = flexmock(statistics=False, list_details=False)
  246. module.prune_archives(
  247. dry_run=False,
  248. repository_path='repo',
  249. config={'borg_exit_codes': borg_exit_codes},
  250. local_borg_version='1.2.3',
  251. global_arguments=flexmock(),
  252. prune_arguments=prune_arguments,
  253. )
  254. def test_prune_archives_with_remote_path_calls_borg_with_remote_path_flags():
  255. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  256. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  257. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  258. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  259. flexmock(module.feature).should_receive('available').with_args(
  260. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  261. ).and_return(False)
  262. insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO)
  263. prune_arguments = flexmock(statistics=False, list_details=False)
  264. module.prune_archives(
  265. dry_run=False,
  266. repository_path='repo',
  267. config={},
  268. local_borg_version='1.2.3',
  269. global_arguments=flexmock(),
  270. remote_path='borg1',
  271. prune_arguments=prune_arguments,
  272. )
  273. def test_prune_archives_with_stats_config_calls_borg_with_stats_flag():
  274. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  275. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  276. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  277. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  278. flexmock(module.feature).should_receive('available').with_args(
  279. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  280. ).and_return(False)
  281. insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), module.borgmatic.logger.ANSWER)
  282. prune_arguments = flexmock(statistics=None, list_details=False)
  283. module.prune_archives(
  284. dry_run=False,
  285. repository_path='repo',
  286. config={'statistics': True},
  287. local_borg_version='1.2.3',
  288. global_arguments=flexmock(),
  289. prune_arguments=prune_arguments,
  290. )
  291. def test_prune_archives_with_list_config_calls_borg_with_list_flag():
  292. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  293. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  294. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  295. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  296. flexmock(module.feature).should_receive('available').with_args(
  297. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  298. ).and_return(False)
  299. insert_execute_command_mock(PRUNE_COMMAND + ('--list', 'repo'), module.borgmatic.logger.ANSWER)
  300. prune_arguments = flexmock(statistics=False, list_details=None)
  301. module.prune_archives(
  302. dry_run=False,
  303. repository_path='repo',
  304. config={'list_details': True},
  305. local_borg_version='1.2.3',
  306. global_arguments=flexmock(),
  307. prune_arguments=prune_arguments,
  308. )
  309. def test_prune_archives_with_umask_calls_borg_with_umask_flags():
  310. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  311. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  312. config = {'umask': '077'}
  313. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  314. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  315. flexmock(module.feature).should_receive('available').with_args(
  316. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  317. ).and_return(False)
  318. insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'), logging.INFO)
  319. prune_arguments = flexmock(statistics=False, list_details=False)
  320. module.prune_archives(
  321. dry_run=False,
  322. repository_path='repo',
  323. config=config,
  324. local_borg_version='1.2.3',
  325. global_arguments=flexmock(),
  326. prune_arguments=prune_arguments,
  327. )
  328. def test_prune_archives_with_log_json_calls_borg_with_log_json_flag():
  329. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  330. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  331. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  332. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  333. flexmock(module.feature).should_receive('available').with_args(
  334. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  335. ).and_return(False)
  336. insert_execute_command_mock(PRUNE_COMMAND + ('--log-json', 'repo'), logging.INFO)
  337. prune_arguments = flexmock(statistics=False, list_details=False)
  338. module.prune_archives(
  339. dry_run=False,
  340. repository_path='repo',
  341. config={'log_json': True},
  342. local_borg_version='1.2.3',
  343. global_arguments=flexmock(),
  344. prune_arguments=prune_arguments,
  345. )
  346. def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
  347. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  348. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  349. config = {'lock_wait': 5}
  350. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  351. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  352. flexmock(module.feature).should_receive('available').with_args(
  353. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  354. ).and_return(False)
  355. insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO)
  356. prune_arguments = flexmock(statistics=False, list_details=False)
  357. module.prune_archives(
  358. dry_run=False,
  359. repository_path='repo',
  360. config=config,
  361. local_borg_version='1.2.3',
  362. global_arguments=flexmock(),
  363. prune_arguments=prune_arguments,
  364. )
  365. def test_prune_archives_with_extra_borg_options_calls_borg_with_extra_options():
  366. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  367. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  368. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  369. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  370. flexmock(module.feature).should_receive('available').with_args(
  371. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  372. ).and_return(False)
  373. insert_execute_command_mock(PRUNE_COMMAND + ('--extra', '--options', 'repo'), logging.INFO)
  374. prune_arguments = flexmock(statistics=False, list_details=False)
  375. module.prune_archives(
  376. dry_run=False,
  377. repository_path='repo',
  378. config={'extra_borg_options': {'prune': '--extra --options'}},
  379. local_borg_version='1.2.3',
  380. global_arguments=flexmock(),
  381. prune_arguments=prune_arguments,
  382. )
  383. def test_prune_archives_with_date_based_matching_calls_borg_with_date_based_flags():
  384. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  385. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  386. flexmock(module.flags).should_receive('make_flags').and_return(())
  387. flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
  388. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  389. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
  390. (
  391. '--newer',
  392. '1d',
  393. '--newest',
  394. '1y',
  395. '--older',
  396. '1m',
  397. '--oldest',
  398. '1w',
  399. '--match-archives',
  400. None,
  401. )
  402. )
  403. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  404. flexmock(module.feature).should_receive('available').with_args(
  405. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  406. ).and_return(False)
  407. flexmock(module.environment).should_receive('make_environment')
  408. flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
  409. flexmock(module).should_receive('execute_command').with_args(
  410. (
  411. 'borg',
  412. 'prune',
  413. '--keep-daily',
  414. '1',
  415. '--keep-weekly',
  416. '2',
  417. '--keep-monthly',
  418. '3',
  419. '--newer',
  420. '1d',
  421. '--newest',
  422. '1y',
  423. '--older',
  424. '1m',
  425. '--oldest',
  426. '1w',
  427. '--match-archives',
  428. None,
  429. '--repo',
  430. 'repo',
  431. ),
  432. output_log_level=logging.INFO,
  433. environment=None,
  434. working_directory=None,
  435. borg_local_path='borg',
  436. borg_exit_codes=None,
  437. )
  438. prune_arguments = flexmock(
  439. statistics=False, list_details=False, newer='1d', newest='1y', older='1m', oldest='1w'
  440. )
  441. module.prune_archives(
  442. dry_run=False,
  443. repository_path='repo',
  444. config={},
  445. local_borg_version='1.2.3',
  446. global_arguments=flexmock(),
  447. prune_arguments=prune_arguments,
  448. )
  449. def test_prune_archives_calls_borg_with_working_directory():
  450. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  451. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  452. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  453. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  454. flexmock(module.feature).should_receive('available').with_args(
  455. module.feature.Feature.NO_PRUNE_STATS, '1.2.3'
  456. ).and_return(False)
  457. insert_execute_command_mock(
  458. PRUNE_COMMAND + ('repo',), logging.INFO, working_directory='/working/dir'
  459. )
  460. prune_arguments = flexmock(statistics=False, list_details=False)
  461. module.prune_archives(
  462. dry_run=False,
  463. repository_path='repo',
  464. config={'working_directory': '/working/dir'},
  465. local_borg_version='1.2.3',
  466. global_arguments=flexmock(),
  467. prune_arguments=prune_arguments,
  468. )
  469. def test_prune_archives_calls_borg_without_stats_when_feature_is_not_available():
  470. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  471. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  472. flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
  473. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  474. flexmock(module.feature).should_receive('available').with_args(
  475. module.feature.Feature.NO_PRUNE_STATS, '2.0.0b10'
  476. ).and_return(True)
  477. insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.ANSWER)
  478. prune_arguments = flexmock(statistics=True, list_details=False)
  479. module.prune_archives(
  480. dry_run=False,
  481. repository_path='repo',
  482. config={'statistics': True},
  483. local_borg_version='2.0.0b10',
  484. global_arguments=flexmock(),
  485. prune_arguments=prune_arguments,
  486. )