コード例 #1
0
    def test_iterkeys(self):
        assert sorted(iterkeys(OpenStruct())) == []

        o = OpenStruct({'foo': 123})
        assert sorted(iterkeys(o)) == sorted(o.keys())

        o['bar'] = 456
        assert sorted(iterkeys(o)) == sorted(o.keys())
コード例 #2
0
    def test_itervalues(self):
        assert sorted(itervalues(OpenStruct())) == []

        o = OpenStruct({'foo': 'hello'})
        assert sorted(itervalues(o)) == sorted(o.values())

        o['bar'] = 'howdy'
        assert sorted(itervalues(o)) == sorted(o.values())
コード例 #3
0
    def test_iter(self):
        assert [x for x in OpenStruct()] == []

        o = OpenStruct({'foo': 'hello'})
        assert sorted([x for x in o]) == sorted(o.keys())

        o['bar'] = 123
        assert sorted([x for x in o]) == sorted(o.keys())
コード例 #4
0
    def test_iteritems(self):
        assert sorted(iteritems(OpenStruct())) == []

        o = OpenStruct({'foo': 'hello'})
        assert sorted(iteritems(o)) == sorted(o.items())

        o['bar'] = 123
        assert sorted(iteritems(o)) == sorted(o.items())
コード例 #5
0
    def test_length(self):
        assert len(OpenStruct()) == 0

        o = OpenStruct({'foo': 'hello'})
        assert len(o) == 1

        o['bar'] = 123
        assert len(o) == 2
コード例 #6
0
    def test_values(self):
        assert sorted(OpenStruct().values()) == []

        o = OpenStruct({'foo': 123})
        assert sorted(o.values()) == sorted([123])

        o['bar'] = 456
        assert sorted(o.values()) == sorted([123, 456])
コード例 #7
0
    def test_items(self):
        assert sorted(OpenStruct().items()) == []

        o = OpenStruct({'foo': 'hello'})
        assert sorted(o.items()) == sorted([('foo', 'hello')])

        o['bar'] = 123
        assert sorted(o.items()) == sorted([('foo', 'hello'), ('bar', 123)])
コード例 #8
0
    def test_keys(self):
        assert sorted(OpenStruct().keys()) == []

        o = OpenStruct({'foo': 1, 'bar': 2})
        assert sorted(o.keys()) == sorted(['foo', 'bar'])

        o['baz'] = 2
        assert sorted(o.keys()) == sorted(['foo', 'bar', 'baz'])
コード例 #9
0
    def test_setattr(self):
        o = OpenStruct({'foo': 'hello'})

        o.foo = 'goodbye'
        o.bar = 123

        assert o.foo == 'goodbye'
        assert o.bar == 123
        assert o['foo'] == o.foo
        assert o['bar'] == o.bar
コード例 #10
0
    def test_hasattr(self):
        o = OpenStruct({'foo': 'hello'})
        o['bar'] = 123

        assert hasattr(o, 'foo')
        assert hasattr(o, 'bar')
        assert not hasattr(o, 'baz')
コード例 #11
0
    def test_setting_values(self):
        o = OpenStruct({'foo': 'hello'})
        o['foo'] = 'goodbye'
        o['bar'] = 111

        assert o['foo'] == 'goodbye'
        assert o['bar'] == 111
コード例 #12
0
    def test_delattr(self):
        o = OpenStruct({'foo': 'hello'})
        o['bar'] = 123

        del o.foo
        assert not hasattr(o, 'foo')

        del o.bar
        assert not hasattr(o, 'bar')
コード例 #13
0
    def test_deleting_values(self):
        o = OpenStruct({'foo': 'hello'})

        del o['foo']
        assert 'foo' not in o

        o['bar'] = 123
        del o['bar']
        assert 'bar' not in o
コード例 #14
0
    def test_contains(self):
        o = OpenStruct({'foo': 'hello'})

        assert 'foo' in o
        assert 'bar' not in o

        o['bar'] = 123

        assert 'foo' in o
        assert 'bar' in o
コード例 #15
0
    def test_getattr_on_nonexisting_key_raises_AttributeError(self):
        o = OpenStruct({'foo': 'hello'})

        with pytest.raises(AttributeError):
            x = o.baz
コード例 #16
0
    def test_getattr(self):
        o = OpenStruct({'foo': 'hello'})
        o['bar'] = 123

        assert o.foo == 'hello'
        assert o.bar == 123
コード例 #17
0
    def test_getting_nonexisting_values_raises_KeyError(self):
        o = OpenStruct({'foo': 'hello', 'bar': 123})

        with pytest.raises(KeyError):
            x = o['baz']
コード例 #18
0
    def test_deleting_nonexisting_values_raises_KeyError(self):
        o = OpenStruct({'foo': 'hello'})

        with pytest.raises(KeyError):
            del o['bar']
コード例 #19
0
    def test_delattr_on_nonexisting_key_raises_AttributeError(self):
        o = OpenStruct()

        with pytest.raises(AttributeError):
            del o.foo
コード例 #20
0
 def test_getting_values(self):
     o = OpenStruct({'foo': 'hello', 'bar': 123})
     assert o['foo'] == 'hello'
     assert o['bar'] == 123