python-mapnik
python-mapnik copied to clipboard
Unit tests - migrate from `nose` to `pytest`
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
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] |
@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/ )
I will take a look @artemp
I will take a look @artemp
👍 I started migration and it's looking good so far..
https://github.com/mapnik/python-mapnik/tree/pytest [WIP]