summaryrefslogtreecommitdiff
path: root/tests/test_collections.py
blob: 6451f37bbf06b645200f3e6d5bf4173158df49ab (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
38
39
40
41
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
    d.setdefault('D', 'test')
    assert d['d'] == 'test'
    d.setdefault('A', 'foo')
    assert d['a'] == 1