Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
"""
Make a test csv file as:
a,b,c,d
e,f,g,h
i,j,1.1,1
"""
self.testclass = pe.SeriesReader
self.testfile = "testcsv.xls"
create_sample_file1_series(self.testfile)
def test_merge_two_files(self):
merged = pyexcel.cookbook.SHEET(self.testfile) + pyexcel.cookbook.SHEET(self.testfile2)
r = pyexcel.SeriesReader(merged)
data = pyexcel.utils.to_dict(r)
content = {}
content.update(self.content)
content.update(self.content2)
assert data == content
try:
pyexcel.cookbook.merge_two_files(self.testfile, self.testfile2)
assert 1==2
except NotImplementedError:
assert 1==1
def test_headers(self):
r = p.SeriesReader(self.testfile, series=4)
actual = r.colnames
eq_(self.content[4], actual)
def test_write_series_reader(self):
r = pe.SeriesReader(self.testfile)
w = pe.Writer(self.testfile2)
w.write_reader(r)
w.close()
r2 = pe.SeriesReader(self.testfile2)
content = pe.utils.to_dict(r2)
assert content == self.content
def _test_update_columns(self):
bad_column = {"A": [31, 1, 1, 1, 1]}
custom_column = {"Z": [33, 44, 55, 66, 77]}
try:
# try non-existent column first
pyexcel.cookbook.update_columns(self.testfile, bad_column)
assert 1==2
except IndexError:
assert 1==1
pyexcel.cookbook.update_columns(self.testfile, custom_column)
r = pyexcel.SeriesReader("pyexcel_%s" % self.testfile)
data = pyexcel.utils.to_dict(r)
assert data["Z"] == custom_column["Z"]
try:
pyexcel.cookbook.update_columns(self.testfile, custom_column)
r = pyexcel.SeriesReader("pyexcel_%s" % self.testfile)
assert 1==2
except NotImplementedError:
assert 1==1
pyexcel.cookbook.update_columns(self.testfile, custom_column, "test4.ods")
r = pyexcel.SeriesReader("test4.ods")
data = pyexcel.utils.to_dict(r)
assert data["Z"] == custom_column["Z"]
def test_headers(self):
r = p.SeriesReader(self.testfile)
actual = r.colnames
assert self.content[0] == actual
def test_merge_readers(self):
r1 = pe.SeriesReader(self.testfile)
r2 = pe.SeriesReader(self.testfile2)
r3 = pe.SeriesReader(self.testfile3)
file_array = [r1, r2, r3]
pe.cookbook.merge_readers(file_array)
r = pe.SeriesReader("pyexcel_merged.csv")
r.format(int)
content = {}
content.update(self.content)
content.update(self.content2)
content.update(self.content3)
eq_(r.dict, content)
pe.cookbook.merge_readers(file_array) # bang, do not overwrite
pyexcel.cookbook.update_columns(self.testfile, bad_column)
assert 1==2
except IndexError:
assert 1==1
pyexcel.cookbook.update_columns(self.testfile, custom_column)
r = pyexcel.SeriesReader("pyexcel_%s" % self.testfile)
data = pyexcel.utils.to_dict(r)
assert data["Z"] == custom_column["Z"]
try:
pyexcel.cookbook.update_columns(self.testfile, custom_column)
r = pyexcel.SeriesReader("pyexcel_%s" % self.testfile)
assert 1==2
except NotImplementedError:
assert 1==1
pyexcel.cookbook.update_columns(self.testfile, custom_column, "test4.ods")
r = pyexcel.SeriesReader("test4.ods")
data = pyexcel.utils.to_dict(r)
assert data["Z"] == custom_column["Z"]
def test_merge_readers(self):
r1 = pe.SeriesReader(self.testfile)
r2 = pe.SeriesReader(self.testfile2)
r3 = pe.SeriesReader(self.testfile3)
file_array = [r1, r2, r3]
pe.cookbook.merge_readers(file_array)
r = pe.SeriesReader("pyexcel_merged.csv")
r.format(int)
content = {}
content.update(self.content)
content.update(self.content2)
content.update(self.content3)
eq_(r.dict, content)
pe.cookbook.merge_readers(file_array) # bang, do not overwrite
def main(base_dir):
# print all in json
#
# Column 1 Column 2 Column 3
# 1 4 7
# 2 5 8
# 3 6 9
reader = SeriesReader(os.path.join(base_dir,"example_series.ods"))
data = to_dict(reader)
print(json.dumps(data))
# output:
# {"Column 2": [4.0, 5.0, 6.0], "Column 3": [7.0, 8.0, 9.0], "Column 1": [1.0, 2.0, 3.0]}
# get the column headers
print(reader.colnames)
# [u'Column 1', u'Column 2', u'Column 3']
# get the content in one dimensional array
data = to_array(reader.enumerate())
print(data)
# [1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0]
# get the content in one dimensional array
# in reverse order