From c202b6be43ab8ce4e53f61600e72c9af4443e8df Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 23 May 2007 09:55:21 +0000 Subject: Import xdgmime and start hooking it up --- (limited to 'tests') diff --git a/tests/test-browser.py b/tests/test-browser.py deleted file mode 100755 index ce9a3cf..0000000 --- a/tests/test-browser.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2006, Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import os - -import pygtk -pygtk.require('2.0') -import gtk -import gobject - -import sugar.browser - -def _print_document(): - #print browser.document - pass - -def _quit(window): - sugar.browser.shutdown() - gtk.main_quit() - -# Main window -window = gtk.Window() -window.connect("destroy", _quit) - -sugar.browser.startup(os.path.expanduser('~/.sugar-browser-test'), 'test') - -browser = sugar.browser.Browser() -window.add(browser) -browser.show() - -browser.load_url('about:blank') - -gobject.idle_add(_print_document) - -window.show() - -gtk.main() diff --git a/tests/test-datastore.py b/tests/test-datastore.py deleted file mode 100755 index d3e8478..0000000 --- a/tests/test-datastore.py +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2006, Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import unittest -from sugar.datastore import datastore -from sugar import util -import dbus - -class NotFoundError(dbus.DBusException): pass - -_ds = datastore.get_instance() - -class DataStoreTestCase(unittest.TestCase): - _TEST_DATA = "adsfkjadsfadskjasdkjf" - _TEST_PROPS = {'foo': 1, 'bar': 'baz'} - def _create_test_object(self, activity_id=None): - obj = _ds.create(self._TEST_DATA, self._TEST_PROPS, activity_id=activity_id) - self.assert_(obj) - return obj - - def testObjectCreate(self): - obj = self._create_test_object() - self.assert_(obj.uid()) - _ds.delete(obj) - - def testObjectCreateWithActivityId(self): - # Try known good create - act_id = util.unique_id('afdkjakjddasf') - obj = self._create_test_object(act_id) - self.assert_(obj.uid()) - _ds.delete(obj) - - def testObjectCreateWithBadActivityId(self): - # try malformed activity id - try: - uid = self._create_test_object("adfadf") - except ValueError: - pass - else: - self.fail("Expected ValueError") - - def testObjectGetActivityObject(self): - # create a new object - act_id = util.unique_id('afdkjakjddasf') - obj = self._create_test_object(act_id) - self.assert_(obj.uid()) - obj2 = _ds.get(activity_id=act_id) - self.assert_(obj2) - _ds.delete(obj) - - def testObjectGet(self): - # create a new object - obj = self._create_test_object() - self.assert_(obj.uid()) - obj2 = _ds.get(obj.uid()) - self.assert_(obj2) - _ds.delete(obj) - - def testObjectDelete(self): - obj = self._create_test_object() - uid = obj.uid() - _ds.delete(obj) - try: - _ds.get(uid) - except dbus.DBusException, e: - if str(e).find("NotFoundError:") < 0: - self.fail("Expected a NotFoundError") - else: - self.fail("Expected a NotFoundError.") - - def testObjectFind(self): - obj = self._create_test_object() - found = _ds.find(self._TEST_PROPS) - self.assert_(obj in found) - _ds.delete(obj) - - def testObjectGetData(self): - obj = self._create_test_object() - data = obj.get_data() - self.assert_(data == self._TEST_DATA) - _ds.delete(obj) - - _OTHER_DATA = "532532532532532;lkjkjkjfsakjfakjfdsakj" - def testObjectSetData(self): - obj = self._create_test_object() - data = obj.get_data() - self.assert_(data == self._TEST_DATA) - obj.set_data(self._OTHER_DATA) - data = obj.get_data() - self.assert_(data == self._OTHER_DATA) - _ds.delete(obj) - - def testObjectGetProperties(self): - obj = self._create_test_object() - props = obj.get_properties() - for (key, value) in props.items(): - if key == 'uid': - continue - self.assert_(key in self._TEST_PROPS) - self.assert_(str(self._TEST_PROPS[key]) == str(value)) - for (key, value) in self._TEST_PROPS.items(): - self.assert_(key in props) - self.assert_(str(props[key]) == str(value)) - _ds.delete(obj) - -def main(): - dsTestSuite = unittest.TestSuite() - dsTestSuite.addTest(DataStoreTestCase('testObjectCreate')) - dsTestSuite.addTest(DataStoreTestCase('testObjectCreateWithActivityId')) - dsTestSuite.addTest(DataStoreTestCase('testObjectCreateWithBadActivityId')) - dsTestSuite.addTest(DataStoreTestCase('testObjectGet')) - dsTestSuite.addTest(DataStoreTestCase('testObjectGetActivityObject')) - dsTestSuite.addTest(DataStoreTestCase('testObjectDelete')) - dsTestSuite.addTest(DataStoreTestCase('testObjectFind')) - dsTestSuite.addTest(DataStoreTestCase('testObjectGetData')) - dsTestSuite.addTest(DataStoreTestCase('testObjectSetData')) - dsTestSuite.addTest(DataStoreTestCase('testObjectGetProperties')) - unittest.TextTestRunner(verbosity=2).run(dsTestSuite) - - -if __name__ == "__main__": - main() diff --git a/tests/test-datastore2.py b/tests/test-datastore2.py deleted file mode 100755 index e874758..0000000 --- a/tests/test-datastore2.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2006, One Laptop Per Child -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from sugar.datastore import datastore -from sugar.datastore.datastore import Text - -# Write a text object -metadata = { 'date' : 1000900000, - 'title' : 'Thai history', - 'preview' : 'The subject of thai history...', - 'icon-color' : '#C2B00C,#785C78', - } -text = Text(metadata) -f = open("/tmp/hello.txt", 'w') -try: - f.write('The subject of thai history blah blah blah, blah blah blah and blah.') -finally: - f.close() -text.set_file_path(f.name) -handle = datastore.write(text) - -# Read back that object -thing = datastore.read(handle) -metadata = thing.get_metadata() -print metadata - -file_path = thing.get_file_path() -f = open(file_path) -try: - print f.read() -finally: - f.close() - -# Retrieve all the objects -objects = datastore.find('') -for obj in objects: - print obj.get_metadata()['title'] diff --git a/tests/test-mime.py b/tests/test-mime.py new file mode 100755 index 0000000..8ecd613 --- /dev/null +++ b/tests/test-mime.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +# Copyright (C) 2006, Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +from sugar import objects + +print objects.mime.get_from_filename('test.pdf') -- cgit v0.9.1