diff --git a/atticmatic/backends/shared.py b/atticmatic/backends/shared.py index 8026540..417a732 100644 --- a/atticmatic/backends/shared.py +++ b/atticmatic/backends/shared.py @@ -68,7 +68,7 @@ def create_archive( attic archive. ''' sources = re.split('\s+', source_directories) - sources = tuple(chain.from_iterable([glob(x) if glob(x) else [x] for x in sources])) + sources = tuple(chain.from_iterable(glob(x) or [x] for x in sources)) exclude_flags = ('--exclude-from', excludes_filename) if excludes_filename else () compression = storage_config.get('compression', None) compression_flags = ('--compression', compression) if compression else () diff --git a/atticmatic/tests/unit/backends/test_shared.py b/atticmatic/tests/unit/backends/test_shared.py index 20a98f6..cddef00 100644 --- a/atticmatic/tests/unit/backends/test_shared.py +++ b/atticmatic/tests/unit/backends/test_shared.py @@ -177,16 +177,49 @@ def test_create_archive_with_umask_should_call_attic_with_umask_parameters(): ) -def test_create_archive_with_globs(): - insert_subprocess_mock(('attic', 'create', 'repo::host-now', 'setup.py', 'setup.cfg')) +def test_create_archive_with_source_directories_glob_expands(): + insert_subprocess_mock(('attic', 'create', 'repo::host-now', 'foo', 'food')) insert_platform_mock() insert_datetime_mock() + flexmock(module).should_receive('glob').with_args('foo*').and_return(['foo', 'food']) module.create_archive( excludes_filename=None, verbosity=None, storage_config={}, - source_directories='setup*', + source_directories='foo*', + repository='repo', + command='attic', + ) + + +def test_create_archive_with_non_matching_source_directories_glob_passes_through(): + insert_subprocess_mock(('attic', 'create', 'repo::host-now', 'foo*')) + insert_platform_mock() + insert_datetime_mock() + flexmock(module).should_receive('glob').with_args('foo*').and_return([]) + + module.create_archive( + excludes_filename=None, + verbosity=None, + storage_config={}, + source_directories='foo*', + repository='repo', + command='attic', + ) + + +def test_create_archive_with_glob_should_call_attic_with_expanded_directories(): + insert_subprocess_mock(('attic', 'create', 'repo::host-now', 'foo', 'food')) + insert_platform_mock() + insert_datetime_mock() + flexmock(module).should_receive('glob').with_args('foo*').and_return(['foo', 'food']) + + module.create_archive( + excludes_filename=None, + verbosity=None, + storage_config={}, + source_directories='foo*', repository='repo', command='attic', )