mapnik / python-mapnik

Python bindings for mapnik
GNU Lesser General Public License v2.1
160 stars 91 forks source link

Unit tests - migrate from `nose` to `pytest` #264

Closed artemp closed 2 months ago

artemp commented 1 year ago

The issue

Current nose based tests are not compatible with python3.11. nose itself is out of date.

Solution

Migrate unit tests to use pytest

artemp commented 1 year ago

Cheat sheet

(borrowed from nose2pytest)

Basic nose to pytest conversion table

Function Statement
assert_true(a[, msg]) assert a[, msg]
assert_false(a[, msg]) assert not a[, msg]
assert_is_none(a[, msg]) assert a is None[, msg]
assert_is_not_none(a[, msg]) assert a is not None[, msg]
assert_equal(a,b[, msg]) assert a == b[, msg]
assert_not_equal(a,b[, msg]) assert a != b[, msg]
assert_list_equal(a,b[, msg]) assert a == b[, msg]
assert_dict_equal(a,b[, msg]) assert a == b[, msg]
assert_set_equal(a,b[, msg]) assert a == b[, msg]
assert_sequence_equal(a,b[, msg]) assert a == b[, msg]
assert_tuple_equal(a,b[, msg]) assert a == b[, msg]
assert_multi_line_equal(a,b[, msg]) assert a == b[, msg]
assert_greater(a,b[, msg]) assert a > b[, msg]
assert_greater_equal(a,b[, msg]) assert a >= b[, msg]
assert_less(a,b[, msg]) assert a < b[, msg]
assert_less_equal(a,b[, msg]) assert a <= b[, msg]
assert_in(a,b[, msg]) assert a in b[, msg]
assert_not_in(a,b[, msg]) assert a not in b[, msg]
assert_is(a,b[, msg]) assert a is b[, msg]
assert_is_not(a,b[, msg]) assert a is not b[, msg]
assert_is_instance(a,b[, msg]) assert isinstance(a, b)[, msg]
assert_count_equal(a,b[, msg]) assert collections.Counter(a) == collections.Counter(b)[, msg]
assert_not_regex(a,b[, msg]) assert not re.search(b, a)[, msg]
assert_regex(a,b[, msg]) assert re.search(b, a)[, msg]
assert_almost_equal(a,b[, msg]) assert a == pytest.approx(b, abs=1e-7)[, msg]
assert_almost_equal(a,b, delta[, msg]) assert a == pytest.approx(b, abs=delta)[, msg]
assert_almost_equal(a, b, places[, msg]) assert a == pytest.approx(b, abs=1e-places)[, msg]
assert_not_almost_equal(a,b[, msg]) assert a != pytest.approx(b, abs=1e-7)[, msg]
assert_not_almost_equal(a,b, delta[, msg]) assert a != pytest.approx(b, abs=delta)[, msg]
assert_not_almost_equal(a,b, places[, msg]) assert a != pytest.approx(b, abs=1e-places)[, msg]
artemp commented 1 year ago

@mathisloge - just linking you here for possible feedback and future reference. The idea is to use a very simple (no python knowledge required) approach.

I had a look at nose2 but didn't find it a inspiring (ref https://nglogic.com/python-unit-testing-frameworks/ )

mathisloge commented 1 year ago

I will take a look @artemp

artemp commented 1 year ago

I will take a look @artemp

👍 I started migration and it's looking good so far..

artemp commented 1 year ago

https://github.com/mapnik/python-mapnik/tree/pytest [WIP]

dotlambda commented 2 months ago

Any progress on this?

https://github.com/mapnik/python-mapnik/tree/pytest

This doesn't exist anymore but I'd be interested in using it as a patch in Nixpkgs.

artemp commented 2 months ago

Any progress on this?

https://github.com/mapnik/python-mapnik/tree/pytest

This doesn't exist anymore but I'd be interested in using it as a patch in Nixpkgs.

@dotlambda merged into master