summaryrefslogtreecommitdiffstats
path: root/bindings/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-09-05 02:23:25 -0400
committerDavid Robillard <d@drobilla.net>2016-09-05 02:23:25 -0400
commitc9a93f83de23c657e40b5f689c9faaa3b3c8828d (patch)
treed82e18e54f04e94fc07f9bfdaf32b8fd71cd6c9d /bindings/test
parent5be277f5d9d2bbfa58028fb7522da4781450d6c4 (diff)
downloadlilv-c9a93f83de23c657e40b5f689c9faaa3b3c8828d.tar.gz
lilv-c9a93f83de23c657e40b5f689c9faaa3b3c8828d.tar.bz2
lilv-c9a93f83de23c657e40b5f689c9faaa3b3c8828d.zip
Add new hand-crafted Python bindings
New bindings are Pythonic, supporting iteration, DWIM type conversion, pretty printing, and so on, where possible. Updated test suite covers 100% of binding code. Which is to say: add real Python bindings. As far as the Lilv API itself is concerned, you can do everything via Python. However, more work is needed to make fancy wrappers for parts of LV2 itself (MIDI, URI map, etc) to be able to run advanced plugins.
Diffstat (limited to 'bindings/test')
-rw-r--r--bindings/test/bindings_test_plugin.ttl.in15
-rw-r--r--bindings/test/python/test_api.py310
2 files changed, 272 insertions, 53 deletions
diff --git a/bindings/test/bindings_test_plugin.ttl.in b/bindings/test/bindings_test_plugin.ttl.in
index a703432..e8323d5 100644
--- a/bindings/test/bindings_test_plugin.ttl.in
+++ b/bindings/test/bindings_test_plugin.ttl.in
@@ -16,18 +16,27 @@
@prefix doap: <http://usefulinc.com/ns/doap#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix lv2: <http://lv2plug.in/ns/lv2core#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .
<http://example.org/lilv-bindings-test-plugin>
a lv2:Plugin ;
doap:name "Lilv Bindings Test" ;
doap:license <http://opensource.org/licenses/isc> ;
+ lv2:optionalFeature lv2:hardRTCapable ;
+ ui:ui <http://example.org/lilv-bindings-test-plugin-ui> ;
lv2:port [
a lv2:InputPort ,
lv2:ControlPort ;
lv2:index 0 ;
lv2:symbol "input" ;
- lv2:name "Input"
+ lv2:name "Input" ;
+ lv2:default 0.5 ;
+ lv2:minimum 0.0 ;
+ lv2:maximum 1.0 ;
+ lv2:scalePoint [ rdfs:label "off" ; rdf:value 0.0 ] ;
+ lv2:scalePoint [ rdfs:label "on" ; rdf:value 1.0 ] ;
] , [
a lv2:OutputPort ,
lv2:ControlPort ;
@@ -47,3 +56,7 @@
lv2:symbol "audio_output" ;
lv2:name "Audio Output" ;
] .
+
+<http://example.org/lilv-bindings-test-plugin-ui>
+ a ui:GtkUI ;
+ ui:binary <TODO> .
diff --git a/bindings/test/python/test_api.py b/bindings/test/python/test_api.py
index 655abba..f594013 100644
--- a/bindings/test/python/test_api.py
+++ b/bindings/test/python/test_api.py
@@ -1,3 +1,4 @@
+# Copyright 2016 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
@@ -12,73 +13,278 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-from lilv import *
+import lilv
import unittest
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")
+ astring = self.world.new_string("hello")
+ self.assertEqual(auri.get_turtle_token(), '<http://example.org>')
+ self.assertTrue(aint.is_int())
+ self.assertTrue(afloat.is_float())
+ self.assertTrue(auri.is_uri())
+ self.assertTrue(astring.is_string())
+ self.assertTrue(astring.is_literal())
+ self.assertFalse(auri.is_blank())
+ self.assertTrue(int(aint) == 1)
+ self.assertTrue(float(afloat) == 2.0)
+ self.assertTrue(bool(atrue))
+ self.assertFalse(bool(afalse))
+ self.assertEqual(afile.get_path(), "/foo/bar")
+ self.assertTrue(aint == aint2)
+ self.assertTrue(aint != aint3)
+ self.assertTrue(aint != afloat)
+ with self.assertRaises(ValueError):
+ int(atrue)
+ with self.assertRaises(ValueError):
+ float(aint)
+ with self.assertRaises(ValueError):
+ bool(astring)
+
class UriTests(unittest.TestCase):
def setUp(self):
- self.world = lilv_world_new()
- lilv_world_load_all(self.world)
+ self.world = lilv.World()
+ self.world.load_all();
def testInvalidURI(self):
- self.uri = lilv_new_uri(self.world, "invalid_uri")
- self.assertIsNone(self.uri)
- def testInvalidURI2(self):
- self.uri = lilv_new_uri(self.world, "invalid_uri")
- self.assertFalse( lilv_node_is_uri(self.uri) )
+ self.plugin_uri = self.world.new_uri("invalid_uri")
+ self.assertIsNone(self.plugin_uri)
def testNonExistentURI(self):
- self.uri = lilv_new_uri(self.world, "exist:does_not")
- plugins = lilv_world_get_all_plugins(self.world)
- self.plugin = lilv_plugins_get_by_uri(plugins, self.uri)
- self.assertIsNone(self.plugin)
+ 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.uri = lilv_new_uri(self.world, LILV_URI_INPUT_PORT)
- self.assertIsNotNone(self.uri)
+ self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_INPUT_PORT))
def testPortTypes2(self):
- self.uri = lilv_new_uri(self.world, LILV_URI_OUTPUT_PORT)
- self.assertIsNotNone(self.uri)
+ self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_OUTPUT_PORT))
def testPortTypes3(self):
- self.uri = lilv_new_uri(self.world, LILV_URI_AUDIO_PORT)
- self.assertIsNotNone(self.uri)
+ self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_AUDIO_PORT))
def testPortTypes4(self):
- self.uri = lilv_new_uri(self.world, LILV_URI_CONTROL_PORT)
- self.assertIsNotNone(self.uri)
+ 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)
+ self.assertIsNone(pclass.get_parent_uri())
+ self.assertIsNotNone(pclass.get_uri())
+ self.assertIsNotNone(pclass.get_label())
+ self.assertEqual(str(pclass.get_uri()), str(pclass))
+ for i in pclass.get_children():
+ self.assertIsNotNone(i)
+ 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()
+ self.assertIsNotNone(classes)
+ self.assertIsNotNone(pclass)
+ self.assertTrue(pclass in classes)
+ self.assertTrue(pclass.get_uri() in classes)
+ self.assertGreater(len(classes), 1)
+ 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 tearDown(self):
- lilv_node_free(self.uri)
- lilv_world_free(self.world)
+ del self.world
+ def testLoadUnload(self):
+ self.world.load_bundle(self.bundle_uri)
+ plugins = self.world.get_all_plugins()
+ 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_new()
- location = "file://" + os.getcwd() + "/bindings/bindings_test_plugin.lv2/"
- self.plugin_uri = lilv_new_uri(self.world, location)
- self.assertIsNotNone(self.plugin_uri, "Invalid URI: '" + location + "'")
- lilv_world_load_bundle(self.world, self.plugin_uri)
- self.plugins = lilv_world_get_all_plugins(self.world)
- self.plugin = lilv_plugins_get(self.plugins, lilv_plugins_begin(self.plugins))
+ self.world = lilv.World()
+ 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.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.assertEqual(location, lilv_node_as_string(lilv_plugin_get_bundle_uri(self.plugin)))
- self.instance = lilv_plugin_instantiate(self.plugin, 48000, None)
+ 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.instance = lilv.Instance(self.plugin, 48000, None)
self.assertIsNotNone(self.instance)
- self.lv2_InputPort = lilv_new_uri(self.world, LILV_URI_INPUT_PORT)
- self.lv2_OutputPort = lilv_new_uri(self.world, LILV_URI_OUTPUT_PORT)
- self.lv2_AudioPort = lilv_new_uri(self.world, LILV_URI_AUDIO_PORT)
- self.lv2_ControlPort = lilv_new_uri(self.world, 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)
+ 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(licenses[0], licenses.get(licenses.begin()))
+ 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.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):
- n = lilv_plugin_get_num_ports_of_class(self.plugin, self.lv2_InputPort, self.lv2_AudioPort)
- self.assertEqual(n, 1)
- def testPorts2(self):
- n = lilv_plugin_get_num_ports_of_class(self.plugin, self.lv2_OutputPort, self.lv2_AudioPort)
- self.assertEqual(n, 1)
- def testPorts3(self):
- n = lilv_plugin_get_num_ports_of_class(self.plugin, self.lv2_OutputPort, self.lv2_ControlPort)
- self.assertEqual(n, 1)
- def testPorts4(self):
- n = lilv_plugin_get_num_ports_of_class(self.plugin, self.lv2_InputPort, self.lv2_ControlPort)
- self.assertEqual(n, 1)
- def tearDown(self):
- lilv_node_free(self.lv2_InputPort)
- lilv_node_free(self.lv2_OutputPort)
- lilv_node_free(self.lv2_AudioPort)
- lilv_node_free(self.plugin_uri)
- lilv_world_free(self.world)
+ self.assertEqual(self.plugin.get_num_ports(), 4)
+ self.assertIsNotNone(self.plugin.get_port(0))
+ self.assertIsNotNone(self.plugin.get_port(1))
+ self.assertIsNotNone(self.plugin.get_port(2))
+ self.assertIsNotNone(self.plugin.get_port(3))
+ self.assertIsNone(self.plugin.get_port_by_index(4))
+ self.assertIsNotNone(self.plugin.get_port("input"))
+ self.assertIsNotNone(self.plugin.get_port("output"))
+ 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_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))
+ port = self.plugin.get_port("input")
+ self.assertTrue(port.get_node().is_blank())
+ self.assertEqual(0, port.get(self.world.ns.lv2.index))
+ self.assertEqual(1, len(port.get_value(self.world.ns.lv2.symbol)))
+ self.assertEqual(port.get_value(self.world.ns.lv2.symbol)[0], "input")
+ self.assertFalse(port.has_property(self.world.ns.lv2.latency))
+ self.assertFalse(port.supports_event(self.world.ns.midi.MidiEvent))
+ 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.assertTrue(port.is_a(self.world.ns.lv2.ControlPort))
+ self.assertFalse(port.is_a(self.world.ns.lv2.AudioPort))
+ self.assertEquals((0.5, 0.0, 1.0), port.get_range())
+ self.assertEquals(0, len(port.get_properties()))
+ def testScalePoints(self):
+ port = self.plugin.get_port("input")
+ points = port.get_scale_points()
+ self.assertEqual(points[0].get_label(), "off")
+ 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))
+
+class QueryTests(unittest.TestCase):
+ def setUp(self):
+ self.world = lilv.World()
+ self.world.load_all()
+ 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())
+ 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")
+ 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))
+
+class InstanceTests(unittest.TestCase):
+ def setUp(self):
+ self.world = lilv.World()
+ 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[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"))
+ def testRun(self):
+ import numpy
+ n_samples = 100
+ buf = numpy.zeros(n_samples)
+ with self.assertRaises(Exception):
+ self.instance.connect_port(0, "hello")
+ self.instance.connect_port(0, None)
+ self.instance.connect_port(0, None)
+ self.instance.connect_port(2, buf)
+ self.instance.connect_port(3, buf)
+ self.instance.activate()
+ self.instance.run(n_samples)
+ self.instance.deactivate()
+
+class UITests(unittest.TestCase):
+ def setUp(self):
+ self.world = lilv.World()
+ 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[0]
+ def testUI(self):
+ uis = self.plugin.get_uis()
+ 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))
+ self.assertEqual(uis[0].get_uri(), ui_uri)
+ self.assertEqual(uis[0].get_bundle_uri(), self.bundle_uri)
+ self.assertEqual(uis[0].get_binary_uri(), str(self.bundle_uri) + "TODO")
+ self.assertEqual(uis[uis[0].get_uri()], uis[0])
+ self.assertTrue(uis[0].is_a(self.world.ns.ui.GtkUI))
+ self.assertTrue(uis[0] in uis)
+ self.assertTrue(uis[0].get_uri() in uis)
+ self.assertEqual([self.world.ns.ui.GtkUI], list(uis[0].get_classes()))
+ for ui in uis:
+ print(ui)