Skip to content

Commit

Permalink
Failing test and logging for #30
Browse files Browse the repository at this point in the history
  • Loading branch information
pombredanne committed Jul 13, 2015
1 parent d816577 commit 63f631d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/extractcode/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ def get_handlers(location):
Return an iterable of (handler, type_matched, mime_matched,
extension_matched,) for this `location`.
"""
if DEBUG:
logger.debug('get_handlers: is_file: %(location)s ' % locals()
+ repr(filetype.is_file(location)))
if filetype.is_file(location):

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

if DEBUG:
logger.debug('get_handlers: %(location)s: ftype: %(ftype)s, mtype: %(mtype)s ' % locals())
logger.debug('get_handlers: %(location)s: matched type: %(type_matched)s, mime: %(mime_matched)s, ext: %(extension_matched)s' % locals())


if type_matched or mime_matched or extension_matched:
if DEBUG:
logger.debug('get_handlers: %(location)s: matched type: %(type_matched)s, mime: %(mime_matched)s, ext: %(extension_matched)s' % locals())
logger.debug('get_handlers: %(location)s: handler: %(handler)r' % locals())
yield handler, type_matched, mime_matched, extension_matched


Expand Down
9 changes: 7 additions & 2 deletions src/extractcode/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def extract(location, kinds=extractcode.default_kinds, recurse=False):
if DEBUG:
logger.debug('extract:walk not recurse: skipped file:' + loc)
continue

if not archive.should_extract(loc, kinds):
if DEBUG:
logger.debug('extract:walk: skipped file: not should_extract:' + loc)
Expand All @@ -157,7 +158,6 @@ def extract(location, kinds=extractcode.default_kinds, recurse=False):
yield xevent



def extract_file(location, target, kinds=extractcode.default_kinds):
"""
Extract a single archive at `location` in the `target` directory if it is
Expand All @@ -166,6 +166,11 @@ def extract_file(location, target, kinds=extractcode.default_kinds):
warnings = []
errors = []
extractor = archive.get_extractor(location, kinds)
if DEBUG:
logger.debug('extract_file: extractor: for:' + location
+ ' with kinds: ' + repr(kinds) + ': '
+ getattr(extractor, '__module__', '')
+ '.' + getattr(extractor, '__name__', ''))
if extractor:
yield ExtractEvent(location, target, done=False, warnings=[], errors=[])
try:
Expand All @@ -179,6 +184,6 @@ def extract_file(location, target, kinds=extractcode.default_kinds):
except Exception, e:
if DEBUG:
logger.debug('extract_file: ERROR: %(errors)r, %(e)r.\n' % locals())
errors=[str(e).strip(' \'"')]
errors = [str(e).strip(' \'"')]
finally:
yield ExtractEvent(location, target, done=True, warnings=warnings, errors=errors)
1 change: 1 addition & 0 deletions tests/extractcode/data/archive/not_archive/hashfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
80de10a8b9f13365de8cc4bbf8efec5e /etc/rsyslog.d/50-default.conf
11 changes: 10 additions & 1 deletion tests/extractcode/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import codecs
import os
import posixpath
from unittest.case import skipIf
from unittest.case import expectedFailure

import commoncode.date
Expand All @@ -43,6 +42,8 @@
from extractcode import libarchive2
from extractcode import sevenzip
from extractcode import ExtractErrorFailedToExtract
from extractcode import default_kinds
from extractcode import all_kinds


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

@expectedFailure
def test_no_handler_is_selected_for_a_non_archive(self):
test_loc = self.get_test_loc('archive/not_archive/hashfile')
assert [] == list(archive.get_handlers(test_loc))
assert None == archive.get_extractor(test_loc)
assert None == archive.get_extractor(test_loc, kinds=all_kinds)
assert not archive.should_extract(test_loc, kinds=default_kinds)


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

0 comments on commit 63f631d

Please sign in to comment.