123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532 |
- 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}'
- 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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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='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', 'repo::{}'.format(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='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', 'repo::{}'.format(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='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', 'repo::{}'.format(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='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='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}'
- 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='repo',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
- 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}'
- 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='{fqdn}',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['{fqdn}'],
- 'exclude_patterns': None,
- },
- storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
- 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='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='repo',
- location_config={
- 'source_directories': ['foo', 'bar'],
- 'repositories': ['repo'],
- 'exclude_patterns': None,
- },
- storage_config={},
- local_borg_version='1.2.3',
- stream_processes=processes,
- )
|