예제 #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])