コード例 #1
0
ファイル: test_struct.py プロジェクト: pombredanne/tri.struct
    def test_hash(self, Struct):
        s = Struct(x=17)
        with pytest.raises(TypeError) as e:
            hash(s)
        if platform.python_implementation() == "PyPy":
            assert "" in str(e)
        else:
            assert "unhashable type: 'Struct'" in str(e)

        f = FrozenStruct(x=17)
        assert isinstance(hash(f), int)
        assert not '_hash' in f.keys()
コード例 #2
0
ファイル: test_struct.py プロジェクト: pombredanne/tri.struct
    def test_modify_frozen_struct(self):
        f = FrozenStruct(x=17)
        with pytest.raises(TypeError) as e:
            f.x = 42
        assert "'FrozenStruct' object attributes are read-only" in str(e)

        with pytest.raises(TypeError) as e:
            f['x'] = 42
        assert "'FrozenStruct' object attributes are read-only" in str(e)

        with pytest.raises(TypeError) as e:
            f.update(dict(x=42))
        assert "'FrozenStruct' object attributes are read-only" in str(e)

        with pytest.raises(TypeError) as e:
            f.setdefault('foo', 11)
        assert "'FrozenStruct' object attributes are read-only" in str(e)

        with pytest.raises(TypeError) as e:
            f.clear()
        assert "'FrozenStruct' object attributes are read-only" in str(e)

        with pytest.raises(TypeError) as e:
            del f.x
        assert "'FrozenStruct' object attributes are read-only" in str(e)

        with pytest.raises(TypeError) as e:
            del f['x']
        assert "'FrozenStruct' object attributes are read-only" in str(e)