summaryrefslogtreecommitdiff
path: root/tests/test_collections.py
blob: 5007948b84c29c7daf1332ebb327b6d8a2fd5827 (plain)
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 asciidoc.collections import AttrDict, DefaultAttrDict, InsensitiveDict


def test_attr_dict():
    d = AttrDict()
    d.a = 1
    d['b'] = 2
    assert d['a'] == 1
    assert d.b == 2
    del d['a']
    del d.b
    assert 'a' not in d
    assert 'b' not in d
    assert d.c is None

    with pytest.raises(AttributeError):
        del d.c


def test_default_attr_dict():
    d = DefaultAttrDict()
    with pytest.raises(AttributeError):
        d.a
    d._default = 'test'

    assert d.a == 'test'


def test_insensitive_dict():
    d = InsensitiveDict()
    d['A'] = 1
    assert d['a'] == 1
    d['aBaBa'] = 2
    assert 'AbAbA' in d
    del d['abaBA']
    assert ('ababa' in d) is False