diff options
author | David Robillard <d@drobilla.net> | 2019-10-19 19:54:03 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-10-19 19:54:13 +0200 |
commit | d959f44bd486b91bf98b689f082713eb795e0be9 (patch) | |
tree | 5dfb3804b30f391898b0159ea19534701d788392 /bindings | |
parent | a4ef0bf8d6afddab9c23d00b4237a96eccd12a32 (diff) | |
download | lilv-d959f44bd486b91bf98b689f082713eb795e0be9.tar.gz lilv-d959f44bd486b91bf98b689f082713eb795e0be9.tar.bz2 lilv-d959f44bd486b91bf98b689f082713eb795e0be9.zip |
Clean up Python test suite
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/test/python/test_api.py | 203 |
1 files changed, 154 insertions, 49 deletions
diff --git a/bindings/test/python/test_api.py b/bindings/test/python/test_api.py index d1f25d1..ab0a1a4 100644 --- a/bindings/test/python/test_api.py +++ b/bindings/test/python/test_api.py @@ -1,4 +1,4 @@ -# Copyright 2016 David Robillard <d@drobilla.net> +# Copyright 2016-2019 David Robillard <d@drobilla.net> # Copyright 2013 Kaspar Emanuel <kaspar.emanuel@gmail.com> # # Permission to use, copy, modify, and/or distribute this software for any @@ -19,20 +19,22 @@ import os location = "file://" + os.getcwd() + "/bindings/bindings_test_plugin.lv2/" + class NodeTests(unittest.TestCase): def setUp(self): self.world = lilv.World() + def testNodes(self): - aint = self.world.new_int(1) - aint2 = self.world.new_int(1) - aint3 = self.world.new_int(3) - afloat = self.world.new_float(2.0) - atrue = self.world.new_bool(True) - afalse = self.world.new_bool(False) - auri = self.world.new_uri("http://example.org") - afile = self.world.new_file_uri(None, "/foo/bar") + aint = self.world.new_int(1) + aint2 = self.world.new_int(1) + aint3 = self.world.new_int(3) + afloat = self.world.new_float(2.0) + atrue = self.world.new_bool(True) + afalse = self.world.new_bool(False) + auri = self.world.new_uri("http://example.org") + afile = self.world.new_file_uri(None, "/foo/bar") astring = self.world.new_string("hello") - self.assertEqual(auri.get_turtle_token(), '<http://example.org>') + self.assertEqual(auri.get_turtle_token(), "<http://example.org>") self.assertTrue(aint.is_int()) self.assertTrue(afloat.is_float()) self.assertTrue(auri.is_uri()) @@ -54,29 +56,38 @@ class NodeTests(unittest.TestCase): with self.assertRaises(ValueError): bool(astring) + class UriTests(unittest.TestCase): def setUp(self): self.world = lilv.World() - self.world.load_all(); + self.world.load_all() + def testInvalidURI(self): self.plugin_uri = self.world.new_uri("invalid_uri") self.assertIsNone(self.plugin_uri) + def testNonExistentURI(self): self.plugin_uri = self.world.new_uri("exist:does_not") self.plugin = self.world.get_all_plugins().get_by_uri(self.plugin_uri) self.assertEqual(self.plugin, None) + def testPortTypes(self): self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_INPUT_PORT)) + def testPortTypes2(self): self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_OUTPUT_PORT)) + def testPortTypes3(self): self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_AUDIO_PORT)) + def testPortTypes4(self): self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_CONTROL_PORT)) + class PluginClassTests(unittest.TestCase): def setUp(self): self.world = lilv.World() + def testPluginClasses(self): pclass = self.world.get_plugin_class() self.assertIsNotNone(pclass) @@ -89,10 +100,12 @@ class PluginClassTests(unittest.TestCase): self.assertIsNotNone(i.get_uri()) self.assertIsNotNone(i.get_label()) + class PluginClassesTests(unittest.TestCase): def setUp(self): self.world = lilv.World() self.world.load_all() + def testPluginClasses(self): classes = self.world.get_plugin_classes() pclass = self.world.get_plugin_class() @@ -104,69 +117,93 @@ class PluginClassesTests(unittest.TestCase): self.assertIsNotNone(classes[0]) self.assertIsNotNone(classes[pclass.get_uri()]) + class LoadTests(unittest.TestCase): def setUp(self): self.world = lilv.World() self.bundle_uri = self.world.new_uri(location) self.world.load_specifications() self.world.load_plugin_classes() + def testLoadUnload(self): self.world.load_bundle(self.bundle_uri) plugins = self.world.get_all_plugins() - plugin = plugins.get(plugins.begin()) + plugin = plugins.get(plugins.begin()) self.world.load_resource(plugin) self.world.unload_resource(plugin) self.world.unload_bundle(self.bundle_uri) + class PluginTests(unittest.TestCase): def setUp(self): self.world = lilv.World() - self.world.set_option(lilv.OPTION_FILTER_LANG, self.world.new_bool(True)) + self.world.set_option( + lilv.OPTION_FILTER_LANG, self.world.new_bool(True) + ) self.bundle_uri = self.world.new_uri(location) self.assertIsNotNone(self.bundle_uri, "Invalid URI: '" + location + "'") self.world.load_bundle(self.bundle_uri) self.plugins = self.world.get_all_plugins() - self.plugin = self.plugins.get(self.plugins.begin()) + self.plugin = self.plugins.get(self.plugins.begin()) self.assertTrue(self.plugin.verify()) self.assertTrue(self.plugin in self.plugins) self.assertTrue(self.plugin.get_uri() in self.plugins) self.assertEqual(self.plugins[self.plugin.get_uri()], self.plugin) - self.assertIsNotNone(self.plugin, msg="Test plugin not found at location: '" + location + "'") + self.assertIsNotNone( + self.plugin, + msg="Test plugin not found at location: '" + location + "'", + ) self.assertEqual(location, str(self.plugin.get_bundle_uri())) self.plugin_uri = self.plugin.get_uri() - self.assertEqual(self.plugin.get_uri(), self.plugin_uri, "URI equality broken") + self.assertEqual( + self.plugin.get_uri(), self.plugin_uri, "URI equality broken" + ) self.instance = lilv.Instance(self.plugin, 48000, None) self.assertIsNotNone(self.instance) - self.lv2_InputPort = self.world.new_uri(lilv.LILV_URI_INPUT_PORT) - self.lv2_OutputPort = self.world.new_uri(lilv.LILV_URI_OUTPUT_PORT) - self.lv2_AudioPort = self.world.new_uri(lilv.LILV_URI_AUDIO_PORT) - self.lv2_ControlPort = self.world.new_uri(lilv.LILV_URI_CONTROL_PORT) + self.lv2_InputPort = self.world.new_uri(lilv.LILV_URI_INPUT_PORT) + self.lv2_OutputPort = self.world.new_uri(lilv.LILV_URI_OUTPUT_PORT) + self.lv2_AudioPort = self.world.new_uri(lilv.LILV_URI_AUDIO_PORT) + self.lv2_ControlPort = self.world.new_uri(lilv.LILV_URI_CONTROL_PORT) + def testGetters(self): self.assertIsNotNone(self.plugin.get_bundle_uri()) self.assertGreater(len(self.plugin.get_data_uris()), 0) self.assertIsNotNone(self.plugin.get_library_uri()) self.assertTrue(self.plugin.get_name().is_string()) self.assertTrue(self.plugin.get_class().get_uri().is_uri()) - self.assertEqual(len(self.plugin.get_value(self.world.ns.doap.license)), 1) + self.assertEqual( + len(self.plugin.get_value(self.world.ns.doap.license)), 1 + ) licenses = self.plugin.get_value(self.world.ns.doap.license) features = self.plugin.get_value(self.world.ns.lv2.optionalFeature) self.assertEqual(len(licenses), 1) self.assertTrue(licenses[0] in licenses) with self.assertRaises(IndexError): self.assertIsNone(licenses[len(licenses)]) - self.assertEqual(len(licenses) + len(features), - len(licenses.merge(features))) - self.assertEqual(licenses.get(licenses.begin()), self.world.new_uri('http://opensource.org/licenses/isc')) + self.assertEqual( + len(licenses) + len(features), len(licenses.merge(features)) + ) + self.assertEqual( + licenses.get(licenses.begin()), + self.world.new_uri("http://opensource.org/licenses/isc"), + ) self.assertEqual(licenses[0], licenses.get(licenses.begin())) - self.assertTrue(self.plugin.has_feature(self.world.ns.lv2.hardRTCapable)) + self.assertTrue( + self.plugin.has_feature(self.world.ns.lv2.hardRTCapable) + ) self.assertEqual(len(self.plugin.get_supported_features()), 1) self.assertEqual(len(self.plugin.get_optional_features()), 1) self.assertEqual(len(self.plugin.get_required_features()), 0) - self.assertFalse(self.plugin.has_extension_data(self.world.new_uri('http://example.org/nope'))) + self.assertFalse( + self.plugin.has_extension_data( + self.world.new_uri("http://example.org/nope") + ) + ) self.assertEqual(len(self.plugin.get_extension_data()), 0) self.assertEqual(len(self.plugin.get_extension_data()), 0) self.assertFalse(self.plugin.has_latency()) self.assertIsNone(self.plugin.get_latency_port_index()) + def testPorts(self): self.assertEqual(self.plugin.get_num_ports(), 4) self.assertIsNotNone(self.plugin.get_port(0)) @@ -179,14 +216,30 @@ class PluginTests(unittest.TestCase): self.assertIsNotNone(self.plugin.get_port("audio_input")) self.assertIsNotNone(self.plugin.get_port("audio_output")) self.assertIsNone(self.plugin.get_port_by_symbol("nonexistent")) - self.assertIsNone(self.plugin.get_port_by_designation(self.world.ns.lv2.InputPort, self.world.ns.lv2.control)) + self.assertIsNone( + self.plugin.get_port_by_designation( + self.world.ns.lv2.InputPort, self.world.ns.lv2.control + ) + ) self.assertIsNone(self.plugin.get_project()) self.assertIsNone(self.plugin.get_author_name()) self.assertIsNone(self.plugin.get_author_email()) self.assertIsNone(self.plugin.get_author_homepage()) self.assertFalse(self.plugin.is_replaced()) - self.assertEqual(0, len(self.plugin.get_related(self.world.new_uri("http://example.org/Type")))) - self.assertEqual(1, self.plugin.get_num_ports_of_class(self.lv2_InputPort, self.lv2_AudioPort)) + self.assertEqual( + 0, + len( + self.plugin.get_related( + self.world.new_uri("http://example.org/Type") + ) + ), + ) + self.assertEqual( + 1, + self.plugin.get_num_ports_of_class( + self.lv2_InputPort, self.lv2_AudioPort + ), + ) port = self.plugin.get_port("input") self.assertTrue(port.get_node().is_blank()) self.assertEqual(0, port.get(self.world.ns.lv2.index)) @@ -197,12 +250,15 @@ class PluginTests(unittest.TestCase): self.assertEqual(0, port.get_index()) self.assertEqual("input", port.get_symbol()) self.assertEqual("Input", port.get_name()) - self.assertEqual([self.world.ns.lv2.ControlPort, self.world.ns.lv2.InputPort], - list(port.get_classes())) + self.assertEqual( + [self.world.ns.lv2.ControlPort, self.world.ns.lv2.InputPort], + list(port.get_classes()), + ) self.assertTrue(port.is_a(self.world.ns.lv2.ControlPort)) self.assertFalse(port.is_a(self.world.ns.lv2.AudioPort)) self.assertEqual((0.5, 0.0, 1.0), port.get_range()) self.assertEqual(0, len(port.get_properties())) + def testScalePoints(self): port = self.plugin.get_port("input") points = port.get_scale_points() @@ -210,11 +266,33 @@ class PluginTests(unittest.TestCase): self.assertEqual(points[0].get_value(), 0.0) self.assertEqual(points[1].get_label(), "on") self.assertEqual(points[1].get_value(), 1.0) + def testPortCount(self): - self.assertEqual(1, self.plugin.get_num_ports_of_class(self.lv2_OutputPort, self.lv2_AudioPort)) - self.assertEqual(1, self.plugin.get_num_ports_of_class(self.lv2_OutputPort, self.lv2_ControlPort)) - self.assertEqual(1, self.plugin.get_num_ports_of_class(self.lv2_InputPort, self.lv2_AudioPort)) - self.assertEqual(1, self.plugin.get_num_ports_of_class(self.lv2_InputPort, self.lv2_ControlPort)) + self.assertEqual( + 1, + self.plugin.get_num_ports_of_class( + self.lv2_OutputPort, self.lv2_AudioPort + ), + ) + self.assertEqual( + 1, + self.plugin.get_num_ports_of_class( + self.lv2_OutputPort, self.lv2_ControlPort + ), + ) + self.assertEqual( + 1, + self.plugin.get_num_ports_of_class( + self.lv2_InputPort, self.lv2_AudioPort + ), + ) + self.assertEqual( + 1, + self.plugin.get_num_ports_of_class( + self.lv2_InputPort, self.lv2_ControlPort + ), + ) + class QueryTests(unittest.TestCase): def setUp(self): @@ -223,20 +301,35 @@ class QueryTests(unittest.TestCase): self.bundle_uri = self.world.new_uri(location) self.world.load_bundle(self.bundle_uri) self.plugins = self.world.get_all_plugins() - self.plugin = self.plugins.get(self.plugins.begin()) + self.plugin = self.plugins.get(self.plugins.begin()) + def testNamespaces(self): self.assertEqual(self.world.ns.lv2, "http://lv2plug.in/ns/lv2core#") - self.assertEqual(self.world.ns.lv2.Plugin, "http://lv2plug.in/ns/lv2core#Plugin") + self.assertEqual( + self.world.ns.lv2.Plugin, "http://lv2plug.in/ns/lv2core#Plugin" + ) + def testQuery(self): - self.assertTrue(self.world.ask(None, - self.world.ns.rdf.type, - self.world.ns.lv2.Plugin)) - self.assertLess(0, len(self.world.find_nodes(None, - self.world.ns.rdf.type, - self.world.ns.lv2.Plugin))) - self.assertEqual(self.plugin.get_uri(), self.world.get(None, - self.world.ns.rdf.type, - self.world.ns.lv2.Plugin)) + self.assertTrue( + self.world.ask( + None, self.world.ns.rdf.type, self.world.ns.lv2.Plugin + ) + ) + self.assertLess( + 0, + len( + self.world.find_nodes( + None, self.world.ns.rdf.type, self.world.ns.lv2.Plugin + ) + ), + ) + self.assertEqual( + self.plugin.get_uri(), + self.world.get( + None, self.world.ns.rdf.type, self.world.ns.lv2.Plugin + ), + ) + class InstanceTests(unittest.TestCase): def setUp(self): @@ -247,10 +340,18 @@ class InstanceTests(unittest.TestCase): self.plugin = self.plugins[0] self.instance = lilv.Instance(self.plugin, 48000) self.assertEqual(self.plugin.get_uri(), self.instance.get_uri()) - self.assertIsNone(self.instance.get_extension_data(self.world.new_uri("http://example.org/ext"))) - self.assertIsNone(self.instance.get_extension_data("http://example.org/ext")) + self.assertIsNone( + self.instance.get_extension_data( + self.world.new_uri("http://example.org/ext") + ) + ) + self.assertIsNone( + self.instance.get_extension_data("http://example.org/ext") + ) + def testRun(self): import numpy + n_samples = 100 buf = numpy.zeros(n_samples) with self.assertRaises(Exception): @@ -263,6 +364,7 @@ class InstanceTests(unittest.TestCase): self.instance.run(n_samples) self.instance.deactivate() + class UITests(unittest.TestCase): def setUp(self): self.world = lilv.World() @@ -270,9 +372,12 @@ class UITests(unittest.TestCase): self.world.load_bundle(self.bundle_uri) self.plugins = self.world.get_all_plugins() self.plugin = self.plugins[0] + def testUI(self): uis = self.plugin.get_uis() - ui_uri = self.world.new_uri('http://example.org/lilv-bindings-test-plugin-ui') + ui_uri = self.world.new_uri( + "http://example.org/lilv-bindings-test-plugin-ui" + ) self.assertEqual(1, len(uis)) self.assertEqual(str(uis[0]), str(ui_uri)) self.assertEqual(uis[0], str(ui_uri)) |