pygobject r772 - in trunk: . gio tests



Author: johan
Date: Tue Apr  8 21:50:46 2008
New Revision: 772
URL: http://svn.gnome.org/viewvc/pygobject?rev=772&view=rev

Log:
2008-04-08  Johan Dahlin  <jdahlin async com br>

    * gio/Makefile.am:
    * gio/__init__.py:
    * gio/gappinfo.override:
    * gio/gio.defs:
    * gio/gio.override:
    * tests/test_gio.py:
    Implement GAppInfo constructor, add tests.



Added:
   trunk/gio/gappinfo.override
Modified:
   trunk/ChangeLog
   trunk/gio/Makefile.am
   trunk/gio/__init__.py
   trunk/gio/gio.defs
   trunk/gio/gio.override
   trunk/tests/test_gio.py

Modified: trunk/gio/Makefile.am
==============================================================================
--- trunk/gio/Makefile.am	(original)
+++ trunk/gio/Makefile.am	Tue Apr  8 21:50:46 2008
@@ -34,6 +34,7 @@
 
 # gio module
 GIO_OVERRIDES = 			\
+	gappinfo.override		\
 	gio.override			\
 	gfile.override			\
 	gfileenumerator.override	\

Modified: trunk/gio/__init__.py
==============================================================================
--- trunk/gio/__init__.py	(original)
+++ trunk/gio/__init__.py	Tue Apr  8 21:50:46 2008
@@ -1,4 +1,4 @@
-# -*- Mode: Python; py-indent-offset: 4 -*-
+# -*- Mode: Python -*-
 # pygobject - Python bindings for the GObject library
 # Copyright (C) 2008  Johan Dahlin
 #
@@ -29,7 +29,9 @@
 
 from gobject import GObjectMeta
 from _gio import *
-from _gio import _file_init, _install_file_meta
+from _gio import \
+     _app_info_init, _install_app_info_meta, \
+     _file_init, _install_file_meta
 try:
     import unix
     unix # pyflakes
@@ -39,5 +41,8 @@
 
 class GFileMeta(GObjectMeta):
     __call__ = _file_init
-
 _install_file_meta(GFileMeta)
+
+class GAppInfoMeta(GObjectMeta):
+    __call__ = _app_info_init
+_install_app_info_meta(GAppInfoMeta)

Added: trunk/gio/gappinfo.override
==============================================================================
--- (empty file)
+++ trunk/gio/gappinfo.override	Tue Apr  8 21:50:46 2008
@@ -0,0 +1,70 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygobject - Python bindings for GObject
+ * Copyright (C) 2008  Johan Dahlin
+ *
+ *   gappinfo.override: module overrides for GInputStream
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+%%
+define _install_app_info_meta
+static PyObject *
+_wrap__install_app_info_meta(PyObject *self, PyObject *args)
+{
+    PyObject *metaclass;
+
+    if (!PyArg_ParseTuple(args, "O", &metaclass))
+	return NULL;
+
+    Py_INCREF(metaclass);
+    PyGAppInfo_Type.ob_type = (PyTypeObject*)metaclass;
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+%%
+define _app_info_init kwargs
+static PyObject *
+_wrap__app_info_init(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = { "commandline", "application_name",
+			      "flags", NULL };
+    char *commandline, *application_name = NULL;
+    PyObject *py_flags = NULL;
+    GAppInfo *ret;
+    GError *error = NULL;
+    GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, 
+				     "s|zO:gio.AppInfo",
+				     kwlist,
+				     &commandline, &application_name,
+				     &py_flags))
+        return NULL;
+    if (py_flags && pyg_flags_get_value(G_TYPE_APP_INFO_CREATE_FLAGS,
+					py_flags, (gpointer)&flags))
+        return NULL;
+    
+    ret = g_app_info_create_from_commandline(commandline,
+					     application_name, flags, &error);
+    
+    if (pyg_error_check(&error))
+        return NULL;
+
+    /* pygobject_new handles NULL checking */
+    return pygobject_new((GObject *)ret);
+}
+    

Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs	(original)
+++ trunk/gio/gio.defs	Tue Apr  8 21:50:46 2008
@@ -15,11 +15,12 @@
 
 (define-function app_info_create_from_commandline
   (c-name "g_app_info_create_from_commandline")
+  (is-constructor-of "GAppInfo")
   (return-type "GAppInfo*")
   (parameters
     '("const-char*" "commandline")
-    '("const-char*" "application_name")
-    '("GAppInfoCreateFlags" "flags")
+    '("const-char*" "application_name" (null-ok) (default "NULL"))
+    '("GAppInfoCreateFlags" "flags" (default "G_APP_INFO_CREATE_NONE"))
     '("GError**" "error")
   )
 )
@@ -1095,6 +1096,7 @@
 
 (define-function file_new_for_path
   (c-name "g_file_new_for_path")
+  (is-constructor-of "GFile")
   (return-type "GFile*")
   (parameters
     '("const-char*" "path")
@@ -1103,6 +1105,7 @@
 
 (define-function file_new_for_uri
   (c-name "g_file_new_for_uri")
+  (is-constructor-of "GFile")
   (return-type "GFile*")
   (parameters
     '("const-char*" "uri")
@@ -1110,6 +1113,7 @@
 )
 
 (define-function file_new_for_commandline_arg
+  (is-constructor-of "GFile")
   (c-name "g_file_new_for_commandline_arg")
   (return-type "GFile*")
   (parameters

Modified: trunk/gio/gio.override
==============================================================================
--- trunk/gio/gio.override	(original)
+++ trunk/gio/gio.override	Tue Apr  8 21:50:46 2008
@@ -78,6 +78,7 @@
 }
 %%
 include
+  gappinfo.override
   gfile.override
   gfileenumerator.override
   gfileinfo.override

Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py	(original)
+++ trunk/tests/test_gio.py	Tue Apr  8 21:50:46 2008
@@ -9,7 +9,7 @@
 class TestFile(unittest.TestCase):
     def setUp(self):
         self._f = open("file.txt", "w+")
-        self.file = gio.file_new_for_path("file.txt")
+        self.file = gio.File("file.txt")
 
     def tearDown(self):
         self._f.close()
@@ -54,7 +54,7 @@
 
 class TestGFileEnumerator(unittest.TestCase):
     def setUp(self):
-        self.file = gio.file_new_for_path(".")
+        self.file = gio.File(".")
 
     def testEnumerateChildren(self):
         enumerator = self.file.enumerate_children(
@@ -186,6 +186,7 @@
         loop = gobject.MainLoop()
         loop.run()
 
+
 class TestVolumeMonitor(unittest.TestCase):
     def setUp(self):
         self.monitor = gio.volume_monitor_get()
@@ -215,16 +216,17 @@
         self.icon.append_name('close')
         self.assertEquals(self.icon.get_names(), ['open', 'close'])
 
-class TestType(unittest.TestCase):
-    def testGuessFromName(self):
+
+class TestContentTypeGuess(unittest.TestCase):
+    def testFromName(self):
         mime_type = gio.content_type_guess('diagram.svg')
         self.assertEquals('image/svg+xml', mime_type)
 
-    def testGuessFromContents(self):
+    def testFromContents(self):
         mime_type = gio.content_type_guess(data='<html></html>')
         self.assertEquals('text/html', mime_type)
 
-    def testGuessFromContentsUncertain(self):
+    def testFromContentsUncertain(self):
         mime_type, result_uncertain = gio.content_type_guess(
             data='<html></html>', want_uncertain=True)
         self.assertEquals('text/html', mime_type)
@@ -233,8 +235,16 @@
 
 class TestFileInfo(unittest.TestCase):
     def testListAttributes(self):
-        gfile = gio.File("test_gio.py")
-        fileinfo = gfile.query_info("*")
+        fileinfo = gio.File("test_gio.py").query_info("*")
         attributes = fileinfo.list_attributes("standard")
         self.failUnless(attributes)
         self.failUnless('standard::name' in attributes)
+
+
+class TestAppInfo(unittest.TestCase):
+    def setUp(self):
+        self.appinfo = gio.AppInfo("does-not-exist")
+
+    def testSimple(self):
+        self.assertEquals(self.appinfo.get_description(),
+                          "Custom definition for (null)")



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]