Browse Source

Mocking out glob() in test so it doesn't hit the filesystem, and simplifying comprehension.

Dan Helfman 9 years ago
parent
commit
0c97dba5f1
2 changed files with 37 additions and 4 deletions
  1. 1 1
      atticmatic/backends/shared.py
  2. 36 3
      atticmatic/tests/unit/backends/test_shared.py

+ 1 - 1
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 ()

+ 36 - 3
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',
     )