Skip to content

Commit 63f631d

Browse files
committed
Failing test and logging for #30
1 parent d816577 commit 63f631d

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/extractcode/archive.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ def get_handlers(location):
173173
Return an iterable of (handler, type_matched, mime_matched,
174174
extension_matched,) for this `location`.
175175
"""
176-
if DEBUG:
177-
logger.debug('get_handlers: is_file: %(location)s ' % locals()
178-
+ repr(filetype.is_file(location)))
179176
if filetype.is_file(location):
180177

181178
T = typecode.contenttype.get_type(location)
@@ -202,7 +199,15 @@ def get_handlers(location):
202199
if handler.exts:
203200
extension_matched = location.lower().endswith(handler.exts)
204201

202+
if DEBUG:
203+
logger.debug('get_handlers: %(location)s: ftype: %(ftype)s, mtype: %(mtype)s ' % locals())
204+
logger.debug('get_handlers: %(location)s: matched type: %(type_matched)s, mime: %(mime_matched)s, ext: %(extension_matched)s' % locals())
205+
206+
205207
if type_matched or mime_matched or extension_matched:
208+
if DEBUG:
209+
logger.debug('get_handlers: %(location)s: matched type: %(type_matched)s, mime: %(mime_matched)s, ext: %(extension_matched)s' % locals())
210+
logger.debug('get_handlers: %(location)s: handler: %(handler)r' % locals())
206211
yield handler, type_matched, mime_matched, extension_matched
207212

208213

src/extractcode/extract.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def extract(location, kinds=extractcode.default_kinds, recurse=False):
137137
if DEBUG:
138138
logger.debug('extract:walk not recurse: skipped file:' + loc)
139139
continue
140+
140141
if not archive.should_extract(loc, kinds):
141142
if DEBUG:
142143
logger.debug('extract:walk: skipped file: not should_extract:' + loc)
@@ -157,7 +158,6 @@ def extract(location, kinds=extractcode.default_kinds, recurse=False):
157158
yield xevent
158159

159160

160-
161161
def extract_file(location, target, kinds=extractcode.default_kinds):
162162
"""
163163
Extract a single archive at `location` in the `target` directory if it is
@@ -166,6 +166,11 @@ def extract_file(location, target, kinds=extractcode.default_kinds):
166166
warnings = []
167167
errors = []
168168
extractor = archive.get_extractor(location, kinds)
169+
if DEBUG:
170+
logger.debug('extract_file: extractor: for:' + location
171+
+ ' with kinds: ' + repr(kinds) + ': '
172+
+ getattr(extractor, '__module__', '')
173+
+ '.' + getattr(extractor, '__name__', ''))
169174
if extractor:
170175
yield ExtractEvent(location, target, done=False, warnings=[], errors=[])
171176
try:
@@ -179,6 +184,6 @@ def extract_file(location, target, kinds=extractcode.default_kinds):
179184
except Exception, e:
180185
if DEBUG:
181186
logger.debug('extract_file: ERROR: %(errors)r, %(e)r.\n' % locals())
182-
errors=[str(e).strip(' \'"')]
187+
errors = [str(e).strip(' \'"')]
183188
finally:
184189
yield ExtractEvent(location, target, done=True, warnings=warnings, errors=errors)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
80de10a8b9f13365de8cc4bbf8efec5e /etc/rsyslog.d/50-default.conf

tests/extractcode/test_archive.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import codecs
2929
import os
3030
import posixpath
31-
from unittest.case import skipIf
3231
from unittest.case import expectedFailure
3332

3433
import commoncode.date
@@ -43,6 +42,8 @@
4342
from extractcode import libarchive2
4443
from extractcode import sevenzip
4544
from extractcode import ExtractErrorFailedToExtract
45+
from extractcode import default_kinds
46+
from extractcode import all_kinds
4647

4748

4849
"""
@@ -153,6 +154,14 @@ def test_score_handlers(self):
153154
scored = archive.score_handlers(handlers)
154155
assert expected == sorted([(h[0], h[1].name) for h in scored], reverse=True)
155156

157+
@expectedFailure
158+
def test_no_handler_is_selected_for_a_non_archive(self):
159+
test_loc = self.get_test_loc('archive/not_archive/hashfile')
160+
assert [] == list(archive.get_handlers(test_loc))
161+
assert None == archive.get_extractor(test_loc)
162+
assert None == archive.get_extractor(test_loc, kinds=all_kinds)
163+
assert not archive.should_extract(test_loc, kinds=default_kinds)
164+
156165

157166
class BaseArchiveTestCase(FileBasedTesting):
158167
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')

0 commit comments

Comments
 (0)