示例#1
0
    def test_key_info():
        o = CustomObject()
        o.my_field = 1
        o.test_exec = lambda: False
        readable_invokable_insertable = polyglot.__key_info__(o, "__init__")

        readable_invokable_modifiable_insertable = polyglot.__key_info__(
            o, "__len__")
        assert readable_invokable_modifiable_insertable == polyglot.__key_info__(
            o, "test_exec")

        readable_modifiable_insertable = polyglot.__key_info__(o, "field")
        assert readable_modifiable_insertable == polyglot.__key_info__(
            o, "my_field")

        assert readable_invokable_insertable != readable_modifiable_insertable
        assert readable_invokable_insertable != readable_invokable_modifiable_insertable
        assert readable_modifiable_insertable != readable_invokable_modifiable_insertable

        sideeffects_get = polyglot.__key_info__(o, "getter")
        sideeffects_get_set = polyglot.__key_info__(o, "setter")
        assert sideeffects_get != sideeffects_get_set
示例#2
0
    def test_key_info():
        o = CustomObject()
        o.my_field = 1
        o.test_exec = lambda: False

        assert polyglot.__key_info__(o, "__len__", "readable")
        assert polyglot.__key_info__(o, "__len__", "invokable")
        assert polyglot.__key_info__(o, "__len__", "modifiable")
        assert polyglot.__key_info__(o, "__len__", "removable")
        assert not polyglot.__key_info__(o, "__len__", "insertable")

        assert polyglot.__key_info__(o, "test_exec", "readable")
        assert polyglot.__key_info__(o, "test_exec", "invokable")
        assert polyglot.__key_info__(o, "test_exec", "modifiable")
        assert polyglot.__key_info__(o, "test_exec", "removable")
        assert not polyglot.__key_info__(o, "test_exec", "insertable")

        assert polyglot.__key_info__(o, "my_field", "readable")
        assert not polyglot.__key_info__(o, "my_field", "invokable")
        assert polyglot.__key_info__(o, "my_field", "modifiable")
        assert polyglot.__key_info__(o, "my_field", "removable")
        assert not polyglot.__key_info__(o, "my_field", "insertable")

        assert polyglot.__key_info__(o, "__getattribute__", "readable")
        assert polyglot.__key_info__(o, "__getattribute__", "invokable")
        assert not polyglot.__key_info__(o, "__getattribute__", "removable")
        assert not polyglot.__key_info__(o, "__getattribute__", "insertable")

        builtinObj = (1,2,3)
        assert polyglot.__key_info__(builtinObj, "__len__", "readable")
        assert polyglot.__key_info__(builtinObj, "__len__", "invokable")
        assert not polyglot.__key_info__(builtinObj, "__len__", "modifiable")
        assert not polyglot.__key_info__(builtinObj, "__len__", "removable")
        assert not polyglot.__key_info__(builtinObj, "__len__", "insertable")