Skip to content

Commit

Permalink
fix broken tests #33
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed May 13, 2017
1 parent af0fb9f commit 9f99b1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pyexcel_io/_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import logging

PY2 = sys.version_info[0] == 2
PY3_ABOVE = sys.version_info[0] >= 3
PY26 = PY2 and sys.version_info[1] < 7
PY27 = PY2 and sys.version_info[1] == 7
PY27_ABOVE = PY27 or PY3_ABOVE

if PY26:
from ordereddict import OrderedDict
Expand Down
16 changes: 11 additions & 5 deletions pyexcel_io/fileformat/_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ def get_file_handle(self):
class CSVinMemoryReader(CSVSheetReader):
def get_file_handle(self):
if compact.PY2:
f = UTF8Recorder(self._native_sheet.payload,
self._encoding)
if hasattr(self._native_sheet.payload, 'read'):
f = UTF8Recorder(self._native_sheet.payload,
self._encoding)
else:
f = self._native_sheet.payload
else:
if isinstance(self._native_sheet.payload, compact.BytesIO):
content = self._native_sheet.payload.read()
Expand Down Expand Up @@ -252,12 +255,15 @@ def open_stream(self, file_stream, multiple_sheets=False, **keywords):
self._native_book = self._load_from_stream()

def open_content(self, file_content, multiple_sheets=False, **keywords):
if not compact.PY26:
if compact.PY27_ABOVE:
import mmap
if isinstance(file_content, mmap.mmap):
# load from mmap
self._file_stream = iter(
lambda: file_content.read().decode('utf-8'), '')
if compact.PY3_ABOVE:
self._file_stream = iter(
lambda: file_content.readline().decode('utf-8'), '')
else:
self._file_stream = iter(file_content.readline, '')
self._keywords = keywords
self._native_book = self._load_from_stream()
else:
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mock
nose
codecov
coverage
Expand Down

0 comments on commit 9f99b1d

Please sign in to comment.