Skip to content

Commit 00a660c

Browse files
authored
Merge pull request #54 from pyrox0/dev
nose -> pytest
2 parents d8953c8 + 9f0d480 commit 00a660c

20 files changed

+76
-90
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
python-version: [3.7, 3.8, 3.9]
11-
os: [macOs-latest, ubuntu-latest, windows-latest]
10+
python-version: [3.7, 3.8, 3.9, 3.10, 3.11, 3.12]
11+
os: [macos-latest, ubuntu-latest, windows-latest]
1212
exclude:
13-
- os: macOs-latest
13+
- os: macos-latest
1414
python-version: 3.7
1515

1616
runs-on: ${{ matrix.os }}
@@ -28,8 +28,8 @@ jobs:
2828
- name: test
2929
run: |
3030
pip freeze
31-
nosetests --verbosity=3 --with-coverage --cover-package pyexcel_xls --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_xls
31+
pytest
3232
- name: Upload coverage
3333
uses: codecov/codecov-action@v1
3434
with:
35-
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
35+
name: ${{ matrix.os }} Python ${{ matrix.python-version }}

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ and update changelog.yml
380380
How to test your contribution
381381
------------------------------
382382

383-
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.
383+
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.
384384

385385
On Linux/Unix systems, please launch your tests like this::
386386

pyexcel_xls/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:copyright: (c) 2016-2021 by Onni Software Ltd
88
:license: New BSD License
99
"""
10+
1011
import xlrd
1112

1213
# flake8: noqa

pyexcel_xls/xlsr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:copyright: (c) 2016-2021 by Onni Software Ltd
88
:license: New BSD License
99
"""
10+
1011
import datetime
1112

1213
import xlrd

pyexcel_xls/xlsw.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:copyright: (c) 2016-2021 by Onni Software Ltd
88
:license: New BSD License
99
"""
10+
1011
import datetime
1112

1213
import xlrd

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts = --cov=pyexcel_xls --doctest-glob="*.rst" tests/ README.rst docs/source pyexcel_xls

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def filter_out_test_code(file_handle):
202202
keywords=KEYWORDS,
203203
python_requires=PYTHON_REQUIRES,
204204
extras_require=EXTRAS_REQUIRE,
205-
tests_require=["nose"],
205+
tests_require=["pytest", "pytest-cov"],
206206
install_requires=INSTALL_REQUIRES,
207207
packages=PACKAGES,
208208
include_package_data=True,

test.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pip freeze
2-
nosetests --with-coverage --cover-package pyexcel_xls --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_xls
2+
pytest

test.sh

Lines changed: 1 addition & 1 deletion
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_xls --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_xls
3+
pytest

tests/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
import pyexcel
55

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

97
def create_sample_file1(file):
108
data = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 1.1, 1]
@@ -29,7 +27,7 @@ class PyexcelHatWriterBase:
2927
def test_series_table(self):
3028
pyexcel.save_as(adict=self.content, dest_file_name=self.testfile)
3129
r = pyexcel.get_sheet(file_name=self.testfile, name_columns_by_row=0)
32-
eq_(r.dict, self.content)
30+
assert r.dict == self.content
3331

3432

3533
class PyexcelWriterBase:
@@ -83,7 +81,7 @@ def test_reading_through_sheets(self):
8381
expected = [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]
8482
assert data == expected
8583
data = list(b["Sheet3"].rows())
86-
expected = [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
84+
expected = [["X", "Y", "Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
8785
assert data == expected
8886
sheet3 = b["Sheet3"]
8987
sheet3.name_columns_by_row(0)

tests/requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
nose
1+
pytest
2+
pytest-cov
23
mock;python_version<"3"
3-
codecov
4-
coverage
54
flake8
65
black
76
isort

tests/requirements3.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
lxml
22
pyexcel-ods3
3-
nose
4-
rednose
5-
nose-cov
6-
codecov
7-
coverage
3+
pytest
4+
pytest-cov

tests/test_bug_fixes.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
import datetime
99
from unittest.mock import MagicMock, patch
1010

11+
import pytest
1112
import pyexcel as pe
1213
from _compact import OrderedDict
1314
from pyexcel_xls import XLRD_VERSION_2_OR_ABOVE, save_data
1415
from pyexcel_xls.xlsr import xldate_to_python_date
1516
from pyexcel_xls.xlsw import XLSWriter as Writer
1617

17-
from nose import SkipTest
18-
from nose.tools import eq_, raises
19-
2018
IN_TRAVIS = "TRAVIS" in os.environ
2119

2220

@@ -43,15 +41,15 @@ def test_issue_9_hidden_sheet():
4341
test_file = get_fixture("hidden_sheets.xls")
4442
book_dict = pe.get_book_dict(file_name=test_file)
4543
assert "hidden" not in book_dict
46-
eq_(book_dict["shown"], [["A", "B"]])
44+
assert book_dict["shown"] == [["A", "B"]]
4745

4846

4947
def test_issue_9_hidden_sheet_2():
5048
test_file = get_fixture("hidden_sheets.xls")
5149
book_dict = pe.get_book_dict(file_name=test_file, skip_hidden_sheets=False)
5250
assert "hidden" in book_dict
53-
eq_(book_dict["shown"], [["A", "B"]])
54-
eq_(book_dict["hidden"], [["a", "b"]])
51+
assert book_dict["shown"] == [["A", "B"]]
52+
assert book_dict["hidden"] == [["a", "b"]]
5553

5654

5755
def test_issue_10_generator_as_content():
@@ -66,9 +64,9 @@ def custom_row_renderer(row):
6664
save_data("test.xls", {"sheet": data_gen()})
6765

6866

69-
@raises(IOError)
7067
def test_issue_13_empty_file_content():
71-
pe.get_sheet(file_content="", file_type="xls")
68+
with pytest.raises(IOError):
69+
pe.get_sheet(file_content="", file_type="xls")
7270

7371

7472
def test_issue_16_file_stream_has_no_getvalue():
@@ -90,36 +88,36 @@ def test_issue_18_encoding_override_isnt_passed(fake_open):
9088

9189
def test_issue_20():
9290
if not IN_TRAVIS:
93-
raise SkipTest()
91+
pytest.skip("Must be in CI for this test")
9492
pe.get_book(
9593
url="https://github.com/pyexcel/pyexcel-xls/raw/master/tests/fixtures/file_with_an_empty_sheet.xls" # noqa: E501
9694
)
9795

9896

9997
def test_issue_151():
10098
if XLRD_VERSION_2_OR_ABOVE:
101-
raise SkipTest()
99+
pytest.skip("XLRD<2 required for this test")
102100
s = pe.get_sheet(
103101
file_name=get_fixture("pyexcel_issue_151.xlsx"),
104102
skip_hidden_row_and_column=False,
105103
library="pyexcel-xls",
106104
)
107-
eq_("#N/A", s[0, 0])
105+
assert "#N/A" == s[0, 0]
108106

109107

110-
@raises(NotImplementedError)
111108
def test_empty_book_pyexcel_issue_120():
112109
"""
113110
https://github.com/pyexcel/pyexcel/issues/120
114111
"""
115-
writer = Writer("fake.xls", "xls")
116-
writer.write({})
112+
with pytest.raises(NotImplementedError):
113+
writer = Writer("fake.xls", "xls")
114+
writer.write({})
117115

118116

119117
def test_pyexcel_issue_54():
120118
xlvalue = 41071.0
121119
date = xldate_to_python_date(xlvalue, 1)
122-
eq_(date, datetime.date(2016, 6, 12))
120+
assert date == datetime.date(2016, 6, 12)
123121

124122

125123
def get_fixture(file_name):

tests/test_filter.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
from pyexcel_io import get_data, save_data
44

5-
from nose.tools import eq_
6-
75

86
class TestFilter:
9-
def setUp(self):
7+
def setup_method(self):
108
self.test_file = "test_filter.xls"
119
sample = [
1210
[1, 21, 31],
@@ -24,21 +22,21 @@ def test_filter_row(self):
2422
self.test_file, start_row=3, library="pyexcel-xls"
2523
)
2624
expected = [[4, 24, 34], [5, 25, 35], [6, 26, 36]]
27-
eq_(filtered_data[self.sheet_name], expected)
25+
assert filtered_data[self.sheet_name] == expected
2826

2927
def test_filter_row_2(self):
3028
filtered_data = get_data(
3129
self.test_file, start_row=3, row_limit=1, library="pyexcel-xls"
3230
)
3331
expected = [[4, 24, 34]]
34-
eq_(filtered_data[self.sheet_name], expected)
32+
assert filtered_data[self.sheet_name] == expected
3533

3634
def test_filter_column(self):
3735
filtered_data = get_data(
3836
self.test_file, start_column=1, library="pyexcel-xls"
3937
)
4038
expected = [[21, 31], [22, 32], [23, 33], [24, 34], [25, 35], [26, 36]]
41-
eq_(filtered_data[self.sheet_name], expected)
39+
assert filtered_data[self.sheet_name] == expected
4240

4341
def test_filter_column_2(self):
4442
filtered_data = get_data(
@@ -48,14 +46,14 @@ def test_filter_column_2(self):
4846
library="pyexcel-xls",
4947
)
5048
expected = [[21], [22], [23], [24], [25], [26]]
51-
eq_(filtered_data[self.sheet_name], expected)
49+
assert filtered_data[self.sheet_name] == expected
5250

5351
def test_filter_both_ways(self):
5452
filtered_data = get_data(
5553
self.test_file, start_column=1, start_row=3, library="pyexcel-xls"
5654
)
5755
expected = [[24, 34], [25, 35], [26, 36]]
58-
eq_(filtered_data[self.sheet_name], expected)
56+
assert filtered_data[self.sheet_name] == expected
5957

6058
def test_filter_both_ways_2(self):
6159
filtered_data = get_data(
@@ -67,7 +65,7 @@ def test_filter_both_ways_2(self):
6765
library="pyexcel-xls",
6866
)
6967
expected = [[24]]
70-
eq_(filtered_data[self.sheet_name], expected)
68+
assert filtered_data[self.sheet_name] == expected
7169

72-
def tearDown(self):
70+
def teardown_method(self):
7371
os.unlink(self.test_file)

tests/test_formatters.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
import pyexcel as pe
55

6-
from nose.tools import eq_
7-
86

97
class TestDateFormat:
108
def test_reading_date_format(self):
@@ -22,7 +20,7 @@ def test_reading_date_format(self):
2220
library="pyexcel-xls",
2321
)
2422
assert isinstance(r[1, 0], datetime.date)
25-
eq_(r[1, 0].strftime("%d/%m/%y"), "25/12/14")
23+
assert r[1, 0].strftime("%d/%m/%y") == "25/12/14"
2624
assert isinstance(r[1, 1], datetime.time) is True
2725
assert r[1, 1].strftime("%H:%M:%S") == "11:11:11"
2826
assert r[4, 0].strftime("%d/%m/%Y") == "01/01/1900"
@@ -62,7 +60,7 @@ def test_writing_date_format(self):
6260

6361

6462
class TestAutoDetectInt:
65-
def setUp(self):
63+
def setup_method(self):
6664
self.content = [[1, 2, 3.1]]
6765
self.test_file = "test_auto_detect_init.xls"
6866
pe.save_as(array=self.content, dest_file_name=self.test_file)
@@ -76,7 +74,7 @@ def test_auto_detect_int(self):
7674
| 1 | 2 | 3.1 |
7775
+---+---+-----+"""
7876
).strip()
79-
eq_(str(sheet), expected)
77+
assert str(sheet) == expected
8078

8179
def test_get_book_auto_detect_int(self):
8280
book = pe.get_book(file_name=self.test_file, library="pyexcel-xls")
@@ -87,7 +85,7 @@ def test_get_book_auto_detect_int(self):
8785
| 1 | 2 | 3.1 |
8886
+---+---+-----+"""
8987
).strip()
90-
eq_(str(book), expected)
88+
assert str(book) == expected
9189

9290
def test_auto_detect_int_false(self):
9391
sheet = pe.get_sheet(
@@ -102,7 +100,7 @@ def test_auto_detect_int_false(self):
102100
| 1.0 | 2.0 | 3.1 |
103101
+-----+-----+-----+"""
104102
).strip()
105-
eq_(str(sheet), expected)
103+
assert str(sheet) == expected
106104

107105
def test_get_book_auto_detect_int_false(self):
108106
book = pe.get_book(
@@ -117,7 +115,7 @@ def test_get_book_auto_detect_int_false(self):
117115
| 1.0 | 2.0 | 3.1 |
118116
+-----+-----+-----+"""
119117
).strip()
120-
eq_(str(book), expected)
118+
assert str(book) == expected
121119

122-
def tearDown(self):
120+
def teardown_method(self):
123121
os.unlink(self.test_file)

tests/test_hidden.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
from pyexcel_xls import get_data
44

5-
from nose.tools import eq_
6-
75

86
def test_simple_hidden_sheets():
97
data = get_data(
108
os.path.join("tests", "fixtures", "hidden.xls"),
119
skip_hidden_row_and_column=True,
1210
)
1311
expected = [[1, 3], [7, 9]]
14-
eq_(data["Sheet1"], expected)
12+
assert data["Sheet1"] == expected
1513

1614

1715
def test_complex_hidden_sheets():
@@ -20,4 +18,4 @@ def test_complex_hidden_sheets():
2018
skip_hidden_row_and_column=True,
2119
)
2220
expected = [[1, 3, 5, 7, 9], [31, 33, 35, 37, 39], [61, 63, 65, 67]]
23-
eq_(data["Sheet1"], expected)
21+
assert data["Sheet1"] == expected

0 commit comments

Comments
 (0)