Ejemplo n.º 1
0
        def supports_readonly_dict_protocols(self):
            # Use single-keypair dict to avoid sorting problems in tests.
            c = Config(defaults={"foo": "bar"})
            c2 = Config(defaults={"foo": "bar"})
            assert "foo" in c
            assert "foo" in c2  # mostly just to trigger loading :x
            assert c == c2
            assert len(c) == 1
            assert c.get("foo") == "bar"
            if six.PY2:
                assert c.has_key("foo") is True  # noqa
                assert list(c.iterkeys()) == ["foo"]
                assert list(c.itervalues()) == ["bar"]
            assert list(c.items()) == [("foo", "bar")]
            assert list(six.iteritems(c)) == [("foo", "bar")]
            assert list(c.keys()) == ["foo"]
            assert list(c.values()) == ["bar"]

            # magicinvoke callable tests
            alias = lambda ctx: ctx.B
            bval = 2
            c3 = Config(defaults={"A": {"num": 1}, "B": bval})
            c3.A.myalias = alias

            assert c3.A.myalias == bval
            assert c3["A"]["myalias"] == bval

            # More advanced traversal tests
            assert c3.get("A").get("myalias", call=False) is alias
            c3.A.loop = lambda ctx: ctx.A
            c3.A.loop.loop.get("loop")["loop"] == c3.A
            c3.A.get("loop", call=False)(c3) == c3.A

            c3.A.num = Lazy("ctx.B")
            assert c3.A.num == c3.B
Ejemplo n.º 2
0
 def supports_readonly_dict_protocols(self):
     # Use single-keypair dict to avoid sorting problems in tests.
     c = Config(defaults={'foo': 'bar'})
     c2 = Config(defaults={'foo': 'bar'})
     assert 'foo' in c
     assert 'foo' in c2 # mostly just to trigger loading :x
     assert c == c2
     assert len(c) == 1
     assert c.get('foo') == 'bar'
     if six.PY2:
         assert c.has_key('foo') is True  # noqa
         assert list(c.iterkeys()) == ['foo']
         assert list(c.itervalues()) == ['bar']
     assert list(c.items()) == [('foo', 'bar')]
     assert list(six.iteritems(c)) == [('foo', 'bar')]
     assert list(c.keys()) == ['foo']
     assert list(c.values()) == ['bar']
Ejemplo n.º 3
0
 def supports_readonly_dict_protocols(self):
     # Use single-keypair dict to avoid sorting problems in tests.
     c = Config(defaults={'foo': 'bar'})
     c2 = Config(defaults={'foo': 'bar'})
     ok_('foo' in c)
     ok_('foo' in c2) # mostly just to trigger loading :x
     eq_(c, c2)
     eq_(len(c), 1)
     eq_(c.get('foo'), 'bar')
     if six.PY2:
         eq_(c.has_key('foo'), True)  # noqa
         eq_(list(c.iterkeys()), ['foo'])
         eq_(list(c.itervalues()), ['bar'])
     eq_(list(c.items()), [('foo', 'bar')])
     eq_(list(six.iteritems(c)), [('foo', 'bar')])
     eq_(list(c.keys()), ['foo'])
     eq_(list(c.values()), ['bar'])
Ejemplo n.º 4
0
 def supports_readonly_dict_protocols(self):
     # Use single-keypair dict to avoid sorting problems in tests.
     c = Config(defaults={"foo": "bar"})
     c2 = Config(defaults={"foo": "bar"})
     assert "foo" in c
     assert "foo" in c2  # mostly just to trigger loading :x
     assert c == c2
     assert len(c) == 1
     assert c.get("foo") == "bar"
     if six.PY2:
         assert c.has_key("foo") is True  # noqa
         assert list(c.iterkeys()) == ["foo"]
         assert list(c.itervalues()) == ["bar"]
     assert list(c.items()) == [("foo", "bar")]
     assert list(six.iteritems(c)) == [("foo", "bar")]
     assert list(c.keys()) == ["foo"]
     assert list(c.values()) == ["bar"]
Ejemplo n.º 5
0
 def supports_readonly_dict_protocols(self):
     # Use single-keypair dict to avoid sorting problems in tests.
     c = Config(defaults={'foo': 'bar'})
     c2 = Config(defaults={'foo': 'bar'})
     assert 'foo' in c
     assert 'foo' in c2  # mostly just to trigger loading :x
     assert c == c2
     assert len(c) == 1
     assert c.get('foo') == 'bar'
     if six.PY2:
         assert c.has_key('foo') is True  # noqa
         assert list(c.iterkeys()) == ['foo']
         assert list(c.itervalues()) == ['bar']
     assert list(c.items()) == [('foo', 'bar')]
     assert list(six.iteritems(c)) == [('foo', 'bar')]
     assert list(c.keys()) == ['foo']
     assert list(c.values()) == ['bar']