Skip to content

Commit 9862d28

Browse files
authored
Merge pull request #45 from pyrox0/dev
nose -> pytest
2 parents 661d4f0 + ca3548c commit 9862d28

17 files changed

+118
-126
lines changed

.github/workflows/tests.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
python-version: [3.6, 3.7, 3.8, 3.9]
11-
os: [macOs-latest, ubuntu-latest, windows-latest]
10+
python-version: [3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12]
11+
os: [macos-latest, ubuntu-latest, windows-latest]
1212

1313
runs-on: ${{ matrix.os }}
1414
name: run tests
@@ -25,8 +25,8 @@ jobs:
2525
- name: test
2626
run: |
2727
pip freeze
28-
nosetests --verbosity=3 --with-coverage --cover-package pyexcel_ods --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_ods
28+
pytest
2929
- name: Upload coverage
3030
uses: codecov/codecov-action@v1
3131
with:
32-
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
32+
name: ${{ matrix.os }} Python ${{ matrix.python-version }}

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ and update CHANGELOG.rst.
353353
How to test your contribution
354354
------------------------------
355355

356-
Although `nose` and `doctest` are both used in code testing, it is adviable that unit tests are put in tests. `doctest` is incorporated only to make sure the code examples in documentation remain valid across different development releases.
356+
Although `pytest` and `doctest` are both used in code testing, it is adviable that unit tests are put in tests. `doctest` is incorporated only to make sure the code examples in documentation remain valid across different development releases.
357357

358358
On Linux/Unix systems, please launch your tests like this::
359359

pyexcel_ods/odsr.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:copyright: (c) 2014-2020 by Onni Software Ltd.
88
:license: New BSD License, see LICENSE for more details
99
"""
10+
1011
# Copyright 2011 Marco Conti
1112

1213
# Licensed under the Apache License, Version 2.0 (the "License");

pyexcel_ods/odsw.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:copyright: (c) 2014-2020 by Onni Software Ltd.
88
:license: New BSD License, see LICENSE for more details
99
"""
10+
1011
import pyexcel_io.service as converter
1112
from odf.text import P
1213
from odf.table import Table, TableRow, TableCell

pytest.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts = --cov=pyexcel_ods --doctest-glob="*.rst" tests/ README.rst docs/source pyexcel_ods

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def filter_out_test_code(file_handle):
193193
keywords=KEYWORDS,
194194
python_requires=PYTHON_REQUIRES,
195195
extras_require=EXTRAS_REQUIRE,
196-
tests_require=["nose"],
196+
tests_require=["pytest", "pytest-cov"],
197197
install_requires=INSTALL_REQUIRES,
198198
packages=PACKAGES,
199199
include_package_data=True,

test.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pip freeze
2-
nosetests --with-coverage --cover-package pyexcel_ods --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_ods
2+
pytest

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#/bin/bash
22
pip freeze
3-
nosetests --with-coverage --cover-package pyexcel_ods --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_ods
3+
pytest

tests/base.py

+32-34
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import os # noqa
22
import datetime # noqa
33

4+
import pytest
45
import pyexcel
56

6-
from nose.tools import eq_, raises # noqa
7-
87

98
def create_sample_file1(file):
109
data = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 1.1, 1]
@@ -29,7 +28,7 @@ class PyexcelHatWriterBase:
2928
def test_series_table(self):
3029
pyexcel.save_as(adict=self.content, dest_file_name=self.testfile)
3130
r = pyexcel.get_sheet(file_name=self.testfile, name_columns_by_row=0)
32-
eq_(r.dict, self.content)
31+
assert r.dict == self.content
3332

3433

3534
class PyexcelWriterBase:
@@ -83,7 +82,7 @@ def test_reading_through_sheets(self):
8382
expected = [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]
8483
assert data == expected
8584
data = list(b["Sheet3"].rows())
86-
expected = [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
85+
expected = [["X", "Y", "Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
8786
assert data == expected
8887
sheet3 = b["Sheet3"]
8988
sheet3.name_columns_by_row(0)
@@ -96,46 +95,45 @@ class ODSCellTypes:
9695
def test_formats(self):
9796
# date formats
9897
date_format = "%d/%m/%Y"
99-
eq_(self.data["Sheet1"][0][0], "Date")
100-
eq_(self.data["Sheet1"][1][0].strftime(date_format), "11/11/2014")
101-
eq_(self.data["Sheet1"][2][0].strftime(date_format), "01/01/2001")
102-
eq_(self.data["Sheet1"][3][0], "")
98+
assert self.data["Sheet1"][0][0] == "Date"
99+
assert self.data["Sheet1"][1][0].strftime(date_format) == "11/11/2014"
100+
assert self.data["Sheet1"][2][0].strftime(date_format) == "01/01/2001"
101+
assert self.data["Sheet1"][3][0] == ""
103102
# time formats
104103
time_format = "%S:%M:%H"
105-
eq_(self.data["Sheet1"][0][1], "Time")
106-
eq_(self.data["Sheet1"][1][1].strftime(time_format), "12:12:11")
107-
eq_(self.data["Sheet1"][2][1].strftime(time_format), "12:00:00")
108-
eq_(self.data["Sheet1"][3][1], 0)
109-
eq_(
110-
self.data["Sheet1"][4][1],
111-
datetime.timedelta(hours=27, minutes=17, seconds=54),
104+
assert self.data["Sheet1"][0][1] == "Time"
105+
assert self.data["Sheet1"][1][1].strftime(time_format) == "12:12:11"
106+
assert self.data["Sheet1"][2][1].strftime(time_format) == "12:00:00"
107+
assert self.data["Sheet1"][3][1] == 0
108+
assert self.data["Sheet1"][4][1] == datetime.timedelta(
109+
hours=27, minutes=17, seconds=54
112110
)
113-
eq_(self.data["Sheet1"][5][1], "Other")
111+
assert self.data["Sheet1"][5][1] == "Other"
114112
# boolean
115-
eq_(self.data["Sheet1"][0][2], "Boolean")
116-
eq_(self.data["Sheet1"][1][2], True)
117-
eq_(self.data["Sheet1"][2][2], False)
113+
assert self.data["Sheet1"][0][2] == "Boolean"
114+
assert self.data["Sheet1"][1][2] == True
115+
assert self.data["Sheet1"][2][2] == False
118116
# Float
119-
eq_(self.data["Sheet1"][0][3], "Float")
120-
eq_(self.data["Sheet1"][1][3], 11.11)
117+
assert self.data["Sheet1"][0][3] == "Float"
118+
assert self.data["Sheet1"][1][3] == 11.11
121119
# Currency
122-
eq_(self.data["Sheet1"][0][4], "Currency")
123-
eq_(self.data["Sheet1"][1][4], "1 GBP")
124-
eq_(self.data["Sheet1"][2][4], "-10000 GBP")
120+
assert self.data["Sheet1"][0][4] == "Currency"
121+
assert self.data["Sheet1"][1][4] == "1 GBP"
122+
assert self.data["Sheet1"][2][4] == "-10000 GBP"
125123
# Percentage
126-
eq_(self.data["Sheet1"][0][5], "Percentage")
127-
eq_(self.data["Sheet1"][1][5], 2)
124+
assert self.data["Sheet1"][0][5] == "Percentage"
125+
assert self.data["Sheet1"][1][5] == 2
128126
# int
129-
eq_(self.data["Sheet1"][0][6], "Int")
130-
eq_(self.data["Sheet1"][1][6], 3)
131-
eq_(self.data["Sheet1"][4][6], 11)
127+
assert self.data["Sheet1"][0][6] == "Int"
128+
assert self.data["Sheet1"][1][6] == 3
129+
assert self.data["Sheet1"][4][6] == 11
132130
# Scientifed not supported
133-
eq_(self.data["Sheet1"][1][7], 100000)
131+
assert self.data["Sheet1"][1][7] == 100000
134132
# Fraction
135-
eq_(self.data["Sheet1"][1][8], 1.25)
133+
assert self.data["Sheet1"][1][8] == 1.25
136134
# Text
137-
eq_(self.data["Sheet1"][1][9], "abc")
135+
assert self.data["Sheet1"][1][9] == "abc"
138136

139-
@raises(IndexError)
140137
def test_no_excessive_trailing_columns(self):
141-
eq_(self.data["Sheet1"][2][6], "")
138+
with pytest.raises(IndexError):
139+
assert self.data["Sheet1"][2][6] == ""

tests/requirements.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
nose
2-
mock;python_version<"3"
1+
pytest
2+
pytest-cov
33
codecov
4-
coverage
54
flake8
65
black
76
isort

tests/test_bug_fixes.py

+34-36
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,81 @@
33
import os
44

55
import psutil
6+
import pytest
67
import pyexcel as pe
78
from pyexcel_ods import get_data, save_data
89
from pyexcel_io.exceptions import IntegerAccuracyLossError
910

10-
from nose import SkipTest
11-
from nose.tools import eq_, raises
12-
1311
IN_TRAVIS = "TRAVIS" in os.environ
1412

1513

1614
def test_bug_fix_for_issue_1():
1715
data = get_data(get_fixtures("repeated.ods"))
18-
eq_(data["Sheet1"], [["repeated", "repeated", "repeated", "repeated"]])
16+
assert data["Sheet1"] == [["repeated", "repeated", "repeated", "repeated"]]
1917

2018

2119
def test_bug_fix_for_issue_2():
2220
data = {}
2321
data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
24-
data.update({"Sheet 2": [[u"row 1", u"Héllô!", u"HolÁ!"]]})
22+
data.update({"Sheet 2": [["row 1", "Héllô!", "HolÁ!"]]})
2523
save_data("your_file.ods", data)
2624
new_data = get_data("your_file.ods")
27-
assert new_data["Sheet 2"] == [[u"row 1", u"H\xe9ll\xf4!", u"Hol\xc1!"]]
25+
assert new_data["Sheet 2"] == [["row 1", "H\xe9ll\xf4!", "Hol\xc1!"]]
2826

2927

30-
@raises(Exception)
3128
def test_invalid_date():
32-
from pyexcel_ods.ods import date_value
33-
34-
value = "2015-08-"
35-
date_value(value)
29+
with pytest.raises(Exception):
30+
from pyexcel_ods.ods import date_value
3631

32+
value = "2015-08-"
33+
date_value(value)
3734

38-
@raises(Exception)
39-
def test_fake_date_time_10():
40-
from pyexcel_ods.ods import date_value
35+
with pytest.raises(Exception):
36+
from pyexcel_ods.ods import date_value
4137

42-
date_value("1234567890")
38+
date_value("1234567890")
4339

4440

45-
@raises(Exception)
4641
def test_fake_date_time_19():
47-
from pyexcel_ods.ods import date_value
42+
with pytest.raises(Exception):
43+
from pyexcel_ods.ods import date_value
4844

49-
date_value("1234567890123456789")
45+
date_value("1234567890123456789")
5046

5147

52-
@raises(Exception)
5348
def test_fake_date_time_20():
54-
from pyexcel_ods.ods import date_value
49+
with pytest.raises(Exception):
50+
from pyexcel_ods.ods import date_value
5551

56-
date_value("12345678901234567890")
52+
date_value("12345678901234567890")
5753

5854

5955
def test_issue_13():
6056
test_file = "test_issue_13.ods"
6157
data = [[1, 2], [], [], [], [3, 4]]
6258
save_data(test_file, {test_file: data})
6359
written_data = get_data(test_file, skip_empty_rows=False)
64-
eq_(data, written_data[test_file])
60+
assert data == written_data[test_file]
6561
os.unlink(test_file)
6662

6763

6864
def test_issue_14():
6965
# pyexcel issue 61
7066
test_file = "issue_61.ods"
7167
data = get_data(get_fixtures(test_file), skip_empty_rows=True)
72-
eq_(data["S-LMC"], [[u"aaa"], [0]])
68+
assert data["S-LMC"] == [["aaa"], [0]]
7369

7470

7571
def test_issue_6():
7672
test_file = "12_day_as_time.ods"
7773
data = get_data(get_fixtures(test_file), skip_empty_rows=True)
78-
eq_(data["Sheet1"][0][0].days, 12)
74+
assert data["Sheet1"][0][0].days == 12
7975

8076

8177
def test_issue_19():
8278
test_file = "pyexcel_81_ods_19.ods"
8379
data = get_data(get_fixtures(test_file), skip_empty_rows=True)
84-
eq_(data["product.template"][1][1], "PRODUCT NAME PMP")
80+
assert data["product.template"][1][1] == "PRODUCT NAME PMP"
8581

8682

8783
def test_issue_83_ods_file_handle():
@@ -110,18 +106,20 @@ def test_issue_83_ods_file_handle():
110106
pe.free_resources()
111107
open_files_l4 = proc.open_files()
112108
# this confirms that no more open file handle
113-
eq_(open_files_l1, open_files_l4)
109+
assert open_files_l1 == open_files_l4
114110

115111

116112
def test_pr_22():
117113
test_file = get_fixtures("white_space.ods")
118114
data = get_data(test_file)
119-
eq_(data["Sheet1"][0][0], "paragraph with tab(\t), space, \nnew line")
115+
assert (
116+
data["Sheet1"][0][0] == "paragraph with tab(\t), space, \nnew line"
117+
)
120118

121119

122120
def test_issue_23():
123121
if not IN_TRAVIS:
124-
raise SkipTest()
122+
pytest.skip("Need to be in Travis CI to run this test.")
125123
pe.get_book(
126124
url=(
127125
"https://github.com/pyexcel/pyexcel-ods/"
@@ -133,13 +131,13 @@ def test_issue_23():
133131
def test_issue_24():
134132
test_file = get_fixtures("comment-in-cell.ods")
135133
data = get_data(test_file)
136-
eq_(data["Sheet1"], [["test"]])
134+
assert data["Sheet1"] == [["test"]]
137135

138136

139137
def test_issue_27():
140138
test_file = get_fixtures("issue_27.ods")
141139
data = get_data(test_file, skip_empty_rows=True)
142-
eq_(data["VGPMX"], [["", "Cost Basis", "0"]])
140+
assert data["VGPMX"] == [["", "Cost Basis", "0"]]
143141

144142

145143
def test_issue_30():
@@ -148,16 +146,16 @@ def test_issue_30():
148146
sheet[0, 0] = 999999999999999
149147
sheet.save_as(test_file)
150148
sheet2 = pe.get_sheet(file_name=test_file)
151-
eq_(sheet[0, 0], sheet2[0, 0])
149+
assert sheet[0, 0] == sheet2[0, 0]
152150
os.unlink(test_file)
153151

154152

155-
@raises(IntegerAccuracyLossError)
156153
def test_issue_30_precision_loss():
157-
test_file = "issue_30_2.ods"
158-
sheet = pe.Sheet()
159-
sheet[0, 0] = 9999999999999999
160-
sheet.save_as(test_file)
154+
with pytest.raises(IntegerAccuracyLossError):
155+
test_file = "issue_30_2.ods"
156+
sheet = pe.Sheet()
157+
sheet[0, 0] = 9999999999999999
158+
sheet.save_as(test_file)
161159

162160

163161
def get_fixtures(filename):

0 commit comments

Comments
 (0)