Skip to content

Commit

Permalink
test coverage improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed May 18, 2015
1 parent bdbf7c2 commit 9f9b7b9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
7 changes: 2 additions & 5 deletions pyexcel_io/csvzipbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def sheet_iterator(self):
raise ValueError("%s cannot be found" % self.sheet_name)
else:
return rets
elif self.sheet_index:
elif self.sheet_index is not None:
file_list = self.native_book.namelist()
length = len(file_list)
if self.sheet_index < length:
Expand All @@ -70,10 +70,7 @@ def get_sheet(self, native_sheet):
if PY2:
sheet = StringIO(content)
else:
if isinstance(content, str):
sheet = StringIO(content)
else:
sheet = StringIO(content.decode('utf-8'))
sheet = StringIO(content.decode('utf-8'))

return CSVinMemoryReader(
NamedContent(
Expand Down
2 changes: 1 addition & 1 deletion test.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nosetests --with-cov --cov pyexcel_io --cov tests --with-doctest --doctest-extension=.rst doc/source tests pyexcel_io
nosetests --with-doctest --doctest-extension=.rst doc/source tests pyexcel_io
del tmp.db
17 changes: 15 additions & 2 deletions tests/test_csvz_book.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from pyexcel_io import CSVZipBook, CSVZipWriter, save_data, OrderedDict
from pyexcel_io import CSVZipBook, CSVZipWriter, save_data, OrderedDict, get_io
import zipfile
from nose.tools import raises
import sys
Expand Down Expand Up @@ -35,11 +35,24 @@ def test_reading(self):
zipreader = CSVZipBook(self.file)
data = zipreader.sheets()
assert data['pyexcel_sheet1'] == [['1','2','3']]

def tearDown(self):
os.unlink(self.file)


def test_reading_from_memory():
data = [[1,2,3]]
io = get_io("csvz")
zipbook = CSVZipWriter(io)
sheet = zipbook.create_sheet(None)
sheet.write_array(data)
sheet.close()
zipbook.close()
zipreader = CSVZipBook(io)
data = zipreader.sheets()
assert data['pyexcel_sheet1'] == [['1','2','3']]


class TestMultipleSheet:
def setUp(self):
self.content = OrderedDict()
Expand Down
8 changes: 7 additions & 1 deletion tests/test_django_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __getattr__(self, field):

class Objects:
def __init__(self):
self.objs = None
self.objs = []

def bulk_create(self, objs, batch_size):
self.objs = objs
Expand Down Expand Up @@ -113,6 +113,12 @@ def test_mapping_dict(self):
writer.close()
assert model.objects.objs == self.result

def test_empty_model(self):
model = FakeDjangoModel()
reader = DjangoModelReader(model)
data = reader.to_array()
assert data == []


class TestMultipleModels:
def setUp(self):
Expand Down
8 changes: 6 additions & 2 deletions tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyexcel_io import (
SheetReaderBase, SheetReader, BookReader,
SheetWriter, BookWriter, NamedContent,
BookReaderBase
BookReaderBase, SheetWriterBase
)
from nose.tools import raises

Expand Down Expand Up @@ -138,7 +138,11 @@ def test_load_from_memory(self):
reader = DictReader(None, self.content)
assert self.content == reader.sheets()


class TestSheetWriterBase:
@raises(TypeError)
def test_abstractness(self):
SheetWriterBase("test")

class TestSheetWriter:
@raises(TypeError)
def test_abstractness(self):
Expand Down

0 comments on commit 9f9b7b9

Please sign in to comment.