Skip to content

Commit

Permalink
test coverage incrase
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed May 15, 2015
1 parent a03b13c commit 3d3279c
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
49 changes: 49 additions & 0 deletions tests/test_csv_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ def test_multiple_sheet(self):
sheets = b.sheets()
assert sheets == self.sheets

def test_read_one_from_many_by_name(self):
b = CSVBook("csv_multiple.csv", load_sheet_with_name="sheet1")
sheets = b.sheets()
assert sheets["sheet1"] == self.sheets["sheet1"]

@raises(ValueError)
def test_read_one_from_many_by_non_existent_name(self):
CSVBook("csv_multiple.csv", load_sheet_with_name="notknown")

def test_read_one_from_many_by_index(self):
b = CSVBook("csv_multiple.csv", load_sheet_at_index=1)
sheets = b.sheets()
assert sheets["sheet2"] == self.sheets["sheet2"]

@raises(IndexError)
def test_read_one_from_many_by_wrong_index(self):
CSVBook("csv_multiple.csv", load_sheet_at_index=90)

def tearDown(self):
index = 0
for key, value in self.sheets.items():
Expand Down Expand Up @@ -253,3 +271,34 @@ def test_book_writer_to_memroy(self):
b.close()
content = io.getvalue().replace('\r', '')
assert content.strip('\n') == self.result


def test_empty_arguments_to_csvbook():
book = CSVBook(None)
assert book.sheets() == {"csv":[]}


class TestNonUniformCSV:
def setUp(self):
self.file_type = "csv"
self.test_file = "csv_book." + self.file_type
self.data = [
["1"],
["4", "5", "6"],
["7"]
]
with open(self.test_file, 'w') as f:
for row in self.data:
f.write(",".join(row) + "\n")

def test_sheet_file_reader(self):
r = CSVFileReader(NamedContent(self.file_type, self.test_file))
result = r.to_array()
assert result == [
["1", "", ""],
["4", "5", "6"],
["7"]
]

def tearDown(self):
os.unlink(self.test_file)
55 changes: 54 additions & 1 deletion 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
from pyexcel_io import CSVZipBook, CSVZipWriter, save_data, OrderedDict
import zipfile
import sys
PY2 = sys.version_info[0] == 2
Expand Down Expand Up @@ -37,3 +37,56 @@ def test_reading(self):

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


class TestMultipleSheet:
def setUp(self):
self.content = OrderedDict()
self.content.update({
'Sheet 1':
[
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0]
]
})
self.content.update({
'Sheet 2':
[
['X', 'Y', 'Z'],
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]
]
})
self.content.update({
'Sheet 3':
[
['O', 'P', 'Q'],
[3.0, 2.0, 1.0],
[4.0, 3.0, 2.0]
]
})
self.file="mybook.csvz"
save_data(self.file, self.content)

def test_read_one_from_many_by_name(self):
b = CSVZipBook(self.file, load_sheet_with_name="Sheet 1")
sheets = b.sheets()
assert sheets['Sheet 1'] == [
[u'1.0', u'2.0', u'3.0'],
[u'4.0', u'5.0', u'6.0'],
[u'7.0', u'8.0', u'9.0']
]

def test_read_one_from_many_by_index(self):
b = CSVZipBook(self.file, load_sheet_at_index=0)
sheets = b.sheets()
assert sheets['Sheet 1'] == [
[u'1.0', u'2.0', u'3.0'],
[u'4.0', u'5.0', u'6.0'],
[u'7.0', u'8.0', u'9.0']
]

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

0 comments on commit 3d3279c

Please sign in to comment.