diff --git a/pyexcel_ods/__init__.py b/pyexcel_ods/__init__.py index 70c50de..3c2a28b 100644 --- a/pyexcel_ods/__init__.py +++ b/pyexcel_ods/__init__.py @@ -9,17 +9,21 @@ # this line has to be place above all else # because of dynamic import from pyexcel_io.plugins import IOPluginInfoChain -from pyexcel_io.io import get_data as read_data, isstream, store_data as write_data +from pyexcel_io.io import ( + get_data as read_data, + isstream, + store_data as write_data, +) -__FILE_TYPE__ = 'ods' +__FILE_TYPE__ = "ods" IOPluginInfoChain(__name__).add_a_reader( - relative_plugin_class_path='odsr.ODSBook', + relative_plugin_class_path="odsr.ODSBook", file_types=[__FILE_TYPE__], - stream_type='binary' + stream_type="binary", ).add_a_writer( - relative_plugin_class_path='odsw.ODSWriter', + relative_plugin_class_path="odsw.ODSWriter", file_types=[__FILE_TYPE__], - stream_type='binary' + stream_type="binary", ) diff --git a/pyexcel_ods/odsr.py b/pyexcel_ods/odsr.py index a76a2f3..3559ffe 100644 --- a/pyexcel_ods/odsr.py +++ b/pyexcel_ods/odsr.py @@ -21,21 +21,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Thanks to grt for the fixes -from odf.teletype import extractText -from odf.table import TableRow, TableCell, Table -from odf.text import P +import pyexcel_io.service as service from odf.namespaces import OFFICENS from odf.opendocument import load +from odf.table import Table, TableCell, TableRow +# Thanks to grt for the fixes +from odf.teletype import extractText +from odf.text import P +from pyexcel_io._compact import OrderedDict from pyexcel_io.book import BookReader from pyexcel_io.sheet import SheetReader -from pyexcel_io._compact import OrderedDict -import pyexcel_io.service as service class ODSSheet(SheetReader): """native ods sheet""" + def __init__(self, sheet, auto_detect_int=True, **keywords): SheetReader.__init__(self, sheet, **keywords) self.__auto_detect_int = auto_detect_int @@ -70,14 +71,14 @@ class ODSSheet(SheetReader): value = cell.getAttrNS(OFFICENS, value_token) currency = cell.getAttrNS(OFFICENS, cell_type) if currency: - ret = value + ' ' + currency + ret = value + " " + currency else: ret = value else: if cell_type in service.VALUE_CONVERTERS: value = cell.getAttrNS(OFFICENS, value_token) n_value = service.VALUE_CONVERTERS[cell_type](value) - if cell_type == 'float' and self.__auto_detect_int: + if cell_type == "float" and self.__auto_detect_int: if service.has_no_digits_in_float(n_value): n_value = int(n_value) ret = n_value @@ -92,14 +93,15 @@ class ODSSheet(SheetReader): # for each text node for paragraph in paragraphs: name_space, tag = paragraph.parentNode.qname - if tag != str('annotation'): + if tag != str("annotation"): data = extractText(paragraph) text_content.append(data) - return '\n'.join(text_content) + return "\n".join(text_content) class ODSBook(BookReader): """read ods book""" + def open(self, file_name, **keywords): """open ods file""" BookReader.open(self, file_name, **keywords) @@ -113,8 +115,11 @@ class ODSBook(BookReader): def read_sheet_by_name(self, sheet_name): """read a named sheet""" tables = self._native_book.spreadsheet.getElementsByType(Table) - rets = [table for table in tables - if table.getAttribute('name') == sheet_name] + rets = [ + table + for table in tables + if table.getAttribute("name") == sheet_name + ] if len(rets) == 0: raise ValueError("%s cannot be found" % sheet_name) else: @@ -127,8 +132,9 @@ class ODSBook(BookReader): if sheet_index < length: return self.read_sheet(tables[sheet_index]) else: - raise IndexError("Index %d of out bound %d" % ( - sheet_index, length)) + raise IndexError( + "Index %d of out bound %d" % (sheet_index, length) + ) def read_all(self): """read all sheets""" diff --git a/pyexcel_ods/odsw.py b/pyexcel_ods/odsw.py index 3be88c2..c911517 100644 --- a/pyexcel_ods/odsw.py +++ b/pyexcel_ods/odsw.py @@ -9,16 +9,14 @@ """ import sys -from odf.table import TableRow, TableCell, Table -from odf.text import P +import pyexcel_io.service as converter from odf.namespaces import OFFICENS from odf.opendocument import OpenDocumentSpreadsheet - +from odf.table import Table, TableCell, TableRow +from odf.text import P from pyexcel_io.book import BookWriter from pyexcel_io.sheet import SheetWriter -import pyexcel_io.service as converter - PY2 = sys.version_info[0] == 2 PY27_BELOW = PY2 and sys.version_info[1] < 7 @@ -28,6 +26,7 @@ class ODSSheetWriter(SheetWriter): """ ODS sheet writer """ + def set_sheet_name(self, name): """initialize the native table""" self._native_sheet = Table(name=name) @@ -41,19 +40,22 @@ class ODSSheetWriter(SheetWriter): cell_to_be_written = TableCell() cell_type = type(cell) cell_odf_type = converter.ODS_WRITE_FORMAT_COVERSION.get( - cell_type, "string") + cell_type, "string" + ) cell_to_be_written.setAttrNS(OFFICENS, "value-type", cell_odf_type) cell_odf_value_token = converter.VALUE_TOKEN.get( - cell_odf_type, "value") + cell_odf_type, "value" + ) converter_func = converter.ODS_VALUE_CONVERTERS.get( - cell_odf_type, None) + cell_odf_type, None + ) if converter_func: cell = converter_func(cell) - if cell_odf_type != 'string': + if cell_odf_type != "string": cell_to_be_written.setAttrNS(OFFICENS, cell_odf_value_token, cell) cell_to_be_written.addElement(P(text=cell)) else: - lines = cell.split('\n') + lines = cell.split("\n") for line in lines: cell_to_be_written.addElement(P(text=line)) row.addElement(cell_to_be_written) @@ -80,6 +82,7 @@ class ODSWriter(BookWriter): open document spreadsheet writer """ + def __init__(self): BookWriter.__init__(self) self._native_book = OpenDocumentSpreadsheet() diff --git a/setup.py b/setup.py index 1199d49..98d8564 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,12 @@ #!/usr/bin/env python3 +import codecs # Template by pypi-mobans import os import sys -import codecs from shutil import rmtree -from setuptools import Command, setup, find_packages - +from setuptools import Command, find_packages, setup NAME = 'pyexcel-ods' AUTHOR = 'C.W.' diff --git a/tests/base.py b/tests/base.py index e469574..c312a6a 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1,11 +1,12 @@ -import os # noqa -import pyexcel import datetime # noqa -from nose.tools import raises, eq_ # noqa +import os # noqa + +import pyexcel +from nose.tools import eq_, raises # noqa def create_sample_file1(file): - data = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1.1, 1] + data = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 1.1, 1] table = [] table.append(data[:4]) table.append(data[4:8]) @@ -17,10 +18,11 @@ class PyexcelHatWriterBase: """ Abstract functional test for hat writers """ + content = { "X": [1, 2, 3, 4, 5], "Y": [6, 7, 8, 9, 10], - "Z": [11, 12, 13, 14, 15] + "Z": [11, 12, 13, 14, 15], } def test_series_table(self): @@ -36,11 +38,12 @@ class PyexcelWriterBase: testfile and testfile2 have to be initialized before it is used for testing """ + content = [ [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], - [1, 2, 3, 4, 5] + [1, 2, 3, 4, 5], ] def _create_a_file(self, file): @@ -54,7 +57,6 @@ class PyexcelWriterBase: class PyexcelMultipleSheetBase: - def _write_test_file(self, filename): pyexcel.save_book_as(bookdict=self.content, dest_file_name=filename) @@ -80,7 +82,7 @@ class PyexcelMultipleSheetBase: expected = [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]] assert data == expected data = list(b["Sheet3"].rows()) - expected = [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]] + expected = [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]] assert data == expected sheet3 = b["Sheet3"] sheet3.name_columns_by_row(0) @@ -90,7 +92,6 @@ class PyexcelMultipleSheetBase: class ODSCellTypes: - def test_formats(self): # date formats date_format = "%d/%m/%Y" @@ -104,9 +105,10 @@ class ODSCellTypes: eq_(self.data["Sheet1"][1][1].strftime(time_format), "12:12:11") eq_(self.data["Sheet1"][2][1].strftime(time_format), "12:00:00") eq_(self.data["Sheet1"][3][1], 0) - eq_(self.data["Sheet1"][4][1], datetime.timedelta(hours=27, - minutes=17, - seconds=54)) + eq_( + self.data["Sheet1"][4][1], + datetime.timedelta(hours=27, minutes=17, seconds=54), + ) eq_(self.data["Sheet1"][5][1], "Other") # boolean eq_(self.data["Sheet1"][0][2], "Boolean") @@ -117,8 +119,8 @@ class ODSCellTypes: eq_(self.data["Sheet1"][1][3], 11.11) # Currency eq_(self.data["Sheet1"][0][4], "Currency") - eq_(self.data["Sheet1"][1][4], '1 GBP') - eq_(self.data["Sheet1"][2][4], '-10000 GBP') + eq_(self.data["Sheet1"][1][4], "1 GBP") + eq_(self.data["Sheet1"][2][4], "-10000 GBP") # Percentage eq_(self.data["Sheet1"][0][5], "Percentage") eq_(self.data["Sheet1"][1][5], 2) diff --git a/tests/test_bug_fixes.py b/tests/test_bug_fixes.py index a99b9cc..72ab370 100644 --- a/tests/test_bug_fixes.py +++ b/tests/test_bug_fixes.py @@ -1,19 +1,21 @@ #!/usr/bin/python # -*- encoding: utf-8 -*- import os + import psutil import pyexcel as pe -from pyexcel_ods import get_data, save_data -from pyexcel_io.exceptions import IntegerAccuracyLossError -from nose.tools import raises, eq_ from nose import SkipTest +from nose.tools import eq_, raises +from pyexcel_io.exceptions import IntegerAccuracyLossError -IN_TRAVIS = 'TRAVIS' in os.environ +from pyexcel_ods import get_data, save_data + +IN_TRAVIS = "TRAVIS" in os.environ def test_bug_fix_for_issue_1(): data = get_data(get_fixtures("repeated.ods")) - eq_(data["Sheet1"], [['repeated', 'repeated', 'repeated', 'repeated']]) + eq_(data["Sheet1"], [["repeated", "repeated", "repeated", "repeated"]]) def test_bug_fix_for_issue_2(): @@ -22,12 +24,13 @@ def test_bug_fix_for_issue_2(): data.update({"Sheet 2": [[u"row 1", u"Héllô!", u"HolÁ!"]]}) save_data("your_file.ods", data) new_data = get_data("your_file.ods") - assert new_data["Sheet 2"] == [[u'row 1', u'H\xe9ll\xf4!', u'Hol\xc1!']] + assert new_data["Sheet 2"] == [[u"row 1", u"H\xe9ll\xf4!", u"Hol\xc1!"]] @raises(Exception) def test_invalid_date(): from pyexcel_ods.ods import date_value + value = "2015-08-" date_value(value) @@ -35,30 +38,27 @@ def test_invalid_date(): @raises(Exception) def test_fake_date_time_10(): from pyexcel_ods.ods import date_value + date_value("1234567890") @raises(Exception) def test_fake_date_time_19(): from pyexcel_ods.ods import date_value + date_value("1234567890123456789") @raises(Exception) def test_fake_date_time_20(): from pyexcel_ods.ods import date_value + date_value("12345678901234567890") def test_issue_13(): test_file = "test_issue_13.ods" - data = [ - [1, 2], - [], - [], - [], - [3, 4] - ] + data = [[1, 2], [], [], [], [3, 4]] save_data(test_file, {test_file: data}) written_data = get_data(test_file, skip_empty_rows=False) eq_(data, written_data[test_file]) @@ -68,23 +68,20 @@ def test_issue_13(): def test_issue_14(): # pyexcel issue 61 test_file = "issue_61.ods" - data = get_data(get_fixtures(test_file), - skip_empty_rows=True) - eq_(data['S-LMC'], [[u'aaa'], [0]]) + data = get_data(get_fixtures(test_file), skip_empty_rows=True) + eq_(data["S-LMC"], [[u"aaa"], [0]]) def test_issue_6(): test_file = "12_day_as_time.ods" - data = get_data(get_fixtures(test_file), - skip_empty_rows=True) - eq_(data['Sheet1'][0][0].days, 12) + data = get_data(get_fixtures(test_file), skip_empty_rows=True) + eq_(data["Sheet1"][0][0].days, 12) def test_issue_19(): test_file = "pyexcel_81_ods_19.ods" - data = get_data(get_fixtures(test_file), - skip_empty_rows=True) - eq_(data['product.template'][1][1], 'PRODUCT NAME PMP') + data = get_data(get_fixtures(test_file), skip_empty_rows=True) + eq_(data["product.template"][1][1], "PRODUCT NAME PMP") def test_issue_83_ods_file_handle(): @@ -95,7 +92,7 @@ def test_issue_83_ods_file_handle(): open_files_l1 = proc.open_files() # start with a csv file - data = pe.iget_array(file_name=test_file, library='pyexcel-ods') + data = pe.iget_array(file_name=test_file, library="pyexcel-ods") open_files_l2 = proc.open_files() delta = len(open_files_l2) - len(open_files_l1) # cannot catch open file handle @@ -120,25 +117,27 @@ def test_pr_22(): test_file = get_fixtures("white_space.ods") data = get_data(test_file) # OrderedDict([(u'Sheet1', [[u'paragraph with tab, space, new line']])]) - eq_(data['Sheet1'][0][0], 'paragraph with tab(\t), space, \nnew line') + eq_(data["Sheet1"][0][0], "paragraph with tab(\t), space, \nnew line") def test_issue_23(): if not IN_TRAVIS: raise SkipTest() - pe.get_book(url="https://github.com/pyexcel/pyexcel-ods/raw/master/tests/fixtures/white_space.ods") # noqa: E501 + pe.get_book( + url="https://github.com/pyexcel/pyexcel-ods/raw/master/tests/fixtures/white_space.ods" + ) # noqa: E501 def test_issue_24(): test_file = get_fixtures("comment-in-cell.ods") data = get_data(test_file) - eq_(data['Sheet1'], [['test']]) + eq_(data["Sheet1"], [["test"]]) def test_issue_27(): test_file = get_fixtures("issue_27.ods") data = get_data(test_file, skip_empty_rows=True) - eq_(data['VGPMX'], [['', 'Cost Basis', '0']]) + eq_(data["VGPMX"], [["", "Cost Basis", "0"]]) def test_issue_30(): diff --git a/tests/test_filter.py b/tests/test_filter.py index b74bc4c..67d8876 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -1,7 +1,7 @@ import os -from pyexcel_io import get_data, save_data from nose.tools import eq_ +from pyexcel_io import get_data, save_data class TestFilter: @@ -13,49 +13,58 @@ class TestFilter: [3, 23, 33], [4, 24, 34], [5, 25, 35], - [6, 26, 36] + [6, 26, 36], ] save_data(self.test_file, sample) self.sheet_name = "pyexcel_sheet1" def test_filter_row(self): - filtered_data = get_data(self.test_file, start_row=3, - library="pyexcel-ods") + filtered_data = get_data( + self.test_file, start_row=3, library="pyexcel-ods" + ) expected = [[4, 24, 34], [5, 25, 35], [6, 26, 36]] eq_(filtered_data[self.sheet_name], expected) def test_filter_row_2(self): - filtered_data = get_data(self.test_file, start_row=3, row_limit=1, - library="pyexcel-ods") + filtered_data = get_data( + self.test_file, start_row=3, row_limit=1, library="pyexcel-ods" + ) expected = [[4, 24, 34]] eq_(filtered_data[self.sheet_name], expected) def test_filter_column(self): - filtered_data = get_data(self.test_file, start_column=1, - library="pyexcel-ods") - expected = [[21, 31], [22, 32], [23, 33], - [24, 34], [25, 35], [26, 36]] + filtered_data = get_data( + self.test_file, start_column=1, library="pyexcel-ods" + ) + expected = [[21, 31], [22, 32], [23, 33], [24, 34], [25, 35], [26, 36]] eq_(filtered_data[self.sheet_name], expected) def test_filter_column_2(self): - filtered_data = get_data(self.test_file, - start_column=1, column_limit=1, - library="pyexcel-ods") + filtered_data = get_data( + self.test_file, + start_column=1, + column_limit=1, + library="pyexcel-ods", + ) expected = [[21], [22], [23], [24], [25], [26]] eq_(filtered_data[self.sheet_name], expected) def test_filter_both_ways(self): - filtered_data = get_data(self.test_file, - start_column=1, start_row=3, - library="pyexcel-ods") + filtered_data = get_data( + self.test_file, start_column=1, start_row=3, library="pyexcel-ods" + ) expected = [[24, 34], [25, 35], [26, 36]] eq_(filtered_data[self.sheet_name], expected) def test_filter_both_ways_2(self): - filtered_data = get_data(self.test_file, - start_column=1, column_limit=1, - start_row=3, row_limit=1, - library="pyexcel-ods") + filtered_data = get_data( + self.test_file, + start_column=1, + column_limit=1, + start_row=3, + row_limit=1, + library="pyexcel-ods", + ) expected = [[24]] eq_(filtered_data[self.sheet_name], expected) diff --git a/tests/test_formatters.py b/tests/test_formatters.py index b0f261f..ba78ec2 100644 --- a/tests/test_formatters.py +++ b/tests/test_formatters.py @@ -1,54 +1,66 @@ import os from textwrap import dedent -from nose.tools import eq_ import pyexcel as pe +from nose.tools import eq_ class TestAutoDetectInt: def setUp(self): self.content = [[1, 2, 3.1]] self.test_file = "test_auto_detect_init.ods" - pe.save_as( - array=self.content, dest_file_name=self.test_file - ) + pe.save_as(array=self.content, dest_file_name=self.test_file) def test_auto_detect_int(self): sheet = pe.get_sheet(file_name=self.test_file, library="pyexcel-ods") - expected = dedent(""" + expected = dedent( + """ pyexcel_sheet1: +---+---+-----+ | 1 | 2 | 3.1 | - +---+---+-----+""").strip() + +---+---+-----+""" + ).strip() eq_(str(sheet), expected) def test_get_book_auto_detect_int(self): book = pe.get_book(file_name=self.test_file, library="pyexcel-ods") - expected = dedent(""" + expected = dedent( + """ pyexcel_sheet1: +---+---+-----+ | 1 | 2 | 3.1 | - +---+---+-----+""").strip() + +---+---+-----+""" + ).strip() eq_(str(book), expected) def test_auto_detect_int_false(self): - sheet = pe.get_sheet(file_name=self.test_file, auto_detect_int=False, - library="pyexcel-ods") - expected = dedent(""" + sheet = pe.get_sheet( + file_name=self.test_file, + auto_detect_int=False, + library="pyexcel-ods", + ) + expected = dedent( + """ pyexcel_sheet1: +-----+-----+-----+ | 1.0 | 2.0 | 3.1 | - +-----+-----+-----+""").strip() + +-----+-----+-----+""" + ).strip() eq_(str(sheet), expected) def test_get_book_auto_detect_int_false(self): - book = pe.get_book(file_name=self.test_file, auto_detect_int=False, - library="pyexcel-ods") - expected = dedent(""" + book = pe.get_book( + file_name=self.test_file, + auto_detect_int=False, + library="pyexcel-ods", + ) + expected = dedent( + """ pyexcel_sheet1: +-----+-----+-----+ | 1.0 | 2.0 | 3.1 | - +-----+-----+-----+""").strip() + +-----+-----+-----+""" + ).strip() eq_(str(book), expected) def tearDown(self): diff --git a/tests/test_multiline_feature.py b/tests/test_multiline_feature.py index 8d049a4..aa2c870 100644 --- a/tests/test_multiline_feature.py +++ b/tests/test_multiline_feature.py @@ -1,12 +1,13 @@ import os + import pyexcel def test_reading_multiline_ods(): testfile = os.path.join("tests", "fixtures", "multilineods.ods") sheet = pyexcel.get_sheet(file_name=testfile) - assert sheet[0, 0] == '1\n2\n3\n4' - assert sheet[1, 0] == 'Line 1\n\nLine 2' + assert sheet[0, 0] == "1\n2\n3\n4" + assert sheet[1, 0] == "Line 1\n\nLine 2" def test_writing_multiline_ods(): diff --git a/tests/test_multiple_sheets.py b/tests/test_multiple_sheets.py index 6d60dbb..6360be6 100644 --- a/tests/test_multiple_sheets.py +++ b/tests/test_multiple_sheets.py @@ -1,7 +1,9 @@ import os import sys + import pyexcel from nose.tools import raises + from base import PyexcelMultipleSheetBase if sys.version_info[0] == 2 and sys.version_info[1] < 7: @@ -42,8 +44,7 @@ class TestAddBooks: 3,3,3,3 """ self.rows = 3 - pyexcel.save_book_as(bookdict=self.content, - dest_file_name=file) + pyexcel.save_book_as(bookdict=self.content, dest_file_name=file) def setUp(self): self.testfile = "multiple1.ods" @@ -55,12 +56,12 @@ class TestAddBooks: def test_load_a_single_sheet(self): b1 = pyexcel.get_book(file_name=self.testfile, sheet_name="Sheet1") assert len(b1.sheet_names()) == 1 - assert b1['Sheet1'].to_array() == self.content['Sheet1'] + assert b1["Sheet1"].to_array() == self.content["Sheet1"] def test_load_a_single_sheet2(self): b1 = pyexcel.load_book(self.testfile, sheet_index=0) assert len(b1.sheet_names()) == 1 - assert b1['Sheet1'].to_array() == self.content['Sheet1'] + assert b1["Sheet1"].to_array() == self.content["Sheet1"] @raises(IndexError) def test_load_a_single_sheet3(self): @@ -229,17 +230,17 @@ class TestMultiSheetReader: self.testfile = "file_with_an_empty_sheet.ods" def test_reader_with_correct_sheets(self): - r = pyexcel.BookReader(os.path.join("tests", "fixtures", - self.testfile)) + r = pyexcel.BookReader( + os.path.join("tests", "fixtures", self.testfile) + ) assert r.number_of_sheets() == 3 def _produce_ordered_dict(): data_dict = OrderedDict() - data_dict.update({ - "Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]}) - data_dict.update({ - "Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]}) - data_dict.update({ - "Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]}) + data_dict.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]}) + data_dict.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]}) + data_dict.update( + {"Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]} + ) return data_dict diff --git a/tests/test_ods_reader.py b/tests/test_ods_reader.py index cf7c1f3..69bb030 100644 --- a/tests/test_ods_reader.py +++ b/tests/test_ods_reader.py @@ -1,15 +1,14 @@ import os + +from base import ODSCellTypes from pyexcel_ods.odsr import ODSBook from pyexcel_ods.odsw import ODSWriter -from base import ODSCellTypes class TestODSReader(ODSCellTypes): def setUp(self): r = ODSBook() - r.open(os.path.join("tests", - "fixtures", - "ods_formats.ods")) + r.open(os.path.join("tests", "fixtures", "ods_formats.ods")) self.data = r.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) @@ -19,9 +18,7 @@ class TestODSReader(ODSCellTypes): class TestODSWriter(ODSCellTypes): def setUp(self): r = ODSBook() - r.open(os.path.join("tests", - "fixtures", - "ods_formats.ods")) + r.open(os.path.join("tests", "fixtures", "ods_formats.ods")) self.data1 = r.read_all() self.testfile = "odswriter.ods" w = ODSWriter() diff --git a/tests/test_stringio.py b/tests/test_stringio.py index f29a465..442a464 100644 --- a/tests/test_stringio.py +++ b/tests/test_stringio.py @@ -1,33 +1,32 @@ import os + import pyexcel from nose.tools import eq_ + from base import create_sample_file1 class TestStringIO: - def test_ods_stringio(self): testfile = "cute.ods" create_sample_file1(testfile) with open(testfile, "rb") as f: content = f.read() - r = pyexcel.get_sheet(file_type="ods", file_content=content, - library="pyexcel-ods") - result = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1.1, 1] + r = pyexcel.get_sheet( + file_type="ods", file_content=content, library="pyexcel-ods" + ) + result = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 1.1, 1] actual = list(r.enumerate()) eq_(result, actual) if os.path.exists(testfile): os.unlink(testfile) def test_ods_output_stringio(self): - data = [ - [1, 2, 3], - [4, 5, 6] - ] - io = pyexcel.save_as(dest_file_type="ods", - array=data) - r = pyexcel.get_sheet(file_type="ods", file_content=io.getvalue(), - library="pyexcel-ods") + data = [[1, 2, 3], [4, 5, 6]] + io = pyexcel.save_as(dest_file_type="ods", array=data) + r = pyexcel.get_sheet( + file_type="ods", file_content=io.getvalue(), library="pyexcel-ods" + ) result = [1, 2, 3, 4, 5, 6] actual = list(r.enumerate()) eq_(result, actual) diff --git a/tests/test_writer.py b/tests/test_writer.py index 5dec2db..ab5a976 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -1,7 +1,8 @@ import os -from pyexcel_ods.odsw import ODSWriter as Writer + +from base import PyexcelHatWriterBase, PyexcelWriterBase from pyexcel_ods.odsr import ODSBook as Reader -from base import PyexcelWriterBase, PyexcelHatWriterBase +from pyexcel_ods.odsw import ODSWriter as Writer class TestNativeODSWriter: @@ -9,7 +10,7 @@ class TestNativeODSWriter: self.content = { "Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], "Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]], - "Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]] + "Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]], } self.testfile = "writer.ods" writer = Writer()