Skip to content

Commit

Permalink
Merge pull request #54 from pyrox0/dev
Browse files Browse the repository at this point in the history
nose -> pytest
  • Loading branch information
chfw authored Nov 12, 2024
2 parents d8953c8 + 9f0d480 commit 00a660c
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 90 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9]
os: [macOs-latest, ubuntu-latest, windows-latest]
python-version: [3.7, 3.8, 3.9, 3.10, 3.11, 3.12]
os: [macos-latest, ubuntu-latest, windows-latest]
exclude:
- os: macOs-latest
- os: macos-latest
python-version: 3.7

runs-on: ${{ matrix.os }}
Expand All @@ -28,8 +28,8 @@ jobs:
- name: test
run: |
pip freeze
nosetests --verbosity=3 --with-coverage --cover-package pyexcel_xls --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_xls
pytest
- name: Upload coverage
uses: codecov/codecov-action@v1
with:
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ and update changelog.yml
How to test your contribution
------------------------------

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.
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.

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

Expand Down
1 change: 1 addition & 0 deletions pyexcel_xls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:copyright: (c) 2016-2021 by Onni Software Ltd
:license: New BSD License
"""

import xlrd

# flake8: noqa
Expand Down
1 change: 1 addition & 0 deletions pyexcel_xls/xlsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:copyright: (c) 2016-2021 by Onni Software Ltd
:license: New BSD License
"""

import datetime

import xlrd
Expand Down
1 change: 1 addition & 0 deletions pyexcel_xls/xlsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:copyright: (c) 2016-2021 by Onni Software Ltd
:license: New BSD License
"""

import datetime

import xlrd
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --cov=pyexcel_xls --doctest-glob="*.rst" tests/ README.rst docs/source pyexcel_xls
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def filter_out_test_code(file_handle):
keywords=KEYWORDS,
python_requires=PYTHON_REQUIRES,
extras_require=EXTRAS_REQUIRE,
tests_require=["nose"],
tests_require=["pytest", "pytest-cov"],
install_requires=INSTALL_REQUIRES,
packages=PACKAGES,
include_package_data=True,
Expand Down
2 changes: 1 addition & 1 deletion test.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pip freeze
nosetests --with-coverage --cover-package pyexcel_xls --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_xls
pytest
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#/bin/bash
pip freeze
nosetests --with-coverage --cover-package pyexcel_xls --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst docs/source pyexcel_xls
pytest
6 changes: 2 additions & 4 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

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]
Expand All @@ -29,7 +27,7 @@ class PyexcelHatWriterBase:
def test_series_table(self):
pyexcel.save_as(adict=self.content, dest_file_name=self.testfile)
r = pyexcel.get_sheet(file_name=self.testfile, name_columns_by_row=0)
eq_(r.dict, self.content)
assert r.dict == self.content


class PyexcelWriterBase:
Expand Down Expand Up @@ -83,7 +81,7 @@ def test_reading_through_sheets(self):
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 = [["X", "Y", "Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
assert data == expected
sheet3 = b["Sheet3"]
sheet3.name_columns_by_row(0)
Expand Down
5 changes: 2 additions & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
nose
pytest
pytest-cov
mock;python_version<"3"
codecov
coverage
flake8
black
isort
Expand Down
7 changes: 2 additions & 5 deletions tests/requirements3.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
lxml
pyexcel-ods3
nose
rednose
nose-cov
codecov
coverage
pytest
pytest-cov
28 changes: 13 additions & 15 deletions tests/test_bug_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
import datetime
from unittest.mock import MagicMock, patch

import pytest
import pyexcel as pe
from _compact import OrderedDict
from pyexcel_xls import XLRD_VERSION_2_OR_ABOVE, save_data
from pyexcel_xls.xlsr import xldate_to_python_date
from pyexcel_xls.xlsw import XLSWriter as Writer

from nose import SkipTest
from nose.tools import eq_, raises

IN_TRAVIS = "TRAVIS" in os.environ


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


def test_issue_9_hidden_sheet_2():
test_file = get_fixture("hidden_sheets.xls")
book_dict = pe.get_book_dict(file_name=test_file, skip_hidden_sheets=False)
assert "hidden" in book_dict
eq_(book_dict["shown"], [["A", "B"]])
eq_(book_dict["hidden"], [["a", "b"]])
assert book_dict["shown"] == [["A", "B"]]
assert book_dict["hidden"] == [["a", "b"]]


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


@raises(IOError)
def test_issue_13_empty_file_content():
pe.get_sheet(file_content="", file_type="xls")
with pytest.raises(IOError):
pe.get_sheet(file_content="", file_type="xls")


def test_issue_16_file_stream_has_no_getvalue():
Expand All @@ -90,36 +88,36 @@ def test_issue_18_encoding_override_isnt_passed(fake_open):

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


def test_issue_151():
if XLRD_VERSION_2_OR_ABOVE:
raise SkipTest()
pytest.skip("XLRD<2 required for this test")
s = pe.get_sheet(
file_name=get_fixture("pyexcel_issue_151.xlsx"),
skip_hidden_row_and_column=False,
library="pyexcel-xls",
)
eq_("#N/A", s[0, 0])
assert "#N/A" == s[0, 0]


@raises(NotImplementedError)
def test_empty_book_pyexcel_issue_120():
"""
https://github.com/pyexcel/pyexcel/issues/120
"""
writer = Writer("fake.xls", "xls")
writer.write({})
with pytest.raises(NotImplementedError):
writer = Writer("fake.xls", "xls")
writer.write({})


def test_pyexcel_issue_54():
xlvalue = 41071.0
date = xldate_to_python_date(xlvalue, 1)
eq_(date, datetime.date(2016, 6, 12))
assert date == datetime.date(2016, 6, 12)


def get_fixture(file_name):
Expand Down
18 changes: 8 additions & 10 deletions tests/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

from pyexcel_io import get_data, save_data

from nose.tools import eq_


class TestFilter:
def setUp(self):
def setup_method(self):
self.test_file = "test_filter.xls"
sample = [
[1, 21, 31],
Expand All @@ -24,21 +22,21 @@ def test_filter_row(self):
self.test_file, start_row=3, library="pyexcel-xls"
)
expected = [[4, 24, 34], [5, 25, 35], [6, 26, 36]]
eq_(filtered_data[self.sheet_name], expected)
assert 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-xls"
)
expected = [[4, 24, 34]]
eq_(filtered_data[self.sheet_name], expected)
assert filtered_data[self.sheet_name] == expected

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

def test_filter_column_2(self):
filtered_data = get_data(
Expand All @@ -48,14 +46,14 @@ def test_filter_column_2(self):
library="pyexcel-xls",
)
expected = [[21], [22], [23], [24], [25], [26]]
eq_(filtered_data[self.sheet_name], expected)
assert 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-xls"
)
expected = [[24, 34], [25, 35], [26, 36]]
eq_(filtered_data[self.sheet_name], expected)
assert filtered_data[self.sheet_name] == expected

def test_filter_both_ways_2(self):
filtered_data = get_data(
Expand All @@ -67,7 +65,7 @@ def test_filter_both_ways_2(self):
library="pyexcel-xls",
)
expected = [[24]]
eq_(filtered_data[self.sheet_name], expected)
assert filtered_data[self.sheet_name] == expected

def tearDown(self):
def teardown_method(self):
os.unlink(self.test_file)
16 changes: 7 additions & 9 deletions tests/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import pyexcel as pe

from nose.tools import eq_


class TestDateFormat:
def test_reading_date_format(self):
Expand All @@ -22,7 +20,7 @@ def test_reading_date_format(self):
library="pyexcel-xls",
)
assert isinstance(r[1, 0], datetime.date)
eq_(r[1, 0].strftime("%d/%m/%y"), "25/12/14")
assert r[1, 0].strftime("%d/%m/%y") == "25/12/14"
assert isinstance(r[1, 1], datetime.time) is True
assert r[1, 1].strftime("%H:%M:%S") == "11:11:11"
assert r[4, 0].strftime("%d/%m/%Y") == "01/01/1900"
Expand Down Expand Up @@ -62,7 +60,7 @@ def test_writing_date_format(self):


class TestAutoDetectInt:
def setUp(self):
def setup_method(self):
self.content = [[1, 2, 3.1]]
self.test_file = "test_auto_detect_init.xls"
pe.save_as(array=self.content, dest_file_name=self.test_file)
Expand All @@ -76,7 +74,7 @@ def test_auto_detect_int(self):
| 1 | 2 | 3.1 |
+---+---+-----+"""
).strip()
eq_(str(sheet), expected)
assert str(sheet) == expected

def test_get_book_auto_detect_int(self):
book = pe.get_book(file_name=self.test_file, library="pyexcel-xls")
Expand All @@ -87,7 +85,7 @@ def test_get_book_auto_detect_int(self):
| 1 | 2 | 3.1 |
+---+---+-----+"""
).strip()
eq_(str(book), expected)
assert str(book) == expected

def test_auto_detect_int_false(self):
sheet = pe.get_sheet(
Expand All @@ -102,7 +100,7 @@ def test_auto_detect_int_false(self):
| 1.0 | 2.0 | 3.1 |
+-----+-----+-----+"""
).strip()
eq_(str(sheet), expected)
assert str(sheet) == expected

def test_get_book_auto_detect_int_false(self):
book = pe.get_book(
Expand All @@ -117,7 +115,7 @@ def test_get_book_auto_detect_int_false(self):
| 1.0 | 2.0 | 3.1 |
+-----+-----+-----+"""
).strip()
eq_(str(book), expected)
assert str(book) == expected

def tearDown(self):
def teardown_method(self):
os.unlink(self.test_file)
6 changes: 2 additions & 4 deletions tests/test_hidden.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

from pyexcel_xls import get_data

from nose.tools import eq_


def test_simple_hidden_sheets():
data = get_data(
os.path.join("tests", "fixtures", "hidden.xls"),
skip_hidden_row_and_column=True,
)
expected = [[1, 3], [7, 9]]
eq_(data["Sheet1"], expected)
assert data["Sheet1"] == expected


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

0 comments on commit 00a660c

Please sign in to comment.