Codebase list pyexcel-ods / ce04e9e
:hammer: make format using isort and black chfw 5 years ago
13 changed file(s) with 178 addition(s) and 145 deletion(s). Raw diff Collapse all Expand all
88 # this line has to be place above all else
99 # because of dynamic import
1010 from pyexcel_io.plugins import IOPluginInfoChain
11 from pyexcel_io.io import get_data as read_data, isstream, store_data as write_data
11 from pyexcel_io.io import (
12 get_data as read_data,
13 isstream,
14 store_data as write_data,
15 )
1216
13 __FILE_TYPE__ = 'ods'
17 __FILE_TYPE__ = "ods"
1418 IOPluginInfoChain(__name__).add_a_reader(
15 relative_plugin_class_path='odsr.ODSBook',
19 relative_plugin_class_path="odsr.ODSBook",
1620 file_types=[__FILE_TYPE__],
17 stream_type='binary'
21 stream_type="binary",
1822 ).add_a_writer(
19 relative_plugin_class_path='odsw.ODSWriter',
23 relative_plugin_class_path="odsw.ODSWriter",
2024 file_types=[__FILE_TYPE__],
21 stream_type='binary'
25 stream_type="binary",
2226 )
2327
2428
2020 # See the License for the specific language governing permissions and
2121 # limitations under the License.
2222
23 import pyexcel_io.service as service
24 from odf.namespaces import OFFICENS
25 from odf.opendocument import load
26 from odf.table import Table, TableCell, TableRow
27
2328 # Thanks to grt for the fixes
2429 from odf.teletype import extractText
25 from odf.table import TableRow, TableCell, Table
2630 from odf.text import P
27 from odf.namespaces import OFFICENS
28 from odf.opendocument import load
29
31 from pyexcel_io._compact import OrderedDict
3032 from pyexcel_io.book import BookReader
3133 from pyexcel_io.sheet import SheetReader
32 from pyexcel_io._compact import OrderedDict
33 import pyexcel_io.service as service
3434
3535
3636 class ODSSheet(SheetReader):
3737 """native ods sheet"""
38
3839 def __init__(self, sheet, auto_detect_int=True, **keywords):
3940 SheetReader.__init__(self, sheet, **keywords)
4041 self.__auto_detect_int = auto_detect_int
6970 value = cell.getAttrNS(OFFICENS, value_token)
7071 currency = cell.getAttrNS(OFFICENS, cell_type)
7172 if currency:
72 ret = value + ' ' + currency
73 ret = value + " " + currency
7374 else:
7475 ret = value
7576 else:
7677 if cell_type in service.VALUE_CONVERTERS:
7778 value = cell.getAttrNS(OFFICENS, value_token)
7879 n_value = service.VALUE_CONVERTERS[cell_type](value)
79 if cell_type == 'float' and self.__auto_detect_int:
80 if cell_type == "float" and self.__auto_detect_int:
8081 if service.has_no_digits_in_float(n_value):
8182 n_value = int(n_value)
8283 ret = n_value
9192 # for each text node
9293 for paragraph in paragraphs:
9394 name_space, tag = paragraph.parentNode.qname
94 if tag != str('annotation'):
95 if tag != str("annotation"):
9596 data = extractText(paragraph)
9697 text_content.append(data)
97 return '\n'.join(text_content)
98 return "\n".join(text_content)
9899
99100
100101 class ODSBook(BookReader):
101102 """read ods book"""
103
102104 def open(self, file_name, **keywords):
103105 """open ods file"""
104106 BookReader.open(self, file_name, **keywords)
112114 def read_sheet_by_name(self, sheet_name):
113115 """read a named sheet"""
114116 tables = self._native_book.spreadsheet.getElementsByType(Table)
115 rets = [table for table in tables
116 if table.getAttribute('name') == sheet_name]
117 rets = [
118 table
119 for table in tables
120 if table.getAttribute("name") == sheet_name
121 ]
117122 if len(rets) == 0:
118123 raise ValueError("%s cannot be found" % sheet_name)
119124 else:
126131 if sheet_index < length:
127132 return self.read_sheet(tables[sheet_index])
128133 else:
129 raise IndexError("Index %d of out bound %d" % (
130 sheet_index, length))
134 raise IndexError(
135 "Index %d of out bound %d" % (sheet_index, length)
136 )
131137
132138 def read_all(self):
133139 """read all sheets"""
88 """
99 import sys
1010
11 from odf.table import TableRow, TableCell, Table
12 from odf.text import P
11 import pyexcel_io.service as converter
1312 from odf.namespaces import OFFICENS
1413 from odf.opendocument import OpenDocumentSpreadsheet
15
14 from odf.table import Table, TableCell, TableRow
15 from odf.text import P
1616 from pyexcel_io.book import BookWriter
1717 from pyexcel_io.sheet import SheetWriter
18
19 import pyexcel_io.service as converter
2018
2119 PY2 = sys.version_info[0] == 2
2220
2725 """
2826 ODS sheet writer
2927 """
28
3029 def set_sheet_name(self, name):
3130 """initialize the native table"""
3231 self._native_sheet = Table(name=name)
4039 cell_to_be_written = TableCell()
4140 cell_type = type(cell)
4241 cell_odf_type = converter.ODS_WRITE_FORMAT_COVERSION.get(
43 cell_type, "string")
42 cell_type, "string"
43 )
4444 cell_to_be_written.setAttrNS(OFFICENS, "value-type", cell_odf_type)
4545 cell_odf_value_token = converter.VALUE_TOKEN.get(
46 cell_odf_type, "value")
46 cell_odf_type, "value"
47 )
4748 converter_func = converter.ODS_VALUE_CONVERTERS.get(
48 cell_odf_type, None)
49 cell_odf_type, None
50 )
4951 if converter_func:
5052 cell = converter_func(cell)
51 if cell_odf_type != 'string':
53 if cell_odf_type != "string":
5254 cell_to_be_written.setAttrNS(OFFICENS, cell_odf_value_token, cell)
5355 cell_to_be_written.addElement(P(text=cell))
5456 else:
55 lines = cell.split('\n')
57 lines = cell.split("\n")
5658 for line in lines:
5759 cell_to_be_written.addElement(P(text=line))
5860 row.addElement(cell_to_be_written)
7981 open document spreadsheet writer
8082
8183 """
84
8285 def __init__(self):
8386 BookWriter.__init__(self)
8487 self._native_book = OpenDocumentSpreadsheet()
00 #!/usr/bin/env python3
11
2 import codecs
23 # Template by pypi-mobans
34 import os
45 import sys
5 import codecs
66 from shutil import rmtree
77
8 from setuptools import Command, setup, find_packages
9
8 from setuptools import Command, find_packages, setup
109
1110 NAME = 'pyexcel-ods'
1211 AUTHOR = 'C.W.'
0 import datetime # noqa
01 import os # noqa
2
13 import pyexcel
2 import datetime # noqa
3 from nose.tools import raises, eq_ # noqa
4 from nose.tools import eq_, raises # noqa
45
56
67 def create_sample_file1(file):
7 data = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1.1, 1]
8 data = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 1.1, 1]
89 table = []
910 table.append(data[:4])
1011 table.append(data[4:8])
1617 """
1718 Abstract functional test for hat writers
1819 """
20
1921 content = {
2022 "X": [1, 2, 3, 4, 5],
2123 "Y": [6, 7, 8, 9, 10],
22 "Z": [11, 12, 13, 14, 15]
24 "Z": [11, 12, 13, 14, 15],
2325 }
2426
2527 def test_series_table(self):
3537 testfile and testfile2 have to be initialized before
3638 it is used for testing
3739 """
40
3841 content = [
3942 [1, 2, 3, 4, 5],
4043 [1, 2, 3, 4, 5],
4144 [1, 2, 3, 4, 5],
42 [1, 2, 3, 4, 5]
45 [1, 2, 3, 4, 5],
4346 ]
4447
4548 def _create_a_file(self, file):
5356
5457
5558 class PyexcelMultipleSheetBase:
56
5759 def _write_test_file(self, filename):
5860 pyexcel.save_book_as(bookdict=self.content, dest_file_name=filename)
5961
7981 expected = [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]
8082 assert data == expected
8183 data = list(b["Sheet3"].rows())
82 expected = [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
84 expected = [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
8385 assert data == expected
8486 sheet3 = b["Sheet3"]
8587 sheet3.name_columns_by_row(0)
8991
9092
9193 class ODSCellTypes:
92
9394 def test_formats(self):
9495 # date formats
9596 date_format = "%d/%m/%Y"
103104 eq_(self.data["Sheet1"][1][1].strftime(time_format), "12:12:11")
104105 eq_(self.data["Sheet1"][2][1].strftime(time_format), "12:00:00")
105106 eq_(self.data["Sheet1"][3][1], 0)
106 eq_(self.data["Sheet1"][4][1], datetime.timedelta(hours=27,
107 minutes=17,
108 seconds=54))
107 eq_(
108 self.data["Sheet1"][4][1],
109 datetime.timedelta(hours=27, minutes=17, seconds=54),
110 )
109111 eq_(self.data["Sheet1"][5][1], "Other")
110112 # boolean
111113 eq_(self.data["Sheet1"][0][2], "Boolean")
116118 eq_(self.data["Sheet1"][1][3], 11.11)
117119 # Currency
118120 eq_(self.data["Sheet1"][0][4], "Currency")
119 eq_(self.data["Sheet1"][1][4], '1 GBP')
120 eq_(self.data["Sheet1"][2][4], '-10000 GBP')
121 eq_(self.data["Sheet1"][1][4], "1 GBP")
122 eq_(self.data["Sheet1"][2][4], "-10000 GBP")
121123 # Percentage
122124 eq_(self.data["Sheet1"][0][5], "Percentage")
123125 eq_(self.data["Sheet1"][1][5], 2)
00 #!/usr/bin/python
11 # -*- encoding: utf-8 -*-
22 import os
3
34 import psutil
45 import pyexcel as pe
6 from nose import SkipTest
7 from nose.tools import eq_, raises
8 from pyexcel_io.exceptions import IntegerAccuracyLossError
9
510 from pyexcel_ods import get_data, save_data
6 from pyexcel_io.exceptions import IntegerAccuracyLossError
7 from nose.tools import raises, eq_
8 from nose import SkipTest
911
10 IN_TRAVIS = 'TRAVIS' in os.environ
12 IN_TRAVIS = "TRAVIS" in os.environ
1113
1214
1315 def test_bug_fix_for_issue_1():
1416 data = get_data(get_fixtures("repeated.ods"))
15 eq_(data["Sheet1"], [['repeated', 'repeated', 'repeated', 'repeated']])
17 eq_(data["Sheet1"], [["repeated", "repeated", "repeated", "repeated"]])
1618
1719
1820 def test_bug_fix_for_issue_2():
2123 data.update({"Sheet 2": [[u"row 1", u"Héllô!", u"HolÁ!"]]})
2224 save_data("your_file.ods", data)
2325 new_data = get_data("your_file.ods")
24 assert new_data["Sheet 2"] == [[u'row 1', u'H\xe9ll\xf4!', u'Hol\xc1!']]
26 assert new_data["Sheet 2"] == [[u"row 1", u"H\xe9ll\xf4!", u"Hol\xc1!"]]
2527
2628
2729 @raises(Exception)
2830 def test_invalid_date():
2931 from pyexcel_ods.ods import date_value
32
3033 value = "2015-08-"
3134 date_value(value)
3235
3437 @raises(Exception)
3538 def test_fake_date_time_10():
3639 from pyexcel_ods.ods import date_value
40
3741 date_value("1234567890")
3842
3943
4044 @raises(Exception)
4145 def test_fake_date_time_19():
4246 from pyexcel_ods.ods import date_value
47
4348 date_value("1234567890123456789")
4449
4550
4651 @raises(Exception)
4752 def test_fake_date_time_20():
4853 from pyexcel_ods.ods import date_value
54
4955 date_value("12345678901234567890")
5056
5157
5258 def test_issue_13():
5359 test_file = "test_issue_13.ods"
54 data = [
55 [1, 2],
56 [],
57 [],
58 [],
59 [3, 4]
60 ]
60 data = [[1, 2], [], [], [], [3, 4]]
6161 save_data(test_file, {test_file: data})
6262 written_data = get_data(test_file, skip_empty_rows=False)
6363 eq_(data, written_data[test_file])
6767 def test_issue_14():
6868 # pyexcel issue 61
6969 test_file = "issue_61.ods"
70 data = get_data(get_fixtures(test_file),
71 skip_empty_rows=True)
72 eq_(data['S-LMC'], [[u'aaa'], [0]])
70 data = get_data(get_fixtures(test_file), skip_empty_rows=True)
71 eq_(data["S-LMC"], [[u"aaa"], [0]])
7372
7473
7574 def test_issue_6():
7675 test_file = "12_day_as_time.ods"
77 data = get_data(get_fixtures(test_file),
78 skip_empty_rows=True)
79 eq_(data['Sheet1'][0][0].days, 12)
76 data = get_data(get_fixtures(test_file), skip_empty_rows=True)
77 eq_(data["Sheet1"][0][0].days, 12)
8078
8179
8280 def test_issue_19():
8381 test_file = "pyexcel_81_ods_19.ods"
84 data = get_data(get_fixtures(test_file),
85 skip_empty_rows=True)
86 eq_(data['product.template'][1][1], 'PRODUCT NAME PMP')
82 data = get_data(get_fixtures(test_file), skip_empty_rows=True)
83 eq_(data["product.template"][1][1], "PRODUCT NAME PMP")
8784
8885
8986 def test_issue_83_ods_file_handle():
9491 open_files_l1 = proc.open_files()
9592
9693 # start with a csv file
97 data = pe.iget_array(file_name=test_file, library='pyexcel-ods')
94 data = pe.iget_array(file_name=test_file, library="pyexcel-ods")
9895 open_files_l2 = proc.open_files()
9996 delta = len(open_files_l2) - len(open_files_l1)
10097 # cannot catch open file handle
119116 test_file = get_fixtures("white_space.ods")
120117 data = get_data(test_file)
121118 # OrderedDict([(u'Sheet1', [[u'paragraph with tab, space, new line']])])
122 eq_(data['Sheet1'][0][0], 'paragraph with tab(\t), space, \nnew line')
119 eq_(data["Sheet1"][0][0], "paragraph with tab(\t), space, \nnew line")
123120
124121
125122 def test_issue_23():
126123 if not IN_TRAVIS:
127124 raise SkipTest()
128 pe.get_book(url="https://github.com/pyexcel/pyexcel-ods/raw/master/tests/fixtures/white_space.ods") # noqa: E501
125 pe.get_book(
126 url="https://github.com/pyexcel/pyexcel-ods/raw/master/tests/fixtures/white_space.ods"
127 ) # noqa: E501
129128
130129
131130 def test_issue_24():
132131 test_file = get_fixtures("comment-in-cell.ods")
133132 data = get_data(test_file)
134 eq_(data['Sheet1'], [['test']])
133 eq_(data["Sheet1"], [["test"]])
135134
136135
137136 def test_issue_27():
138137 test_file = get_fixtures("issue_27.ods")
139138 data = get_data(test_file, skip_empty_rows=True)
140 eq_(data['VGPMX'], [['', 'Cost Basis', '0']])
139 eq_(data["VGPMX"], [["", "Cost Basis", "0"]])
141140
142141
143142 def test_issue_30():
00 import os
11
2 from nose.tools import eq_
23 from pyexcel_io import get_data, save_data
3 from nose.tools import eq_
44
55
66 class TestFilter:
1212 [3, 23, 33],
1313 [4, 24, 34],
1414 [5, 25, 35],
15 [6, 26, 36]
15 [6, 26, 36],
1616 ]
1717 save_data(self.test_file, sample)
1818 self.sheet_name = "pyexcel_sheet1"
1919
2020 def test_filter_row(self):
21 filtered_data = get_data(self.test_file, start_row=3,
22 library="pyexcel-ods")
21 filtered_data = get_data(
22 self.test_file, start_row=3, library="pyexcel-ods"
23 )
2324 expected = [[4, 24, 34], [5, 25, 35], [6, 26, 36]]
2425 eq_(filtered_data[self.sheet_name], expected)
2526
2627 def test_filter_row_2(self):
27 filtered_data = get_data(self.test_file, start_row=3, row_limit=1,
28 library="pyexcel-ods")
28 filtered_data = get_data(
29 self.test_file, start_row=3, row_limit=1, library="pyexcel-ods"
30 )
2931 expected = [[4, 24, 34]]
3032 eq_(filtered_data[self.sheet_name], expected)
3133
3234 def test_filter_column(self):
33 filtered_data = get_data(self.test_file, start_column=1,
34 library="pyexcel-ods")
35 expected = [[21, 31], [22, 32], [23, 33],
36 [24, 34], [25, 35], [26, 36]]
35 filtered_data = get_data(
36 self.test_file, start_column=1, library="pyexcel-ods"
37 )
38 expected = [[21, 31], [22, 32], [23, 33], [24, 34], [25, 35], [26, 36]]
3739 eq_(filtered_data[self.sheet_name], expected)
3840
3941 def test_filter_column_2(self):
40 filtered_data = get_data(self.test_file,
41 start_column=1, column_limit=1,
42 library="pyexcel-ods")
42 filtered_data = get_data(
43 self.test_file,
44 start_column=1,
45 column_limit=1,
46 library="pyexcel-ods",
47 )
4348 expected = [[21], [22], [23], [24], [25], [26]]
4449 eq_(filtered_data[self.sheet_name], expected)
4550
4651 def test_filter_both_ways(self):
47 filtered_data = get_data(self.test_file,
48 start_column=1, start_row=3,
49 library="pyexcel-ods")
52 filtered_data = get_data(
53 self.test_file, start_column=1, start_row=3, library="pyexcel-ods"
54 )
5055 expected = [[24, 34], [25, 35], [26, 36]]
5156 eq_(filtered_data[self.sheet_name], expected)
5257
5358 def test_filter_both_ways_2(self):
54 filtered_data = get_data(self.test_file,
55 start_column=1, column_limit=1,
56 start_row=3, row_limit=1,
57 library="pyexcel-ods")
59 filtered_data = get_data(
60 self.test_file,
61 start_column=1,
62 column_limit=1,
63 start_row=3,
64 row_limit=1,
65 library="pyexcel-ods",
66 )
5867 expected = [[24]]
5968 eq_(filtered_data[self.sheet_name], expected)
6069
00 import os
11 from textwrap import dedent
2 from nose.tools import eq_
32
43 import pyexcel as pe
4 from nose.tools import eq_
55
66
77 class TestAutoDetectInt:
88 def setUp(self):
99 self.content = [[1, 2, 3.1]]
1010 self.test_file = "test_auto_detect_init.ods"
11 pe.save_as(
12 array=self.content, dest_file_name=self.test_file
13 )
11 pe.save_as(array=self.content, dest_file_name=self.test_file)
1412
1513 def test_auto_detect_int(self):
1614 sheet = pe.get_sheet(file_name=self.test_file, library="pyexcel-ods")
17 expected = dedent("""
15 expected = dedent(
16 """
1817 pyexcel_sheet1:
1918 +---+---+-----+
2019 | 1 | 2 | 3.1 |
21 +---+---+-----+""").strip()
20 +---+---+-----+"""
21 ).strip()
2222 eq_(str(sheet), expected)
2323
2424 def test_get_book_auto_detect_int(self):
2525 book = pe.get_book(file_name=self.test_file, library="pyexcel-ods")
26 expected = dedent("""
26 expected = dedent(
27 """
2728 pyexcel_sheet1:
2829 +---+---+-----+
2930 | 1 | 2 | 3.1 |
30 +---+---+-----+""").strip()
31 +---+---+-----+"""
32 ).strip()
3133 eq_(str(book), expected)
3234
3335 def test_auto_detect_int_false(self):
34 sheet = pe.get_sheet(file_name=self.test_file, auto_detect_int=False,
35 library="pyexcel-ods")
36 expected = dedent("""
36 sheet = pe.get_sheet(
37 file_name=self.test_file,
38 auto_detect_int=False,
39 library="pyexcel-ods",
40 )
41 expected = dedent(
42 """
3743 pyexcel_sheet1:
3844 +-----+-----+-----+
3945 | 1.0 | 2.0 | 3.1 |
40 +-----+-----+-----+""").strip()
46 +-----+-----+-----+"""
47 ).strip()
4148 eq_(str(sheet), expected)
4249
4350 def test_get_book_auto_detect_int_false(self):
44 book = pe.get_book(file_name=self.test_file, auto_detect_int=False,
45 library="pyexcel-ods")
46 expected = dedent("""
51 book = pe.get_book(
52 file_name=self.test_file,
53 auto_detect_int=False,
54 library="pyexcel-ods",
55 )
56 expected = dedent(
57 """
4758 pyexcel_sheet1:
4859 +-----+-----+-----+
4960 | 1.0 | 2.0 | 3.1 |
50 +-----+-----+-----+""").strip()
61 +-----+-----+-----+"""
62 ).strip()
5163 eq_(str(book), expected)
5264
5365 def tearDown(self):
00 import os
1
12 import pyexcel
23
34
45 def test_reading_multiline_ods():
56 testfile = os.path.join("tests", "fixtures", "multilineods.ods")
67 sheet = pyexcel.get_sheet(file_name=testfile)
7 assert sheet[0, 0] == '1\n2\n3\n4'
8 assert sheet[1, 0] == 'Line 1\n\nLine 2'
8 assert sheet[0, 0] == "1\n2\n3\n4"
9 assert sheet[1, 0] == "Line 1\n\nLine 2"
910
1011
1112 def test_writing_multiline_ods():
00 import os
11 import sys
2
23 import pyexcel
34 from nose.tools import raises
5
46 from base import PyexcelMultipleSheetBase
57
68 if sys.version_info[0] == 2 and sys.version_info[1] < 7:
4143 3,3,3,3
4244 """
4345 self.rows = 3
44 pyexcel.save_book_as(bookdict=self.content,
45 dest_file_name=file)
46 pyexcel.save_book_as(bookdict=self.content, dest_file_name=file)
4647
4748 def setUp(self):
4849 self.testfile = "multiple1.ods"
5455 def test_load_a_single_sheet(self):
5556 b1 = pyexcel.get_book(file_name=self.testfile, sheet_name="Sheet1")
5657 assert len(b1.sheet_names()) == 1
57 assert b1['Sheet1'].to_array() == self.content['Sheet1']
58 assert b1["Sheet1"].to_array() == self.content["Sheet1"]
5859
5960 def test_load_a_single_sheet2(self):
6061 b1 = pyexcel.load_book(self.testfile, sheet_index=0)
6162 assert len(b1.sheet_names()) == 1
62 assert b1['Sheet1'].to_array() == self.content['Sheet1']
63 assert b1["Sheet1"].to_array() == self.content["Sheet1"]
6364
6465 @raises(IndexError)
6566 def test_load_a_single_sheet3(self):
228229 self.testfile = "file_with_an_empty_sheet.ods"
229230
230231 def test_reader_with_correct_sheets(self):
231 r = pyexcel.BookReader(os.path.join("tests", "fixtures",
232 self.testfile))
232 r = pyexcel.BookReader(
233 os.path.join("tests", "fixtures", self.testfile)
234 )
233235 assert r.number_of_sheets() == 3
234236
235237
236238 def _produce_ordered_dict():
237239 data_dict = OrderedDict()
238 data_dict.update({
239 "Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
240 data_dict.update({
241 "Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
242 data_dict.update({
243 "Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
240 data_dict.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
241 data_dict.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
242 data_dict.update(
243 {"Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]}
244 )
244245 return data_dict
00 import os
1
2 from base import ODSCellTypes
13 from pyexcel_ods.odsr import ODSBook
24 from pyexcel_ods.odsw import ODSWriter
3 from base import ODSCellTypes
45
56
67 class TestODSReader(ODSCellTypes):
78 def setUp(self):
89 r = ODSBook()
9 r.open(os.path.join("tests",
10 "fixtures",
11 "ods_formats.ods"))
10 r.open(os.path.join("tests", "fixtures", "ods_formats.ods"))
1211 self.data = r.read_all()
1312 for key in self.data.keys():
1413 self.data[key] = list(self.data[key])
1817 class TestODSWriter(ODSCellTypes):
1918 def setUp(self):
2019 r = ODSBook()
21 r.open(os.path.join("tests",
22 "fixtures",
23 "ods_formats.ods"))
20 r.open(os.path.join("tests", "fixtures", "ods_formats.ods"))
2421 self.data1 = r.read_all()
2522 self.testfile = "odswriter.ods"
2623 w = ODSWriter()
00 import os
1
12 import pyexcel
23 from nose.tools import eq_
4
35 from base import create_sample_file1
46
57
68 class TestStringIO:
7
89 def test_ods_stringio(self):
910 testfile = "cute.ods"
1011 create_sample_file1(testfile)
1112 with open(testfile, "rb") as f:
1213 content = f.read()
13 r = pyexcel.get_sheet(file_type="ods", file_content=content,
14 library="pyexcel-ods")
15 result = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1.1, 1]
14 r = pyexcel.get_sheet(
15 file_type="ods", file_content=content, library="pyexcel-ods"
16 )
17 result = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 1.1, 1]
1618 actual = list(r.enumerate())
1719 eq_(result, actual)
1820 if os.path.exists(testfile):
1921 os.unlink(testfile)
2022
2123 def test_ods_output_stringio(self):
22 data = [
23 [1, 2, 3],
24 [4, 5, 6]
25 ]
26 io = pyexcel.save_as(dest_file_type="ods",
27 array=data)
28 r = pyexcel.get_sheet(file_type="ods", file_content=io.getvalue(),
29 library="pyexcel-ods")
24 data = [[1, 2, 3], [4, 5, 6]]
25 io = pyexcel.save_as(dest_file_type="ods", array=data)
26 r = pyexcel.get_sheet(
27 file_type="ods", file_content=io.getvalue(), library="pyexcel-ods"
28 )
3029 result = [1, 2, 3, 4, 5, 6]
3130 actual = list(r.enumerate())
3231 eq_(result, actual)
00 import os
1
2 from base import PyexcelHatWriterBase, PyexcelWriterBase
3 from pyexcel_ods.odsr import ODSBook as Reader
14 from pyexcel_ods.odsw import ODSWriter as Writer
2 from pyexcel_ods.odsr import ODSBook as Reader
3 from base import PyexcelWriterBase, PyexcelHatWriterBase
45
56
67 class TestNativeODSWriter:
89 self.content = {
910 "Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]],
1011 "Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]],
11 "Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
12 "Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]],
1213 }
1314 self.testfile = "writer.ods"
1415 writer = Writer()