def __init__(self, file_type=None, file_stream=None, **keywords): if file_stream: self.content = file_stream else: self.content = get_io(file_type) self.file_type = file_type self.keywords = keywords
def test_book_reader_from_memory_source(self): io = get_io(self.file_type) with open(self.test_file, 'r') as f: io.write(f.read()) io.seek(0) b = CSVBook(None, io) sheets = b.sheets() assert sheets['csv'] == self.data
def test_sheet_memory_reader(self): io = get_io(self.file_type) with open(self.test_file, 'r') as f: io.write(f.read()) io.seek(0) r = CSVinMemoryReader(NamedContent(self.file_type, io)) result = r.to_array() assert result == self.data
def test_sheet_writer_to_memory(self): io = get_io(self.file_type) w = CSVSheetWriter(io, None, single_sheet_in_book=True) for row in self.data: w.write_row(row) w.close() content = io.getvalue().replace('\r', '') assert content.strip('\n') == self.result
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']]
def test_save_to(): file_type = 'csv' io = get_io(file_type) g = (i for i in [[1,2],[3,4]]) ss = SheetSource((file_type, io), lineterminator='\n') sheet_stream = SheetStream("test", g) sheet_stream.save_to(ss) content = io.getvalue() expected = dedent("""\ 1,2 3,4 """) assert content == expected
def __init__(self, file_type=None, **keywords): self.content = get_io(file_type) self.file_name = (file_type, self.content) self.keywords = keywords
def test_get_io(): io = get_io("hello") assert io == None
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