|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# coding=utf-8 |
|
3
|
|
|
from __future__ import division, print_function, unicode_literals |
|
4
|
|
|
import pytest |
|
5
|
|
|
from sacred.config.custom_containers import FallbackDict |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
@pytest.fixture |
|
9
|
|
|
def fbdict(): |
|
10
|
|
|
return FallbackDict({'fall1': 7, 'fall3': True}) |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
def test_is_dictionary(fbdict): |
|
14
|
|
|
assert isinstance(fbdict, dict) |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
def test_getitem(fbdict): |
|
18
|
|
|
assert 'foo' not in fbdict |
|
19
|
|
|
fbdict['foo'] = 23 |
|
20
|
|
|
assert 'foo' in fbdict |
|
21
|
|
|
assert fbdict['foo'] == 23 |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
def test_fallback(fbdict): |
|
25
|
|
|
assert 'fall1' in fbdict |
|
26
|
|
|
assert fbdict['fall1'] == 7 |
|
27
|
|
|
fbdict['fall1'] = 8 |
|
28
|
|
|
assert fbdict['fall1'] == 8 |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
def test_get(fbdict): |
|
32
|
|
|
fbdict['a'] = 'b' |
|
33
|
|
|
assert fbdict.get('a', 18) == 'b' |
|
34
|
|
|
assert fbdict.get('fall1', 18) == 7 |
|
35
|
|
|
assert fbdict.get('notexisting', 18) == 18 |
|
36
|
|
|
assert fbdict.get('fall3', 18) is True |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
@pytest.mark.parametrize('method', |
|
40
|
|
|
['items', 'iteritems', 'iterkeys', 'itervalues', |
|
41
|
|
|
'keys', 'popitem', 'update', 'values', 'viewitems', |
|
42
|
|
|
'viewkeys', 'viewvalues', '__iter__', '__len__']) |
|
43
|
|
|
def test_not_implemented(method, fbdict): |
|
44
|
|
|
with pytest.raises(NotImplementedError): |
|
45
|
|
|
getattr(fbdict, method)() |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
def test_special_not_implemented(fbdict): |
|
49
|
|
|
with pytest.raises(NotImplementedError): |
|
50
|
|
|
fbdict.pop('fall1') |
|
51
|
|
|
with pytest.raises(NotImplementedError): |
|
52
|
|
|
fbdict.setdefault('fall2', None) |
|
53
|
|
|
|