12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582 |
- 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(
- location_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(
- location_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(
- location_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(location_config={'patterns_from': None})
- assert pattern_flags == ()
- def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
- exclude_flags = module.make_exclude_flags(
- location_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(
- location_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(
- location_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(location_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(location_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(location_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(
- location_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(location_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(location_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(location_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(location_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(location_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')
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'patterns': ['pattern'],
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': ['exclude'],
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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,
- )
- insert_logging_mock(logging.INFO)
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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,
- )
- insert_logging_mock(logging.DEBUG)
- module.create_archive(
- dry_run=False,
- repository_path='repo',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'checkpoint_interval': 600},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'checkpoint_volume': 1024},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'chunker_params': '1,2,3,4'},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'compression': 'rle'},
- local_borg_version='1.2.3',
- )
- @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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'upload_rate_limit': 100},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'working_directory': '/working/dir',
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'one_file_system': True,
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- @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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'numeric_ids': True,
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'read_special': True,
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- @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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- option_name: option_value,
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- @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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'atime': option_value,
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- @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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'flags': option_value,
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'files_cache': 'ctime,size',
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'umask': 740},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'lock_wait': 5},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'read_special': False,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'read_special': True,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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,
- ).and_return('[]')
- json_output = module.create_archive(
- dry_run=False,
- repository_path='repo',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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,
- ).and_return('[]')
- json_output = module.create_archive(
- dry_run=False,
- repository_path='repo',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo*'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo*'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo*'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'archive_name_format': 'ARCHIVE_NAME'},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'archive_name_format': 'Documents_{hostname}-{now}'}, # noqa: FS003
- local_borg_version='1.2.3',
- )
- 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
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['{fqdn}'], # noqa: FS003
- 'exclude_patterns': None,
- },
- storage_config={'archive_name_format': 'Documents_{hostname}-{now}'}, # noqa: FS003
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'extra_borg_options': {'create': '--extra --options'}},
- local_borg_version='1.2.3',
- )
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- 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',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- 'source_directories_must_exist': True,
- },
- storage_config={},
- local_borg_version='1.2.3',
- )
- 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'])
|