2015-08-19 23:45:23 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- encoding: utf-8 -*-
|
2015-05-28 10:28:23 +02:00
|
|
|
import os
|
2018-11-26 08:56:21 +01:00
|
|
|
|
2020-10-03 11:22:16 +02:00
|
|
|
import psutil
|
2017-06-01 00:39:12 +02:00
|
|
|
import pyexcel as pe
|
2019-11-10 17:30:00 +01:00
|
|
|
from pyexcel_ods import get_data, save_data
|
2020-10-03 11:22:16 +02:00
|
|
|
from pyexcel_io.exceptions import IntegerAccuracyLossError
|
2019-11-10 17:30:00 +01:00
|
|
|
|
2019-03-19 09:37:19 +01:00
|
|
|
from nose import SkipTest
|
|
|
|
from nose.tools import eq_, raises
|
|
|
|
|
2018-11-26 08:56:21 +01:00
|
|
|
IN_TRAVIS = "TRAVIS" in os.environ
|
2015-05-28 10:28:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_bug_fix_for_issue_1():
|
2017-06-01 00:39:12 +02:00
|
|
|
data = get_data(get_fixtures("repeated.ods"))
|
2018-11-26 08:56:21 +01:00
|
|
|
eq_(data["Sheet1"], [["repeated", "repeated", "repeated", "repeated"]])
|
2016-05-23 10:00:23 +02:00
|
|
|
|
|
|
|
|
2015-08-19 23:45:23 +02:00
|
|
|
def test_bug_fix_for_issue_2():
|
|
|
|
data = {}
|
|
|
|
data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
|
|
|
|
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")
|
2018-11-26 08:56:21 +01:00
|
|
|
assert new_data["Sheet 2"] == [[u"row 1", u"H\xe9ll\xf4!", u"Hol\xc1!"]]
|
2015-09-09 00:29:01 +02:00
|
|
|
|
2016-05-23 10:00:23 +02:00
|
|
|
|
2015-09-14 22:02:31 +02:00
|
|
|
@raises(Exception)
|
|
|
|
def test_invalid_date():
|
2016-05-23 10:00:23 +02:00
|
|
|
from pyexcel_ods.ods import date_value
|
2018-11-26 08:56:21 +01:00
|
|
|
|
2015-09-14 22:02:31 +02:00
|
|
|
value = "2015-08-"
|
2015-09-23 21:27:24 +02:00
|
|
|
date_value(value)
|
|
|
|
|
2016-05-23 10:00:23 +02:00
|
|
|
|
2015-09-23 21:27:24 +02:00
|
|
|
@raises(Exception)
|
|
|
|
def test_fake_date_time_10():
|
2016-05-23 10:00:23 +02:00
|
|
|
from pyexcel_ods.ods import date_value
|
2018-11-26 08:56:21 +01:00
|
|
|
|
2015-09-23 21:27:24 +02:00
|
|
|
date_value("1234567890")
|
|
|
|
|
2016-05-23 10:00:23 +02:00
|
|
|
|
2015-09-23 21:27:24 +02:00
|
|
|
@raises(Exception)
|
|
|
|
def test_fake_date_time_19():
|
2016-05-23 10:00:23 +02:00
|
|
|
from pyexcel_ods.ods import date_value
|
2018-11-26 08:56:21 +01:00
|
|
|
|
2015-09-23 21:27:24 +02:00
|
|
|
date_value("1234567890123456789")
|
|
|
|
|
2016-05-23 10:00:23 +02:00
|
|
|
|
2015-09-23 21:27:24 +02:00
|
|
|
@raises(Exception)
|
|
|
|
def test_fake_date_time_20():
|
2016-05-23 10:00:23 +02:00
|
|
|
from pyexcel_ods.ods import date_value
|
2018-11-26 08:56:21 +01:00
|
|
|
|
2015-09-23 21:27:24 +02:00
|
|
|
date_value("12345678901234567890")
|
2016-06-02 10:11:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_issue_13():
|
|
|
|
test_file = "test_issue_13.ods"
|
2018-11-26 08:56:21 +01:00
|
|
|
data = [[1, 2], [], [], [], [3, 4]]
|
2016-08-25 18:54:20 +02:00
|
|
|
save_data(test_file, {test_file: data})
|
|
|
|
written_data = get_data(test_file, skip_empty_rows=False)
|
2016-06-02 10:11:32 +02:00
|
|
|
eq_(data, written_data[test_file])
|
2016-06-09 00:43:46 +02:00
|
|
|
os.unlink(test_file)
|
2016-10-18 01:41:01 +02:00
|
|
|
|
|
|
|
|
2016-10-18 01:47:03 +02:00
|
|
|
def test_issue_14():
|
|
|
|
# pyexcel issue 61
|
2016-10-18 01:41:01 +02:00
|
|
|
test_file = "issue_61.ods"
|
2018-11-26 08:56:21 +01:00
|
|
|
data = get_data(get_fixtures(test_file), skip_empty_rows=True)
|
|
|
|
eq_(data["S-LMC"], [[u"aaa"], [0]])
|
2017-04-07 09:21:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_issue_6():
|
|
|
|
test_file = "12_day_as_time.ods"
|
2018-11-26 08:56:21 +01:00
|
|
|
data = get_data(get_fixtures(test_file), skip_empty_rows=True)
|
|
|
|
eq_(data["Sheet1"][0][0].days, 12)
|
2017-05-03 13:45:21 +02:00
|
|
|
|
2017-05-03 23:26:07 +02:00
|
|
|
|
2017-05-03 13:45:21 +02:00
|
|
|
def test_issue_19():
|
|
|
|
test_file = "pyexcel_81_ods_19.ods"
|
2018-11-26 08:56:21 +01:00
|
|
|
data = get_data(get_fixtures(test_file), skip_empty_rows=True)
|
|
|
|
eq_(data["product.template"][1][1], "PRODUCT NAME PMP")
|
2017-06-01 00:39:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_issue_83_ods_file_handle():
|
|
|
|
# this proves that odfpy
|
|
|
|
# does not leave a file handle open at all
|
|
|
|
proc = psutil.Process()
|
|
|
|
test_file = get_fixtures("issue_61.ods")
|
|
|
|
open_files_l1 = proc.open_files()
|
|
|
|
|
|
|
|
# start with a csv file
|
2018-11-26 08:56:21 +01:00
|
|
|
data = pe.iget_array(file_name=test_file, library="pyexcel-ods")
|
2017-06-01 00:39:12 +02:00
|
|
|
open_files_l2 = proc.open_files()
|
|
|
|
delta = len(open_files_l2) - len(open_files_l1)
|
|
|
|
# cannot catch open file handle
|
|
|
|
assert delta == 0
|
|
|
|
|
|
|
|
# now the file handle get opened when we run through
|
|
|
|
# the generator
|
|
|
|
list(data)
|
|
|
|
open_files_l3 = proc.open_files()
|
|
|
|
delta = len(open_files_l3) - len(open_files_l1)
|
|
|
|
# cannot catch open file handle
|
|
|
|
assert delta == 0
|
|
|
|
|
|
|
|
# free the fish
|
2017-06-15 00:27:31 +02:00
|
|
|
pe.free_resources()
|
2017-06-01 00:39:12 +02:00
|
|
|
open_files_l4 = proc.open_files()
|
|
|
|
# this confirms that no more open file handle
|
|
|
|
eq_(open_files_l1, open_files_l4)
|
|
|
|
|
|
|
|
|
2017-08-23 19:16:37 +02:00
|
|
|
def test_pr_22():
|
|
|
|
test_file = get_fixtures("white_space.ods")
|
|
|
|
data = get_data(test_file)
|
2018-11-26 08:56:21 +01:00
|
|
|
eq_(data["Sheet1"][0][0], "paragraph with tab(\t), space, \nnew line")
|
2017-08-23 19:16:37 +02:00
|
|
|
|
|
|
|
|
2017-08-24 00:33:13 +02:00
|
|
|
def test_issue_23():
|
2017-08-24 19:48:49 +02:00
|
|
|
if not IN_TRAVIS:
|
|
|
|
raise SkipTest()
|
2018-11-26 08:56:21 +01:00
|
|
|
pe.get_book(
|
2018-11-26 09:10:27 +01:00
|
|
|
url=(
|
|
|
|
"https://github.com/pyexcel/pyexcel-ods/"
|
|
|
|
+ "raw/master/tests/fixtures/white_space.ods"
|
|
|
|
)
|
|
|
|
)
|
2017-08-24 00:24:05 +02:00
|
|
|
|
|
|
|
|
2018-05-23 09:15:54 +02:00
|
|
|
def test_issue_24():
|
2018-05-23 09:27:08 +02:00
|
|
|
test_file = get_fixtures("comment-in-cell.ods")
|
|
|
|
data = get_data(test_file)
|
2018-11-26 08:56:21 +01:00
|
|
|
eq_(data["Sheet1"], [["test"]])
|
2018-05-23 09:27:08 +02:00
|
|
|
|
|
|
|
|
2018-05-23 09:35:20 +02:00
|
|
|
def test_issue_27():
|
|
|
|
test_file = get_fixtures("issue_27.ods")
|
|
|
|
data = get_data(test_file, skip_empty_rows=True)
|
2018-11-26 08:56:21 +01:00
|
|
|
eq_(data["VGPMX"], [["", "Cost Basis", "0"]])
|
2018-05-23 09:15:54 +02:00
|
|
|
|
|
|
|
|
2018-11-26 08:50:08 +01:00
|
|
|
def test_issue_30():
|
|
|
|
test_file = "issue_30.ods"
|
|
|
|
sheet = pe.Sheet()
|
|
|
|
sheet[0, 0] = 999999999999999
|
|
|
|
sheet.save_as(test_file)
|
|
|
|
sheet2 = pe.get_sheet(file_name=test_file)
|
|
|
|
eq_(sheet[0, 0], sheet2[0, 0])
|
|
|
|
os.unlink(test_file)
|
|
|
|
|
|
|
|
|
|
|
|
@raises(IntegerAccuracyLossError)
|
|
|
|
def test_issue_30_precision_loss():
|
|
|
|
test_file = "issue_30_2.ods"
|
|
|
|
sheet = pe.Sheet()
|
|
|
|
sheet[0, 0] = 9999999999999999
|
|
|
|
sheet.save_as(test_file)
|
2017-08-24 00:24:05 +02:00
|
|
|
|
|
|
|
|
2017-06-01 00:39:12 +02:00
|
|
|
def get_fixtures(filename):
|
|
|
|
return os.path.join("tests", "fixtures", filename)
|