diff options
author | Simón Pena <spenap@gmail.com> | 2010-09-29 16:30:59 +0200 |
---|---|---|
committer | Víctor Manuel Jáquez Leal <vjaquez@igalia.com> | 2010-09-30 17:21:23 +0200 |
commit | 648523c697474051ab88091dbff23041427ceaa2 (patch) | |
tree | 0d6a9d4ab72f5e945ef6b1540e500fdd5b1c3caf /tests | |
parent | 585dfd314058877afe265eb103894c4bff95047e (diff) | |
download | grilo-648523c697474051ab88091dbff23041427ceaa2.tar.gz |
tests: Tested the PluginRegistry class using GI
This patch tests the class' methods from Python using
GObject Introspection, checking functionality and bindings
at the same time.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/python/Makefile.am | 3 | ||||
-rw-r--r-- | tests/python/constants.py | 50 | ||||
-rw-r--r-- | tests/python/test_registry.py | 158 |
3 files changed, 210 insertions, 1 deletions
diff --git a/tests/python/Makefile.am b/tests/python/Makefile.am index b4c053a..b615834 100644 --- a/tests/python/Makefile.am +++ b/tests/python/Makefile.am @@ -10,7 +10,8 @@ endif if HAVE_INTROSPECTION EXTRA_DIST = \ - testrunner.py + testrunner.py \ + test_registry.py endif .PHONY: test test-report perf-report full-report diff --git a/tests/python/constants.py b/tests/python/constants.py new file mode 100644 index 0000000..e8e2690 --- /dev/null +++ b/tests/python/constants.py @@ -0,0 +1,50 @@ +KEY_NONEXISTING = 'nonexisting-key' +KEY_ALBUM = 'album' +KEY_ARTIST = 'artist' +KEY_AUTHOR = 'author' +KEY_BITRATE = 'bitrate' +KEY_CERTIFICATE = 'certificate' +KEY_CHILDCOUNT = 'childcount' +KEY_DATE = 'date' +KEY_DESCRIPTION = 'description' +KEY_DURATION = 'duration' +KEY_EXTERNAL_PLAYER = 'external-player' +KEY_EXTERNAL_URL = 'external-url' +KEY_FRAMERATE = 'framerate' +KEY_GENRE = 'genre' +KEY_HEIGHT = 'height' +KEY_ID = 'id' +KEY_LAST_PLAYED = 'last-played' +KEY_LAST_POSITION = 'last-position' +KEY_LICENSE = 'license' +KEY_LYRICS = 'lyrics' +KEY_MIME = 'mime' +KEY_PLAY_COUNT = 'play-count' +KEY_RATING = 'rating' +KEY_SITE = 'site' +KEY_SOURCE = 'source' +KEY_STUDIO = 'studio' +KEY_THUMBNAIL = 'thumbnail' +KEY_TITLE = 'title' +KEY_URL = 'url' +KEY_WIDTH = 'width' + +REGISTERED_KEYS = [KEY_ALBUM, KEY_ARTIST, KEY_AUTHOR, KEY_BITRATE, + KEY_CERTIFICATE, KEY_CHILDCOUNT, KEY_DATE, + KEY_DESCRIPTION, KEY_DURATION, KEY_EXTERNAL_PLAYER, + KEY_EXTERNAL_URL, KEY_FRAMERATE, KEY_GENRE, KEY_HEIGHT, + KEY_ID, KEY_LAST_PLAYED, KEY_LAST_POSITION, KEY_LICENSE, + KEY_LYRICS, KEY_MIME, KEY_PLAY_COUNT, KEY_RATING, + KEY_SITE, KEY_SOURCE, KEY_STUDIO, KEY_THUMBNAIL, + KEY_TITLE, KEY_URL, KEY_WIDTH] + +SUPPORTED_OPS = [] +try: + from gi.repository import Grl + SUPPORTED_OPS = [Grl.SupportedOps.NONE, Grl.SupportedOps.METADATA, + Grl.SupportedOps.RESOLVE, Grl.SupportedOps.BROWSE, + Grl.SupportedOps.SEARCH, Grl.SupportedOps.QUERY, + Grl.SupportedOps.STORE, Grl.SupportedOps.STORE_PARENT, + Grl.SupportedOps.REMOVE, Grl.SupportedOps.SET_METADATA] +except: + pass diff --git a/tests/python/test_registry.py b/tests/python/test_registry.py new file mode 100644 index 0000000..b7b85c1 --- /dev/null +++ b/tests/python/test_registry.py @@ -0,0 +1,158 @@ +import unittest +import os +import util +import tempfile +import logging +import constants + +try: + from gi.repository import Grl +except: + logging.warning("Unable to import Grilo's introspection bindings") + exit() + +class TestPluginRegistry(unittest.TestCase): + + EXISTING_LIBRARY_PATH = None + + NONEXISTING_LIBRARY_PATH = 'NONEXISTING_LIBRARY.so' + + INVALID_LIBRARY_PATH = os.path.join(util.PREFIX, + util.GRL_LIB_NAME) + + NONEXISTING_SOURCE = 'NON_EXISTING_SOURCE' + + def setUp(self): + Grl.init([]) + self.registry = Grl.PluginRegistry.get_default() + plugin_dir = os.listdir(util.GRL_PLUGIN_PATH) + if plugin_dir: + self.EXISTING_LIBRARY_PATH = os.path.join(util.GRL_PLUGIN_PATH, + plugin_dir[0]) + + def tearDown(self): + for source in self.registry.get_sources(False): + self.registry.unload(source.get_id()) + self.registry.unregister_source(source) + + def test_get_default_not_null(self): + registry = Grl.PluginRegistry.get_default() + self.assertTrue(registry) + + def test_get_default_singleton(self): + registry1 = Grl.PluginRegistry.get_default() + registry2 = Grl.PluginRegistry.get_default() + self.assertEquals(registry1, registry2) + + def test_add_directory(self): + pass + + def test_load_existing(self): + if not self.registry.load(self.EXISTING_LIBRARY_PATH): + self.fail() + + def test_load_unexisting(self): + if self.registry.load(self.NONEXISTING_LIBRARY_PATH): + self.fail() + + def test_load_invalid(self): + if self.registry.load(self.INVALID_LIBRARY_PATH): + self.fail() + + def test_load_directory_nonexisting(self): + if self.registry.load_directory(''): + self.fail() + + def test_load_directory_existing(self): + if not self.registry.load_directory(os.getcwd()): + self.fail() + + def test_unload(self): + pass + + def test_load_all(self): + self.assertTrue(self.registry.load_all()) + + def test_register_source(self): + pass + + def test_unregister_source(self): + self.registry.load_all() + sources = self.registry.get_sources(False) + for source in sources: + self.registry.unregister_source(source) + sources = self.registry.get_sources(False) + self.assertEqual(len(sources), 0) + + def test_lookup_source(self): + self.registry.load_all() + sources = self.registry.get_sources(False) + + if sources: + expected = sources[0] + search_id = expected.get_id() + found = self.registry.lookup_source(search_id) + + self.assertEqual(expected, found) + + def test_lookup_source_nonexisting(self): + self.registry.load_all() + found = self.registry.lookup_source(self.NONEXISTING_SOURCE) + self.assertFalse(found) + + def test_get_sources(self): + sources = self.registry.get_sources(False) + self.assertEqual(len(sources), 0) + + self.registry.load_all() + sources = self.registry.get_sources(False) + self.assertNotEqual(len(sources), 0) + + def test_get_sources_ordering(self): + self.registry.load_all() + ordered_sources = self.registry.get_sources(True) + unordered_sources = self.registry.get_sources(False) + + unordered_sources.sort(key=Grl.MediaPlugin.get_rank) + self.assertEquals(ordered_sources, unordered_sources) + + def test_get_sources_by_operations_supported_ops(self): + self.registry.load_all() + for op in constants.SUPPORTED_OPS: + if op != Grl.SupportedOps.NONE: + sources = self.registry.get_sources_by_operations(op, False) + if sources: + supported_operations = sources[0].supported_operations() + self.assertTrue(supported_operations & op) + + def test_register_metadata_key(self): + pass + + def test_lookup_metadata_key_existing_key(self): + existing_key = self.registry.lookup_metadata_key(constants.KEY_ID) + self.assertTrue(existing_key) + + def test_lookup_metadata_key_nonexisting_key(self): + nonexisting_key = self.registry.lookup_metadata_key(constants.KEY_NONEXISTING) + self.assertTrue(nonexisting_key is None) + + def test_lookup_metadata_key_singleton(self): + a_key = self.registry.lookup_metadata_key(constants.KEY_ID) + another_key = self.registry.lookup_metadata_key(constants.KEY_ID) + self.assertEquals(a_key, another_key) + + def test_get_metadata_keys_contains(self): + registered_key = self.registry.lookup_metadata_key(constants.KEY_ARTIST) + metadata_keys = self.registry.get_metadata_keys() + self.assertTrue(registered_key in metadata_keys) + + def test_get_metadata_keys_all_keys(self): + registered_keys = [] + for k in constants.REGISTERED_KEYS: + registered_keys.append(self.registry.lookup_metadata_key(k)) + + metadata_keys = self.registry.get_metadata_keys() + self.assertEquals(registered_keys.sort(), metadata_keys.sort()) + + def test_add_config(self): + pass |