Example #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}
         )"""))
Example #2
0
 def test_items_list(self):
     config = ConfigNode([])
     expected = "'list' object has no attribute 'items'"
     with ShouldRaise(AttributeError(expected)):
         tuple(config.items())
Example #3
0
 def test_items_dict(self):
     config = ConfigNode({'foo': 1, 'bar': 2})
     compare(config.items(), expected=[('bar', 2), ('foo', 1)])
Example #4
0
 def test_list_value(self):
     config = ConfigNode({'foo': [1]})
     obj = config['foo']
     assert isinstance(obj, ConfigNode)
     compare(obj.data, expected=[1])
Example #5
0
 def test_simple_value(self):
     config = ConfigNode({})
     compare(config.get('foo', 1), expected=1)
Example #6
0
 def test_get_list_number_key(self):
     config = ConfigNode([1])
     compare(config.get(0), expected=1)
Example #7
0
 def test_set_item(self):
     config = ConfigNode()
     with ShouldRaise(TypeError):
         config['foo'] = 1
     compare(config.data, expected={})
Example #8
0
 def test_get_list_number_key(self):
     config = ConfigNode([1])
     compare(config.get(0), expected=1)
Example #9
0
 def test_list_source(self):
     config = ConfigNode([1])
     with ShouldRaise(AttributeError('foo')):
         config.foo
Example #10
0
 def test_name_clash_with_real_attrs(self):
     # method, data, __method
     config = ConfigNode({'get': 1})
     compare(config.get('get'), expected=1)
Example #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})
Example #12
0
 def test_simple_value(self):
     config = ConfigNode({'foo': 1})
     compare(config.foo, expected=1)
Example #13
0
 def test_not_there(self):
     config = ConfigNode({})
     with ShouldRaise(AttributeError('foo')):
         config.foo
Example #14
0
 def test_dict(self):
     config = ConfigNode(dict(x=1))
     compare(config['x'], expected=1)
Example #15
0
 def test_there(self):
     config = ConfigNode({'foo': 1})
     compare(config.foo, expected=1)
Example #16
0
 def test_name_clash_with_real_attrs(self):
     # method, data, __method
     config = ConfigNode({'get': 1})
     compare(config.get('get'), expected=1)
Example #17
0
 def test_get(self):
     config = ConfigNode({'foo': 1})
     compare(config.get('foo'), expected=1)
Example #18
0
 def test_simple_source(self):
     config = ConfigNode(1)
     with ShouldRaise(AttributeError('foo')):
         config.foo
Example #19
0
 def test_simple_value(self):
     config = ConfigNode({})
     compare(config.get('foo', 1), expected=1)
Example #20
0
 def test_set_attr(self):
     config = ConfigNode()
     with ShouldRaise(AttributeError):
         config.foo = 1
     compare(config.data, expected={})
Example #21
0
 def test_get_default_default(self):
     config = ConfigNode({})
     compare(config.get('foo'), expected=None)
Example #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])
Example #23
0
 def test_get_list_string_key(self):
     config = ConfigNode([1])
     compare(config.get('foo'), expected=None)
Example #24
0
 def test_iterate_over_list_of_dicts(self):
     node = ConfigNode([{'x': 1}])
     compare(tuple(node)[0], expected=ConfigNode({'x': 2}))
Example #25
0
 def test_empty(self):
     config = ConfigNode()
     compare(config.data, expected={})
Example #26
0
 def test_int(self):
     # not very useful, but documents .data as a public api
     config = ConfigNode(1)
     compare(config.data, 1)
Example #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})
Example #28
0
 def test_there_dict(self):
     config = ConfigNode({'foo': 1})
     compare(config['foo'], expected=1)
Example #29
0
 def test_items_list(self):
     config = ConfigNode([])
     expected = "'list' object has no attribute 'items'"
     with ShouldRaise(AttributeError(expected)):
         tuple(config.items())
Example #30
0
 def test_there_list(self):
     config = ConfigNode([1])
     compare(config[0], expected=1)
Example #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])
Example #32
0
 def test_not_there_dict(self):
     config = ConfigNode({})
     with ShouldRaise(KeyError('foo')):
         config['foo']
Example #33
0
 def test_set_attr(self):
     config = ConfigNode()
     with ShouldRaise(AttributeError):
         config.foo = 1
     compare(config.data, expected={})
Example #34
0
 def test_not_there_list(self):
     config = ConfigNode([])
     with ShouldRaise(IndexError('list index out of range')):
         config[0]
Example #35
0
 def test_get_default_default(self):
     config = ConfigNode({})
     compare(config.get('foo'), expected=None)
Example #36
0
 def test_not_there_simple(self):
     config = ConfigNode(1)
     with ShouldRaise(KeyError('foo')):
         config['foo']
Example #37
0
 def test_get_list_string_key(self):
     config = ConfigNode([1])
     compare(config.get('foo'), expected=None)
Example #38
0
 def test_get(self):
     config = ConfigNode({'foo': 1})
     compare(config.get('foo'), expected=1)
Example #39
0
 def test_items_dict(self):
     config = ConfigNode({'foo': 1, 'bar': 2})
     compare(config.items(), expected=[('bar', 2), ('foo', 1)])
Example #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])