File: test_utils.py

package info (click to toggle)
python-nbstripout 0.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: python: 870; sh: 18; makefile: 13
file content (37 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pytest

from nbstripout._utils import pop_recursive


def make_dict():
    return {'a': {'b': 1, 'c': 2, 'd.e': 3, 'f': {'g': 4}}}


def make_data(default=None):
    return [
        ('a.c', 2, {'a': {'b': 1, 'd.e': 3, 'f': {'g': 4}}}),
        ('a.d.e', 3, {'a': {'b': 1, 'c': 2, 'f': {'g': 4}}}),
        ('a.f', {'g': 4}, {'a': {'b': 1, 'c': 2, 'd.e': 3}}),
        ('a.f.g', 4, {'a': {'b': 1, 'c': 2, 'd.e': 3, 'f': {}}}),
        ('a', {'b': 1, 'c': 2, 'd.e': 3, 'f': {'g': 4}}, {}),
        ('notfound', default, make_dict()),
        ('a.notfound', default, make_dict()),
        ('a.b.notfound', default, make_dict()),
    ]


@pytest.fixture
def d():
    return make_dict()


@pytest.mark.parametrize(('key', 'res', 'remainder'), make_data())
def test_pop_recursive(d, key, res, remainder):
    assert pop_recursive(d, key) == res
    assert d == remainder


@pytest.mark.parametrize(('key', 'res', 'remainder'), make_data(default=0))
def test_pop_recursive_default(d, key, res, remainder):
    assert pop_recursive(d, key, default=0) == res
    assert d == remainder