swig/Examples/test-suite/python/python_append_runme.py
William S Fulton a01e8474f6 Fixing setting this in Python when using __slots__
Don't attempt to use the class's __dict__ for setting 'this' when
a user has extended a class with:
    __slots__ = ['this'].
Was segfaulting. Now we fall back to a simple PyObject_SetAttr if the
usual approach to setting 'this' in __dict__ does not work.

Closes #1673 Closes #1674
2020-02-06 07:08:16 +00:00

36 lines
880 B
Python

from python_append import *
# test not relevant for -builtin
if is_python_builtin():
exit(0)
t = Test()
t.funk()
t.static_func()
if grabpath() != os.path.dirname(mypath):
raise RuntimeError("grabpath failed")
if grabstaticpath() != os.path.basename(mypath):
raise RuntimeError("grabstaticpath failed")
clearstaticpath()
if grabstaticpath() != None:
raise RuntimeError("Resetting staticfuncpath failed")
Test.static_func()
if grabstaticpath() != os.path.basename(mypath):
raise RuntimeError("grabstaticpath failed")
# slots test
fs = ForSlots()
if fs.ValidVariable != 99:
raise RuntimeError("ValidVariable failed")
fs.ValidVariable = 11
if fs.ValidVariable != 11:
raise RuntimeError("ValidVariable failed")
try:
fs.Invalid = 22
raise RuntimeError("It should not be possible to set a random variable name")
except AttributeError:
pass