summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Dahlin <johan@src.gnome.org>2004-07-19 11:29:13 +0000
committerJohan Dahlin <johan@src.gnome.org>2004-07-19 11:29:13 +0000
commitc2d430551d355245c74e8b30ca4796e772f42275 (patch)
tree501c7dd5ef8a0176a3781a7c600c431704f5961b
parentcfa02147247fa59b82eff91e2058d1488ff438e3 (diff)
downloadpygobject-c2d430551d355245c74e8b30ca4796e772f42275.tar.gz
pygobject-c2d430551d355245c74e8b30ca4796e772f42275.tar.xz
pygobject-c2d430551d355245c74e8b30ca4796e772f42275.zip
Fix, a window is really WITHDRAWN if it's not SHOWN and not ICONIFIED...
* tests/enum.py (EnumTest.testWindowGetState): Fix, a window is really WITHDRAWN if it's not SHOWN and not ICONIFIED... * tests/common.py: Add .. and ../gobject when distcheck isn't ran * gobject/pygenum.c: Use a dict instead of a tuple for __enum_values__, so we can handle negative enum values (eg: GDK_NOTHING) * gobject/pyflags.c: Ditto for __flag_values__ * gobject/pygparamspec.c (pyg_param_spec_getattr): reference count fixing
-rw-r--r--gobject/pygenum.c40
-rw-r--r--gobject/pygflags.c10
-rw-r--r--gobject/pygparamspec.c2
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/common.py7
-rw-r--r--tests/enum.py10
6 files changed, 42 insertions, 29 deletions
diff --git a/gobject/pygenum.c b/gobject/pygenum.c
index ecc4dbe..0ccbb90 100644
--- a/gobject/pygenum.c
+++ b/gobject/pygenum.c
@@ -108,7 +108,7 @@ pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
return NULL;
}
- if (!PyTuple_Check(values) || PyTuple_Size(values) != eclass->n_values) {
+ if (!PyDict_Check(values) || PyDict_Size(values) != eclass->n_values) {
PyErr_SetString(PyExc_TypeError, "__enum_values__ badly formed");
Py_DECREF(values);
g_type_class_unref(eclass);
@@ -117,7 +117,7 @@ pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
g_type_class_unref(eclass);
- ret = PyTuple_GetItem(values, value);
+ ret = PyDict_GetItem(values, PyInt_FromLong(value));
Py_INCREF(ret);
Py_DECREF(values);
return ret;
@@ -135,9 +135,9 @@ pyg_enum_from_gtype (GType gtype, int value)
values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict,
"__enum_values__");
- retval = PyTuple_GetItem(values, value);
+ retval = PyDict_GetItem(values, PyInt_FromLong(value));
Py_INCREF(retval);
-
+
return retval;
}
@@ -181,28 +181,28 @@ pyg_enum_add (PyObject * module,
/* Register enum values */
eclass = G_ENUM_CLASS(g_type_class_ref(gtype));
- values = PyTuple_New(eclass->n_values);
+ values = PyDict_New();
for (i = 0; i < eclass->n_values; i++) {
- PyObject *item;
+ PyObject *item;
+
+ item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0);
+ ((PyIntObject*)item)->ob_ival = eclass->values[i].value;
+ ((PyGEnum*)item)->gtype = gtype;
+
+ PyDict_SetItem(values, PyInt_FromLong(eclass->values[i].value), item);
- item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0);
- ((PyIntObject*)item)->ob_ival = eclass->values[i].value;
- ((PyGEnum*)item)->gtype = gtype;
-
- PyTuple_SetItem(values, i, item);
-
- PyModule_AddObject(module,
- pyg_constant_strip_prefix(eclass->values[i].value_name,
- strip_prefix),
- item);
- Py_INCREF(item);
- }
+ PyModule_AddObject(module,
+ pyg_constant_strip_prefix(eclass->values[i].value_name,
+ strip_prefix),
+ item);
+ Py_INCREF(item);
+ }
PyDict_SetItemString(((PyTypeObject *)stub)->tp_dict,
"__enum_values__", values);
- Py_DECREF(values);
+ Py_DECREF(values);
- g_type_class_unref(eclass);
+ g_type_class_unref(eclass);
return stub;
}
diff --git a/gobject/pygflags.c b/gobject/pygflags.c
index d90f677..9a07ffb 100644
--- a/gobject/pygflags.c
+++ b/gobject/pygflags.c
@@ -133,7 +133,7 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
return NULL;
}
- if (!PyTuple_Check(values) || PyTuple_Size(values) != eclass->n_values) {
+ if (!PyDict_Check(values) || PyDict_Size(values) != eclass->n_values) {
PyErr_SetString(PyExc_TypeError, "__flags_values__ badly formed");
Py_DECREF(values);
g_type_class_unref(eclass);
@@ -142,7 +142,7 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
g_type_class_unref(eclass);
- ret = PyTuple_GetItem(values, value);
+ ret = PyDict_GetItem(values, PyInt_FromLong(value));
Py_INCREF(ret);
Py_DECREF(values);
return ret;
@@ -160,7 +160,7 @@ pyg_flags_from_gtype (GType gtype, int value)
values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict,
"__flags_values__");
- retval = PyTuple_GetItem(values, value);
+ retval = PyDict_GetItem(values, PyInt_FromLong(value));
if (!retval) {
PyErr_Clear();
@@ -215,7 +215,7 @@ pyg_flags_add (PyObject * module,
/* Register flag values */
eclass = G_FLAGS_CLASS(g_type_class_ref(gtype));
- values = PyTuple_New(eclass->n_values);
+ values = PyDict_New();
for (i = 0; i < eclass->n_values; i++) {
PyObject *item;
@@ -223,7 +223,7 @@ pyg_flags_add (PyObject * module,
((PyIntObject*)item)->ob_ival = eclass->values[i].value;
((PyGFlags*)item)->gtype = gtype;
- PyTuple_SetItem(values, i, item);
+ PyDict_SetItem(values, PyInt_FromLong(eclass->values[i].value), item);
PyModule_AddObject(module,
pyg_constant_strip_prefix(eclass->values[i].value_name,
diff --git a/gobject/pygparamspec.c b/gobject/pygparamspec.c
index b515baa..530bb3c 100644
--- a/gobject/pygparamspec.c
+++ b/gobject/pygparamspec.c
@@ -156,6 +156,7 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
pyclass = (PyObject*)g_type_get_qdata(G_ENUM_CLASS_TYPE(G_PARAM_SPEC_ENUM(self->pspec)->enum_class), quark);
g_assert(pyclass != NULL);
+ Py_INCREF(pyclass);
return pyclass;
}
} else if (!strcmp(attr, "flags_class")) {
@@ -167,6 +168,7 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
pyclass = (PyObject*)g_type_get_qdata(G_FLAGS_CLASS_TYPE(G_PARAM_SPEC_FLAGS(self->pspec)->flags_class), quark);
g_assert(pyclass != NULL);
+ Py_INCREF(pyclass);
return pyclass;
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d7ef601..6543375 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -7,7 +7,7 @@ PYTHONPATH = $(top_builddir):$(top_builddir)/gobject:$(top_srcdir):$(top_srcdir)
check-local: $(top_srcdir)/gtk/__init__.py
@if ! test -e $(top_builddir)/gtk/__init__.py; then cp $(top_srcdir)/gtk/__init__.py $(top_builddir)/gtk/__init__.py; fi
- @PYTHONPATH=$(PYTHONPATH) $(PYTHON) $(srcdir)/runtests.py
+ @PYTHONPATH=$(PYTHONPATH) DIST_CHECK=1 $(PYTHON) $(srcdir)/runtests.py
@if test "$(top_builddir)" != "$(top_srcdir)"; then rm -f $(top_builddir)/gtk/__init__.py*; fi
@rm -fr *.pyc
diff --git a/tests/common.py b/tests/common.py
index b5eb774..adf4bcc 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -1,3 +1,10 @@
+import os
+import sys
+
+if not os.environ.has_key('DIST_CHECK'):
+ sys.path.insert(0, '..')
+ sys.path.insert(0, '../gobject')
+
import ltihooks
import gobject
diff --git a/tests/enum.py b/tests/enum.py
index ed9b98f..6b4f435 100644
--- a/tests/enum.py
+++ b/tests/enum.py
@@ -28,9 +28,9 @@ class EnumTest(unittest.TestCase):
win.realize()
state = win.window.get_state()
- assert state == gdk.WINDOW_STATE_ICONIFIED
+ assert state == gdk.WINDOW_STATE_WITHDRAWN
assert isinstance(state, gdk.WindowState)
- assert 'WINDOW_STATE_ICONIFIED' in repr(state)
+ assert 'WINDOW_STATE_WITHDRAWN' in repr(state)
def testProperty(self):
win = gtk.Window()
@@ -52,7 +52,11 @@ class EnumTest(unittest.TestCase):
enum = enums[0]
assert hasattr(enum, 'enum_class')
assert issubclass(enum.enum_class, gobject.GEnum)
-
+
+ def testWeirdEnumValues(self):
+ assert int(gdk.NOTHING) == -1
+ assert int(gdk.BUTTON_PRESS) == 4
+
class FlagsTest(unittest.TestCase):
def testFlags(self):
assert issubclass(gobject.GFlags, int)