Skip to content

Commit

Permalink
reaching 100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed May 19, 2015
1 parent 3f53535 commit f43a218
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 19 deletions.
3 changes: 0 additions & 3 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ After that, you can start get and save data in the loaded format.
0.0.4 0.0.7 0.0.6 0.0.6 0.0.8
0.0.3 0.0.6 0.0.5 0.0.5 0.0.7
0.0.2 0.0.3-0.0.5 0.0.2-0.0.4 0.0.4 0.0.5-0.0.6
0.0.2 0.0.3-0.0.5 0.0.2-0.0.4 0.0.4 0.0.5-0.0.6
0.0.2 0.0.3-0.0.5 0.0.2-0.0.4 0.0.4 0.0.5-0.0.6
0.0.2 0.0.3-0.0.5 0.0.2-0.0.4 0.0.4 0.0.5-0.0.6
0.0.1 0.0.2 0.0.1 0.0.3 0.0.4
============= =========== ============ ============ ============

Expand Down
9 changes: 6 additions & 3 deletions pyexcel_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
DEFAULT_SHEET_NAME
)

# Please also register here
TEXT_STREAM_TYPES = [FILE_FORMAT_CSV, FILE_FORMAT_TSV]

# Please also register here
BINARY_STREAM_TYPES = [FILE_FORMAT_CSVZ, FILE_FORMAT_TSVZ,
FILE_FORMAT_ODS, FILE_FORMAT_XLS,
FILE_FORMAT_XLSX, FILE_FORMAT_XLSM]
Expand Down Expand Up @@ -194,7 +197,7 @@ def get_writer(filename, file_type=None, **keywords):


def get_io(file_type):
if file_type in [FILE_FORMAT_CSV, FILE_FORMAT_TSV]:
if file_type in TEXT_STREAM_TYPES:
return StringIO()
elif file_type in BINARY_STREAM_TYPES:
return BytesIO()
Expand All @@ -203,7 +206,7 @@ def get_io(file_type):


def validate_io(file_type, io):
if file_type in [FILE_FORMAT_CSV, FILE_FORMAT_TSV]:
if file_type in TEXT_STREAM_TYPES:
return isinstance(io, StringIO)
elif file_type in BINARY_STREAM_TYPES:
return isinstance(io, BytesIO)
Expand Down Expand Up @@ -242,7 +245,7 @@ def save_data(afile, data, file_type=None, **keywords):
else:
single_sheet_in_book = False

if isstream(afile):
if isstream(afile) and file_type is None:
file_type = FILE_FORMAT_CSV

store_data(afile, to_store,
Expand Down
29 changes: 19 additions & 10 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ class TestSheetWriterBase:
@raises(TypeError)
def test_abstractness(self):
SheetWriterBase("test")

def test_sheet_writer_base(self):
class D(SheetWriterBase):
def close(self):
SheetWriterBase.close(self)
pass

def set_size(self, size):
SheetWriterBase.set_size(self, size)
pass

def write_array(self, table):
SheetWriterBase.write_array(self, table)
pass

d = D()
d.set_size(10)
d.write_array([11,11])
d.close()

class TestSheetWriter:
@raises(TypeError)
Expand All @@ -150,20 +169,10 @@ def test_abstractness(self):

def test_inheritance(self):
class D(SheetWriter):
def set_sheet_name(self, name):
SheetWriter.set_sheet_name(self, name)
pass

def set_size(self, size):
SheetWriter.set_size(self, size)
pass

def write_row(self, row):
SheetWriter.write_row(self, row)
pass

D('t','e','s').set_sheet_name("test")
D('t','e','s').set_size(10)
D('t','e','s').write_row([11,11])

def test_writer(self):
Expand Down
49 changes: 46 additions & 3 deletions tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from pyexcel_io import load_data, StringIO, get_writer, get_io, BytesIO
from pyexcel_io import load_data, StringIO, get_writer, get_io, BytesIO, BINARY_STREAM_TYPES, save_data, get_data
from nose.tools import raises

PY2 = sys.version_info[0] == 2
Expand Down Expand Up @@ -30,19 +30,37 @@ def test_load_xls_data_from_memory():
io = BytesIO()
load_data(io, file_type="xls")


@raises(NotImplementedError)
def test_load_unknown_data():
load_data("test.unknown")


@raises(NotImplementedError)
def test_load_unknown_data_from_memory():
io = BytesIO()
load_data(io, file_type="unknown")


@raises(IOError)
def test_load_xlsm_data_from_memory():
if not PY2:
io = StringIO()
get_writer(io, file_type="xlsm")
else:
raise IOError("pass it")



@raises(NotImplementedError)
def test_write_xlsx_data():
get_writer("test.xlsx")


@raises(NotImplementedError)
def test_write_unknown_data():
get_writer("test.unknown")


@raises(IOError)
def test_writer_xlsm_data_from_memory():
if not PY2:
Expand All @@ -51,12 +69,37 @@ def test_writer_xlsm_data_from_memory():
else:
raise IOError("pass it")


@raises(NotImplementedError)
def test_writer_xlsm_data_from_memory2():
io = BytesIO()
get_writer(io, file_type="xlsm")


@raises(NotImplementedError)
def test_writer_unknown_data_from_memory2():
io = BytesIO()
# mock it
BINARY_STREAM_TYPES.append('unknown1')
get_writer(io, file_type="unknown1")


def test_get_io():
io = get_io("hello")
assert io == None
assert io == None


def test_binary_file_content():
data = [['1','2','3']]
io = get_io("csvz")
save_data(io, data, 'csvz')
result = get_data(io.getvalue(), 'csvz')
assert result == data


def test_text_file_content():
data = [['1','2','3']]
io = get_io("csv")
save_data(io, data, 'csv')
result = get_data(io.getvalue(), 'csv')
assert result == data

0 comments on commit f43a218

Please sign in to comment.