python-mapnik icon indicating copy to clipboard operation
python-mapnik copied to clipboard

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

Open artemp opened this issue 2 years ago • 5 comments

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 avatar Jan 25 '23 14:01 artemp

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 avatar Jan 25 '23 14:01 artemp

@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/ )

artemp avatar Jan 25 '23 14:01 artemp

I will take a look @artemp

mathisloge avatar Jan 25 '23 14:01 mathisloge

I will take a look @artemp

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

artemp avatar Jan 25 '23 14:01 artemp

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

artemp avatar Jan 26 '23 21:01 artemp