1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758 |
- import logging
- import sys
- import pytest
- from flexmock import flexmock
- from borgmatic.borg import create as module
- from ..test_verbosity import insert_logging_mock
- def test_expand_directory_with_basic_path_passes_it_through():
- flexmock(module.os.path).should_receive('expanduser').and_return('foo')
- flexmock(module.glob).should_receive('glob').and_return([])
- paths = module.expand_directory('foo')
- assert paths == ['foo']
- def test_expand_directory_with_glob_expands():
- flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
- flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
- paths = module.expand_directory('foo*')
- assert paths == ['foo', 'food']
- def test_expand_directories_flattens_expanded_directories():
- flexmock(module).should_receive('expand_directory').with_args('~/foo').and_return(['/root/foo'])
- flexmock(module).should_receive('expand_directory').with_args('bar*').and_return(
- ['bar', 'barf']
- )
- paths = module.expand_directories(('~/foo', 'bar*'))
- assert paths == ('/root/foo', 'bar', 'barf')
- def test_expand_directories_considers_none_as_no_directories():
- paths = module.expand_directories(None)
- assert paths == ()
- def test_expand_home_directories_expands_tildes():
- flexmock(module.os.path).should_receive('expanduser').with_args('~/bar').and_return('/foo/bar')
- flexmock(module.os.path).should_receive('expanduser').with_args('baz').and_return('baz')
- paths = module.expand_home_directories(('~/bar', 'baz'))
- assert paths == ('/foo/bar', 'baz')
- def test_expand_home_directories_considers_none_as_no_directories():
- paths = module.expand_home_directories(None)
- assert paths == ()
- def test_map_directories_to_devices_gives_device_id_per_path():
- flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
- flexmock(module.os).should_receive('stat').with_args('/bar').and_return(flexmock(st_dev=66))
- device_map = module.map_directories_to_devices(('/foo', '/bar'))
- assert device_map == {
- '/foo': 55,
- '/bar': 66,
- }
- def test_map_directories_to_devices_with_missing_path_does_not_error():
- flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
- flexmock(module.os).should_receive('stat').with_args('/bar').and_raise(FileNotFoundError)
- device_map = module.map_directories_to_devices(('/foo', '/bar'))
- assert device_map == {
- '/foo': 55,
- '/bar': None,
- }
- @pytest.mark.parametrize(
- 'directories,additional_directories,expected_directories',
- (
- ({'/': 1, '/root': 1}, {}, ('/',)),
- ({'/': 1, '/root/': 1}, {}, ('/',)),
- ({'/': 1, '/root': 2}, {}, ('/', '/root')),
- ({'/root': 1, '/': 1}, {}, ('/',)),
- ({'/root': 1, '/root/foo': 1}, {}, ('/root',)),
- ({'/root/': 1, '/root/foo': 1}, {}, ('/root/',)),
- ({'/root': 1, '/root/foo/': 1}, {}, ('/root',)),
- ({'/root': 1, '/root/foo': 2}, {}, ('/root', '/root/foo')),
- ({'/root/foo': 1, '/root': 1}, {}, ('/root',)),
- ({'/root': None, '/root/foo': None}, {}, ('/root', '/root/foo')),
- ({'/root': 1, '/etc': 1, '/root/foo/bar': 1}, {}, ('/etc', '/root')),
- ({'/root': 1, '/root/foo': 1, '/root/foo/bar': 1}, {}, ('/root',)),
- ({'/dup': 1, '/dup': 1}, {}, ('/dup',)),
- ({'/foo': 1, '/bar': 1}, {}, ('/bar', '/foo')),
- ({'/foo': 1, '/bar': 2}, {}, ('/bar', '/foo')),
- ({'/root/foo': 1}, {'/root': 1}, ()),
- ({'/root/foo': 1}, {'/root': 2}, ('/root/foo',)),
- ({'/root/foo': 1}, {}, ('/root/foo',)),
- ),
- )
- def test_deduplicate_directories_removes_child_paths_on_the_same_filesystem(
- directories, additional_directories, expected_directories
- ):
- assert (
- module.deduplicate_directories(directories, additional_directories) == expected_directories
- )
- def test_write_pattern_file_writes_pattern_lines():
- temporary_file = flexmock(name='filename', flush=lambda: None)
- temporary_file.should_receive('write').with_args('R /foo\n+ /foo/bar')
- flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
- module.write_pattern_file(['R /foo', '+ /foo/bar'])
- def test_write_pattern_file_with_sources_writes_sources_as_roots():
- temporary_file = flexmock(name='filename', flush=lambda: None)
- temporary_file.should_receive('write').with_args('R /foo\n+ /foo/bar\nR /baz\nR /quux')
- flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
- module.write_pattern_file(['R /foo', '+ /foo/bar'], sources=['/baz', '/quux'])
- def test_write_pattern_file_without_patterns_but_with_sources_writes_sources_as_roots():
- temporary_file = flexmock(name='filename', flush=lambda: None)
- temporary_file.should_receive('write').with_args('R /baz\nR /quux')
- flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
- module.write_pattern_file([], sources=['/baz', '/quux'])
- def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
- module.write_pattern_file([])
- def test_write_pattern_file_overwrites_existing_file():
- pattern_file = flexmock(name='filename', flush=lambda: None)
- pattern_file.should_receive('seek').with_args(0).once()
- pattern_file.should_receive('write').with_args('R /foo\n+ /foo/bar')
- flexmock(module.tempfile).should_receive('NamedTemporaryFile').never()
- module.write_pattern_file(['R /foo', '+ /foo/bar'], pattern_file=pattern_file)
- @pytest.mark.parametrize(
- 'filename_lists,opened_filenames',
- (
- ([('foo', 'bar'), ('baz', 'quux')], ('foo', 'bar', 'baz', 'quux')),
- ([None, ('foo', 'bar')], ('foo', 'bar')),
- ([None, None], ()),
- ),
- )
- def test_ensure_files_readable_opens_filenames(filename_lists, opened_filenames):
- for expected_filename in opened_filenames:
- flexmock(sys.modules['builtins']).should_receive('open').with_args(
- expected_filename
- ).and_return(flexmock(close=lambda: None))
- module.ensure_files_readable(*filename_lists)
- def test_make_pattern_flags_includes_pattern_filename_when_given():
- pattern_flags = module.make_pattern_flags(
- config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
- )
- assert pattern_flags == ('--patterns-from', '/tmp/patterns')
- def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
- pattern_flags = module.make_pattern_flags(config={'patterns_from': ['patterns', 'other']})
- assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
- def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
- pattern_flags = module.make_pattern_flags(
- config={'patterns_from': ['patterns']}, pattern_filename='/tmp/patterns'
- )
- assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
- def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
- pattern_flags = module.make_pattern_flags(config={'patterns_from': None})
- assert pattern_flags == ()
- def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
- exclude_flags = module.make_exclude_flags(
- config={'exclude_patterns': ['*.pyc', '/var']}, exclude_filename='/tmp/excludes'
- )
- assert exclude_flags == ('--exclude-from', '/tmp/excludes')
- def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
- exclude_flags = module.make_exclude_flags(config={'exclude_from': ['excludes', 'other']})
- assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
- def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
- exclude_flags = module.make_exclude_flags(
- config={'exclude_from': ['excludes']}, exclude_filename='/tmp/excludes'
- )
- assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
- def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
- exclude_flags = module.make_exclude_flags(config={'exclude_from': None})
- assert exclude_flags == ()
- def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
- exclude_flags = module.make_exclude_flags(config={'exclude_caches': True})
- assert exclude_flags == ('--exclude-caches',)
- def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
- exclude_flags = module.make_exclude_flags(config={'exclude_caches': False})
- assert exclude_flags == ()
- def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
- exclude_flags = module.make_exclude_flags(
- config={'exclude_if_present': ['exclude_me', 'also_me']}
- )
- assert exclude_flags == (
- '--exclude-if-present',
- 'exclude_me',
- '--exclude-if-present',
- 'also_me',
- )
- def test_make_exclude_flags_includes_keep_exclude_tags_when_true_in_config():
- exclude_flags = module.make_exclude_flags(config={'keep_exclude_tags': True})
- assert exclude_flags == ('--keep-exclude-tags',)
- def test_make_exclude_flags_does_not_include_keep_exclude_tags_when_false_in_config():
- exclude_flags = module.make_exclude_flags(config={'keep_exclude_tags': False})
- assert exclude_flags == ()
- def test_make_exclude_flags_includes_exclude_nodump_when_true_in_config():
- exclude_flags = module.make_exclude_flags(config={'exclude_nodump': True})
- assert exclude_flags == ('--exclude-nodump',)
- def test_make_exclude_flags_does_not_include_exclude_nodump_when_false_in_config():
- exclude_flags = module.make_exclude_flags(config={'exclude_nodump': False})
- assert exclude_flags == ()
- def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
- exclude_flags = module.make_exclude_flags(config={})
- assert exclude_flags == ()
- def test_make_list_filter_flags_with_debug_and_feature_available_includes_plus_and_minus():
- flexmock(module.logger).should_receive('isEnabledFor').and_return(True)
- flexmock(module.feature).should_receive('available').and_return(True)
- assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=False) == 'AME+-'
- def test_make_list_filter_flags_with_info_and_feature_available_omits_plus_and_minus():
- flexmock(module.logger).should_receive('isEnabledFor').and_return(False)
- flexmock(module.feature).should_receive('available').and_return(True)
- assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=False) == 'AME'
- def test_make_list_filter_flags_with_debug_and_feature_available_and_dry_run_includes_plus_and_minus():
- flexmock(module.logger).should_receive('isEnabledFor').and_return(True)
- flexmock(module.feature).should_receive('available').and_return(True)
- assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=True) == 'AME+-'
- def test_make_list_filter_flags_with_info_and_feature_available_and_dry_run_includes_plus_and_minus():
- flexmock(module.logger).should_receive('isEnabledFor').and_return(False)
- flexmock(module.feature).should_receive('available').and_return(True)
- assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=True) == 'AME+-'
- def test_make_list_filter_flags_with_debug_and_feature_not_available_includes_x():
- flexmock(module.logger).should_receive('isEnabledFor').and_return(True)
- flexmock(module.feature).should_receive('available').and_return(False)
- assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=False) == 'AMEx-'
- def test_make_list_filter_flags_with_info_and_feature_not_available_omits_x():
- flexmock(module.logger).should_receive('isEnabledFor').and_return(False)
- flexmock(module.feature).should_receive('available').and_return(False)
- assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=False) == 'AME-'
- def test_collect_borgmatic_source_directories_set_when_directory_exists():
- flexmock(module.os.path).should_receive('exists').and_return(True)
- flexmock(module.os.path).should_receive('expanduser')
- assert module.collect_borgmatic_source_directories('/tmp') == ['/tmp']
- def test_collect_borgmatic_source_directories_empty_when_directory_does_not_exist():
- flexmock(module.os.path).should_receive('exists').and_return(False)
- flexmock(module.os.path).should_receive('expanduser')
- assert module.collect_borgmatic_source_directories('/tmp') == []
- def test_collect_borgmatic_source_directories_defaults_when_directory_not_given():
- flexmock(module.os.path).should_receive('exists').and_return(True)
- flexmock(module.os.path).should_receive('expanduser')
- assert module.collect_borgmatic_source_directories(None) == [
- module.state.DEFAULT_BORGMATIC_SOURCE_DIRECTORY
- ]
- def test_pattern_root_directories_deals_with_none_patterns():
- assert module.pattern_root_directories(patterns=None) == []
- def test_pattern_root_directories_parses_roots_and_ignores_others():
- assert module.pattern_root_directories(
- ['R /root', '+ /root/foo', '- /root/foo/bar', 'R /baz']
- ) == ['/root', '/baz']
- @pytest.mark.parametrize(
- 'character_device,block_device,fifo,expected_result',
- (
- (False, False, False, False),
- (True, False, False, True),
- (False, True, False, True),
- (True, True, False, True),
- (False, False, True, True),
- (False, True, True, True),
- (True, False, True, True),
- ),
- )
- def test_special_file_looks_at_file_type(character_device, block_device, fifo, expected_result):
- flexmock(module.os).should_receive('stat').and_return(flexmock(st_mode=flexmock()))
- flexmock(module.stat).should_receive('S_ISCHR').and_return(character_device)
- flexmock(module.stat).should_receive('S_ISBLK').and_return(block_device)
- flexmock(module.stat).should_receive('S_ISFIFO').and_return(fifo)
- assert module.special_file('/dev/special') == expected_result
- def test_special_file_treats_broken_symlink_as_non_special():
- flexmock(module.os).should_receive('stat').and_raise(FileNotFoundError)
- assert module.special_file('/broken/symlink') is False
- def test_any_parent_directories_treats_parents_as_match():
- module.any_parent_directories('/foo/bar.txt', ('/foo', '/etc'))
- def test_any_parent_directories_treats_grandparents_as_match():
- module.any_parent_directories('/foo/bar/baz.txt', ('/foo', '/etc'))
- def test_any_parent_directories_treats_unrelated_paths_as_non_match():
- module.any_parent_directories('/foo/bar.txt', ('/usr', '/etc'))
- def test_collect_special_file_paths_parses_special_files_from_borg_dry_run_file_list():
- flexmock(module).should_receive('execute_command_and_capture_output').and_return(
- 'Processing files ...\n- /foo\n+ /bar\n- /baz'
- )
- flexmock(module).should_receive('special_file').and_return(True)
- flexmock(module).should_receive('any_parent_directories').and_return(False)
- assert module.collect_special_file_paths(
- ('borg', 'create'),
- local_path=None,
- working_directory=None,
- borg_environment=None,
- skip_directories=flexmock(),
- ) == ('/foo', '/bar', '/baz')
- def test_collect_special_file_paths_excludes_requested_directories():
- flexmock(module).should_receive('execute_command_and_capture_output').and_return(
- '+ /foo\n- /bar\n- /baz'
- )
- flexmock(module).should_receive('special_file').and_return(True)
- flexmock(module).should_receive('any_parent_directories').and_return(False).and_return(
- True
- ).and_return(False)
- assert module.collect_special_file_paths(
- ('borg', 'create'),
- local_path=None,
- working_directory=None,
- borg_environment=None,
- skip_directories=flexmock(),
- ) == ('/foo', '/baz')
- def test_collect_special_file_paths_excludes_non_special_files():
- flexmock(module).should_receive('execute_command_and_capture_output').and_return(
- '+ /foo\n+ /bar\n+ /baz'
- )
- flexmock(module).should_receive('special_file').and_return(True).and_return(False).and_return(
- True
- )
- flexmock(module).should_receive('any_parent_directories').and_return(False)
- assert module.collect_special_file_paths(
- ('borg', 'create'),
- local_path=None,
- working_directory=None,
- borg_environment=None,
- skip_directories=flexmock(),
- ) == ('/foo', '/baz')
- def test_collect_special_file_paths_omits_exclude_no_dump_flag_from_command():
- flexmock(module).should_receive('execute_command_and_capture_output').with_args(
- ('borg', 'create', '--dry-run', '--list'),
- capture_stderr=True,
- working_directory=None,
- extra_environment=None,
- borg_local_path='borg',
- ).and_return('Processing files ...\n- /foo\n+ /bar\n- /baz').once()
- flexmock(module).should_receive('special_file').and_return(True)
- flexmock(module).should_receive('any_parent_directories').and_return(False)
- module.collect_special_file_paths(
- ('borg', 'create', '--exclude-nodump'),
- local_path='borg',
- working_directory=None,
- borg_environment=None,
- skip_directories=flexmock(),
- )
- DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}' # noqa: FS003
- REPO_ARCHIVE_WITH_PATHS = (f'repo::{DEFAULT_ARCHIVE_NAME}', 'foo', 'bar')
- def test_create_archive_calls_borg_with_parameters():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_calls_borg_with_environment():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- environment = {'BORG_THINGY': 'YUP'}
- flexmock(module.environment).should_receive('make_environment').and_return(environment)
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=environment,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_patterns_calls_borg_with_patterns_including_converted_source_directories():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- pattern_flags = ('--patterns-from', 'patterns')
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(
- flexmock(name='/tmp/patterns')
- ).and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(pattern_flags)
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + pattern_flags + (f'repo::{DEFAULT_ARCHIVE_NAME}',),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'patterns': ['pattern'],
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_sources_and_used_config_paths_calls_borg_with_sources_and_config_paths():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(
- ('foo', 'bar', '/etc/borgmatic/config.yaml')
- )
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').with_args([]).and_return(())
- flexmock(module).should_receive('expand_directories').with_args(
- ('foo', 'bar', '/etc/borgmatic/config.yaml')
- ).and_return(('foo', 'bar', '/etc/borgmatic/config.yaml'))
- flexmock(module).should_receive('expand_directories').with_args([]).and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- environment = {'BORG_THINGY': 'YUP'}
- flexmock(module.environment).should_receive('make_environment').and_return(environment)
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('/etc/borgmatic/config.yaml',),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=environment,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=['/etc/borgmatic/config.yaml']),
- )
- def test_create_archive_with_sources_and_used_config_paths_with_store_config_files_false_calls_borg_with_sources_and_no_config_paths():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(
- ('foo', 'bar')
- )
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').with_args([]).and_return(())
- flexmock(module).should_receive('expand_directories').with_args(
- ('foo', 'bar')
- ).and_return(('foo', 'bar'))
- flexmock(module).should_receive('expand_directories').with_args([]).and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- environment = {'BORG_THINGY': 'YUP'}
- flexmock(module.environment).should_receive('make_environment').and_return(environment)
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=environment,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'store_config_files': False,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=['/etc/borgmatic/config.yaml']),
- )
- def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- exclude_flags = ('--exclude-from', 'excludes')
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(('exclude',))
- flexmock(module).should_receive('write_pattern_file').and_return(None).and_return(
- flexmock(name='/tmp/excludes')
- )
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(exclude_flags)
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + exclude_flags + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': ['exclude'],
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_log_info_calls_borg_with_info_parameter():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--info',),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- insert_logging_mock(logging.INFO)
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command_and_capture_output').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',),
- working_directory=None,
- extra_environment=None,
- borg_local_path='borg',
- )
- insert_logging_mock(logging.INFO)
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- json=True,
- )
- def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--debug', '--show-rc'),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- insert_logging_mock(logging.DEBUG)
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command_and_capture_output').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',),
- working_directory=None,
- extra_environment=None,
- borg_local_path='borg',
- )
- insert_logging_mock(logging.DEBUG)
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- json=True,
- )
- def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--dry-run') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=True,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_stats_and_dry_run_calls_borg_without_stats_parameter():
- # --dry-run and --stats are mutually exclusive, see:
- # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--dry-run') + REPO_ARCHIVE_WITH_PATHS + ('--info',),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- insert_logging_mock(logging.INFO)
- module.create_archive(
- dry_run=True,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- stats=True,
- )
- def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--checkpoint-interval', '600') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'checkpoint_interval': 600,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_checkpoint_volume_calls_borg_with_checkpoint_volume_parameters():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--checkpoint-volume', '1024') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'checkpoint_volume': 1024,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_parameters():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--chunker-params', '1,2,3,4') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'chunker_params': '1,2,3,4',
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_compression_calls_borg_with_compression_parameters():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--compression', 'rle') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'compression': 'rle',
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- @pytest.mark.parametrize(
- 'feature_available,option_flag',
- ((True, '--upload-ratelimit'), (False, '--remote-ratelimit')),
- )
- def test_create_archive_with_upload_rate_limit_calls_borg_with_upload_ratelimit_parameters(
- feature_available, option_flag
- ):
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(feature_available)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', option_flag, '100') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'upload_rate_limit': 100,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_working_directory_calls_borg_with_working_directory():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').with_args('/working/dir').and_return(
- '/working/dir'
- )
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory='/working/dir',
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'working_directory': '/working/dir',
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--one-file-system') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'one_file_system': True,
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- @pytest.mark.parametrize(
- 'feature_available,option_flag',
- ((True, '--numeric-ids'), (False, '--numeric-owner')),
- )
- def test_create_archive_with_numeric_ids_calls_borg_with_numeric_ids_parameter(
- feature_available, option_flag
- ):
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(feature_available)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', option_flag) + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'numeric_ids': True,
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('collect_special_file_paths').and_return(())
- create_command = ('borg', 'create', '--read-special') + REPO_ARCHIVE_WITH_PATHS
- flexmock(module).should_receive('execute_command').with_args(
- create_command + ('--dry-run', '--list'),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- flexmock(module).should_receive('execute_command').with_args(
- create_command,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'read_special': True,
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- @pytest.mark.parametrize(
- 'option_name,option_value',
- (
- ('ctime', True),
- ('ctime', False),
- ('birthtime', True),
- ('birthtime', False),
- ),
- )
- def test_create_archive_with_basic_option_calls_borg_with_corresponding_parameter(
- option_name, option_value
- ):
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- option_flag = '--no' + option_name.replace('', '') if option_value is False else None
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + ((option_flag,) if option_flag else ()) + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- option_name: option_value,
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- @pytest.mark.parametrize(
- 'option_value,feature_available,option_flag',
- (
- (True, True, '--atime'),
- (True, False, None),
- (False, True, None),
- (False, False, '--noatime'),
- ),
- )
- def test_create_archive_with_atime_option_calls_borg_with_corresponding_parameter(
- option_value, feature_available, option_flag
- ):
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(feature_available)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + ((option_flag,) if option_flag else ()) + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'atime': option_value,
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- @pytest.mark.parametrize(
- 'option_value,feature_available,option_flag',
- (
- (True, True, None),
- (True, False, None),
- (False, True, '--noflags'),
- (False, False, '--nobsdflags'),
- ),
- )
- def test_create_archive_with_flags_option_calls_borg_with_corresponding_parameter(
- option_value, feature_available, option_flag
- ):
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(feature_available)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + ((option_flag,) if option_flag else ()) + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'flags': option_value,
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--files-cache', 'ctime,size') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'files_cache': 'ctime,size',
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_local_path_calls_borg_via_local_path():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg1', 'create') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg1',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- local_path='borg1',
- )
- def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--remote-path', 'borg1') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- remote_path='borg1',
- )
- def test_create_archive_with_umask_calls_borg_with_umask_parameters():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--umask', '740') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'umask': 740,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_log_json_calls_borg_with_log_json_parameters():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--log-json') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=True, used_config_paths=[]),
- )
- def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--lock-wait', '5') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'lock_wait': 5,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_stats_calls_borg_with_stats_parameter_and_answer_output_log_level():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--stats',),
- output_log_level=module.borgmatic.logger.ANSWER,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- stats=True,
- )
- def test_create_archive_with_files_calls_borg_with_list_parameter_and_answer_output_log_level():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--list', '--filter', 'FOO') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=module.borgmatic.logger.ANSWER,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- list_files=True,
- )
- def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_parameter_and_no_list():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create')
- + REPO_ARCHIVE_WITH_PATHS
- + (
- '--info',
- '--progress',
- ),
- output_log_level=logging.INFO,
- output_file=module.DO_NOT_CAPTURE,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- insert_logging_mock(logging.INFO)
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- progress=True,
- )
- def test_create_archive_with_progress_calls_borg_with_progress_parameter():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--progress',),
- output_log_level=logging.INFO,
- output_file=module.DO_NOT_CAPTURE,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- progress=True,
- )
- def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progress_parameter():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- processes = flexmock()
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('collect_special_file_paths').and_return(())
- create_command = (
- ('borg', 'create', '--one-file-system', '--read-special')
- + REPO_ARCHIVE_WITH_PATHS
- + ('--progress',)
- )
- flexmock(module).should_receive('execute_command_with_processes').with_args(
- create_command + ('--dry-run', '--list'),
- processes=processes,
- output_log_level=logging.INFO,
- output_file=module.DO_NOT_CAPTURE,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- flexmock(module).should_receive('execute_command_with_processes').with_args(
- create_command,
- processes=processes,
- output_log_level=logging.INFO,
- output_file=module.DO_NOT_CAPTURE,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- progress=True,
- stream_processes=processes,
- )
- def test_create_archive_with_stream_processes_ignores_read_special_false_and_logs_warnings():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- processes = flexmock()
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(flexmock(name='/tmp/excludes'))
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module.logger).should_receive('warning').twice()
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('collect_special_file_paths').and_return(('/dev/null',))
- create_command = (
- 'borg',
- 'create',
- '--one-file-system',
- '--read-special',
- ) + REPO_ARCHIVE_WITH_PATHS
- flexmock(module).should_receive('execute_command_with_processes').with_args(
- create_command + ('--dry-run', '--list'),
- processes=processes,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- flexmock(module).should_receive('execute_command_with_processes').with_args(
- create_command,
- processes=processes,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'read_special': False,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- stream_processes=processes,
- )
- def test_create_archive_with_stream_processes_adds_special_files_to_excludes():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- processes = flexmock()
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(()).and_return(
- ('special',)
- )
- flexmock(module).should_receive('write_pattern_file').and_return(None).and_return(
- flexmock(name='/excludes')
- )
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(()).and_return(
- '--exclude-from', '/excludes'
- )
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('collect_special_file_paths').and_return(('special',))
- create_command = (
- 'borg',
- 'create',
- '--one-file-system',
- '--read-special',
- ) + REPO_ARCHIVE_WITH_PATHS
- flexmock(module).should_receive('execute_command_with_processes').with_args(
- create_command + ('--dry-run', '--list'),
- processes=processes,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- flexmock(module).should_receive('execute_command_with_processes').with_args(
- create_command + ('--exclude-from', '/excludes'),
- processes=processes,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- stream_processes=processes,
- )
- def test_create_archive_with_stream_processes_and_read_special_does_not_add_special_files_to_excludes():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- processes = flexmock()
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(()).and_return(
- ('special',)
- )
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('collect_special_file_paths').and_return(('special',))
- create_command = (
- 'borg',
- 'create',
- '--one-file-system',
- '--read-special',
- ) + REPO_ARCHIVE_WITH_PATHS
- flexmock(module).should_receive('execute_command_with_processes').with_args(
- create_command + ('--dry-run', '--list'),
- processes=processes,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- flexmock(module).should_receive('execute_command_with_processes').with_args(
- create_command,
- processes=processes,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'read_special': True,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- stream_processes=processes,
- )
- def test_create_archive_with_json_calls_borg_with_json_parameter():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command_and_capture_output').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',),
- working_directory=None,
- extra_environment=None,
- borg_local_path='borg',
- ).and_return('[]')
- json_output = module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- json=True,
- )
- assert json_output == '[]'
- def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command_and_capture_output').with_args(
- ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',),
- working_directory=None,
- extra_environment=None,
- borg_local_path='borg',
- ).and_return('[]')
- json_output = module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- json=True,
- stats=True,
- )
- assert json_output == '[]'
- def test_create_archive_with_source_directories_glob_expands():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', f'repo::{DEFAULT_ARCHIVE_NAME}', 'foo', 'food'),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo*'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_non_matching_source_directories_glob_passes_through():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo*',))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', f'repo::{DEFAULT_ARCHIVE_NAME}', 'foo*'),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo*'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_glob_calls_borg_with_expanded_directories():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', f'repo::{DEFAULT_ARCHIVE_NAME}', 'foo', 'food'),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo*'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- ('repo::ARCHIVE_NAME',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'archive_name_format': 'ARCHIVE_NAME',
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- repository_archive_pattern = 'repo::Documents_{hostname}-{now}' # noqa: FS003
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (repository_archive_pattern,)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', repository_archive_pattern, 'foo', 'bar'),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'archive_name_format': 'Documents_{hostname}-{now}', # noqa: FS003
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_repository_accepts_borg_placeholders():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- repository_archive_pattern = '{fqdn}::Documents_{hostname}-{now}' # noqa: FS003
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (repository_archive_pattern,)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', repository_archive_pattern, 'foo', 'bar'),
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='{fqdn}', # noqa: FS003
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['{fqdn}'], # noqa: FS003
- 'exclude_patterns': None,
- 'archive_name_format': 'Documents_{hostname}-{now}', # noqa: FS003
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('execute_command').with_args(
- ('borg', 'create', '--extra', '--options') + REPO_ARCHIVE_WITH_PATHS,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'extra_borg_options': {'create': '--extra --options'},
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_create_archive_with_stream_processes_calls_borg_with_processes_and_read_special():
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- processes = flexmock()
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
- flexmock(module).should_receive('map_directories_to_devices').and_return({})
- flexmock(module).should_receive('expand_directories').and_return(())
- flexmock(module).should_receive('pattern_root_directories').and_return([])
- flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
- flexmock(module).should_receive('expand_home_directories').and_return(())
- flexmock(module).should_receive('write_pattern_file').and_return(None)
- flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
- flexmock(module.feature).should_receive('available').and_return(True)
- flexmock(module).should_receive('ensure_files_readable')
- flexmock(module).should_receive('make_pattern_flags').and_return(())
- flexmock(module).should_receive('make_exclude_flags').and_return(())
- flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
- (f'repo::{DEFAULT_ARCHIVE_NAME}',)
- )
- flexmock(module.environment).should_receive('make_environment')
- flexmock(module).should_receive('collect_special_file_paths').and_return(())
- create_command = (
- 'borg',
- 'create',
- '--one-file-system',
- '--read-special',
- ) + REPO_ARCHIVE_WITH_PATHS
- flexmock(module).should_receive('execute_command_with_processes').with_args(
- create_command + ('--dry-run', 'list'),
- processes=processes,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- flexmock(module).should_receive('execute_command_with_processes').with_args(
- create_command,
- processes=processes,
- output_log_level=logging.INFO,
- output_file=None,
- borg_local_path='borg',
- working_directory=None,
- extra_environment=None,
- )
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- stream_processes=processes,
- )
- def test_create_archive_with_non_existent_directory_and_source_directories_must_exist_raises_error():
- '''
- If a source directory doesn't exist and source_directories_must_exist is True, raise an error.
- '''
- flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
- flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
- flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
- flexmock(module).should_receive('check_all_source_directories_exist').and_raise(ValueError)
- with pytest.raises(ValueError):
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'source_directories_must_exist': True,
- },
- local_borg_version='1.2.3',
- global_arguments=flexmock(log_json=False, used_config_paths=[]),
- )
- def test_check_all_source_directories_exist_with_glob_and_tilde_directories():
- flexmock(module).should_receive('expand_directory').with_args('foo*').and_return(
- ('foo', 'food')
- )
- flexmock(module).should_receive('expand_directory').with_args('~/bar').and_return(
- ('/root/bar',)
- )
- flexmock(module.os.path).should_receive('exists').and_return(False)
- flexmock(module.os.path).should_receive('exists').with_args('foo').and_return(True)
- flexmock(module.os.path).should_receive('exists').with_args('food').and_return(True)
- flexmock(module.os.path).should_receive('exists').with_args('/root/bar').and_return(True)
- module.check_all_source_directories_exist(['foo*', '~/bar'])
- def test_check_all_source_directories_exist_with_non_existent_directory_raises():
- flexmock(module).should_receive('expand_directory').with_args('foo').and_return(('foo',))
- flexmock(module.os.path).should_receive('exists').and_return(False)
- with pytest.raises(ValueError):
- module.check_all_source_directories_exist(['foo'])
|