示例#1
0
 def test_repr(self):
     node = ConfigNode({
         'some long key': 'some\nvalue',
         'another long key': 2,
         'yet another long key': 3
     })
     compare(repr(node),
             expected=dedent("""\
         configurator.node.ConfigNode(
         {'another long key': 2,
          'some long key': 'some\\nvalue',
          'yet another long key': 3}
         )"""))
示例#2
0
 def test_items_list(self):
     config = ConfigNode([])
     expected = "'list' object has no attribute 'items'"
     with ShouldRaise(AttributeError(expected)):
         tuple(config.items())
示例#3
0
 def test_items_dict(self):
     config = ConfigNode({'foo': 1, 'bar': 2})
     compare(config.items(), expected=[('bar', 2), ('foo', 1)])
示例#4
0
 def test_list_value(self):
     config = ConfigNode({'foo': [1]})
     obj = config['foo']
     assert isinstance(obj, ConfigNode)
     compare(obj.data, expected=[1])
示例#5
0
 def test_simple_value(self):
     config = ConfigNode({})
     compare(config.get('foo', 1), expected=1)
示例#6
0
 def test_get_list_number_key(self):
     config = ConfigNode([1])
     compare(config.get(0), expected=1)
示例#7
0
 def test_set_item(self):
     config = ConfigNode()
     with ShouldRaise(TypeError):
         config['foo'] = 1
     compare(config.data, expected={})
示例#8
0
 def test_get_list_number_key(self):
     config = ConfigNode([1])
     compare(config.get(0), expected=1)
示例#9
0
 def test_list_source(self):
     config = ConfigNode([1])
     with ShouldRaise(AttributeError('foo')):
         config.foo
示例#10
0
 def test_name_clash_with_real_attrs(self):
     # method, data, __method
     config = ConfigNode({'get': 1})
     compare(config.get('get'), expected=1)
示例#11
0
 def test_dict_value(self):
     config = ConfigNode({'foo': {'bar': 1}})
     obj = config.foo
     assert isinstance(obj, ConfigNode)
     compare(obj.data, expected={'bar': 1})
示例#12
0
 def test_simple_value(self):
     config = ConfigNode({'foo': 1})
     compare(config.foo, expected=1)
示例#13
0
 def test_not_there(self):
     config = ConfigNode({})
     with ShouldRaise(AttributeError('foo')):
         config.foo
示例#14
0
 def test_dict(self):
     config = ConfigNode(dict(x=1))
     compare(config['x'], expected=1)
示例#15
0
 def test_there(self):
     config = ConfigNode({'foo': 1})
     compare(config.foo, expected=1)
示例#16
0
 def test_name_clash_with_real_attrs(self):
     # method, data, __method
     config = ConfigNode({'get': 1})
     compare(config.get('get'), expected=1)
示例#17
0
 def test_get(self):
     config = ConfigNode({'foo': 1})
     compare(config.get('foo'), expected=1)
示例#18
0
 def test_simple_source(self):
     config = ConfigNode(1)
     with ShouldRaise(AttributeError('foo')):
         config.foo
示例#19
0
 def test_simple_value(self):
     config = ConfigNode({})
     compare(config.get('foo', 1), expected=1)
示例#20
0
 def test_set_attr(self):
     config = ConfigNode()
     with ShouldRaise(AttributeError):
         config.foo = 1
     compare(config.data, expected={})
示例#21
0
 def test_get_default_default(self):
     config = ConfigNode({})
     compare(config.get('foo'), expected=None)
示例#22
0
 def test_list(self):
     config = ConfigNode([1, 2])
     compare(config[0], expected=1)
     compare(config[1], expected=2)
     compare(list(config), expected=[1, 2])
示例#23
0
 def test_get_list_string_key(self):
     config = ConfigNode([1])
     compare(config.get('foo'), expected=None)
示例#24
0
 def test_iterate_over_list_of_dicts(self):
     node = ConfigNode([{'x': 1}])
     compare(tuple(node)[0], expected=ConfigNode({'x': 2}))
示例#25
0
 def test_empty(self):
     config = ConfigNode()
     compare(config.data, expected={})
示例#26
0
 def test_int(self):
     # not very useful, but documents .data as a public api
     config = ConfigNode(1)
     compare(config.data, 1)
示例#27
0
 def test_get_wrapped_value(self):
     config = ConfigNode({'foo': {'bar': 1}})
     obj = config['foo']
     assert isinstance(obj, ConfigNode)
     compare(obj.data, expected={'bar': 1})
示例#28
0
 def test_there_dict(self):
     config = ConfigNode({'foo': 1})
     compare(config['foo'], expected=1)
示例#29
0
 def test_items_list(self):
     config = ConfigNode([])
     expected = "'list' object has no attribute 'items'"
     with ShouldRaise(AttributeError(expected)):
         tuple(config.items())
示例#30
0
 def test_there_list(self):
     config = ConfigNode([1])
     compare(config[0], expected=1)
示例#31
0
 def test_items_wrapped_value(self):
     config = ConfigNode({'foo': [1]})
     obj = tuple(config.items())[0][1]
     assert isinstance(obj, ConfigNode)
     compare(obj.data, expected=[1])
示例#32
0
 def test_not_there_dict(self):
     config = ConfigNode({})
     with ShouldRaise(KeyError('foo')):
         config['foo']
示例#33
0
 def test_set_attr(self):
     config = ConfigNode()
     with ShouldRaise(AttributeError):
         config.foo = 1
     compare(config.data, expected={})
示例#34
0
 def test_not_there_list(self):
     config = ConfigNode([])
     with ShouldRaise(IndexError('list index out of range')):
         config[0]
示例#35
0
 def test_get_default_default(self):
     config = ConfigNode({})
     compare(config.get('foo'), expected=None)
示例#36
0
 def test_not_there_simple(self):
     config = ConfigNode(1)
     with ShouldRaise(KeyError('foo')):
         config['foo']
示例#37
0
 def test_get_list_string_key(self):
     config = ConfigNode([1])
     compare(config.get('foo'), expected=None)
示例#38
0
 def test_get(self):
     config = ConfigNode({'foo': 1})
     compare(config.get('foo'), expected=1)
示例#39
0
 def test_items_dict(self):
     config = ConfigNode({'foo': 1, 'bar': 2})
     compare(config.items(), expected=[('bar', 2), ('foo', 1)])
示例#40
0
 def test_items_wrapped_value(self):
     config = ConfigNode({'foo': [1]})
     obj = tuple(config.items())[0][1]
     assert isinstance(obj, ConfigNode)
     compare(obj.data, expected=[1])