diff --git a/DEVELOPERS b/DEVELOPERS index 0451d8341c..5ffd0e5398 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -2295,6 +2295,7 @@ F: support/testing/tests/package/test_python_pydantic_settings.py F: support/testing/tests/package/test_python_ruamel_yaml.py F: support/testing/tests/package/test_python_sdbus_modemmanager.py F: support/testing/tests/package/test_python_tzlocal.py +F: support/testing/tests/package/test_python_varlink/ F: support/testing/tests/package/test_python_waitress.py F: support/testing/tests/package/test_python_whitenoise.py F: support/testing/tests/package/sample_python_apscheduler.py diff --git a/support/testing/tests/package/test_python_varlink.py b/support/testing/tests/package/test_python_varlink.py new file mode 100644 index 0000000000..f8595582f5 --- /dev/null +++ b/support/testing/tests/package/test_python_varlink.py @@ -0,0 +1,30 @@ +import os + +from tests.package.test_python import TestPythonPackageBase + + +class TestPythonPy3Varlink(TestPythonPackageBase): + __test__ = True + config = TestPythonPackageBase.config + \ + """ + BR2_PACKAGE_PYTHON3=y + BR2_PACKAGE_PYTHON_VARLINK=y + """ + sample_scripts = ["tests/package/test_python_varlink/sample_python_varlink.py", + "tests/package/test_python_varlink/org.example.test.varlink"] + + def test_run(self): + self.login() + self.check_sample_scripts_exist() + # we need to supress any output here as otherwise the commnd output parsing + # gets confused for the second command + cmd = "%s %s > /dev/null 2>&1 &" % (self.interpreter, os.path.basename(self.sample_scripts[0])) + + _, exit_code = self.emulator.run(cmd, timeout=self.timeout) + + varlink_cli_call = "-m varlink.cli call 'unix:@test/org.example.test.Ping' '{\"ping\": \"hello\"}'" + unprettyprint = "| python -m json.tool --compact" + cmd = "%s %s %s" % (self.interpreter, varlink_cli_call, unprettyprint) + output, exit_code = self.emulator.run(cmd, timeout=self.timeout) + self.assertEqual(exit_code, 0) + self.assertEqual(output[0], '{"pong":"hello"}') diff --git a/support/testing/tests/package/test_python_varlink/org.example.test.varlink b/support/testing/tests/package/test_python_varlink/org.example.test.varlink new file mode 100644 index 0000000000..c199824e6e --- /dev/null +++ b/support/testing/tests/package/test_python_varlink/org.example.test.varlink @@ -0,0 +1,5 @@ +# Example Varlink service +interface org.example.test + +# Returns the same string +method Ping(ping: string) -> (pong: string) diff --git a/support/testing/tests/package/test_python_varlink/sample_python_varlink.py b/support/testing/tests/package/test_python_varlink/sample_python_varlink.py new file mode 100644 index 0000000000..567d95da80 --- /dev/null +++ b/support/testing/tests/package/test_python_varlink/sample_python_varlink.py @@ -0,0 +1,24 @@ +import os + +import varlink + +service = varlink.Service(interface_dir=os.path.dirname(__file__)) + + +class ServiceRequestHandler(varlink.RequestHandler): + service = service + + +@service.interface("org.example.test") +class Example: + def Ping(self, ping): + return {"pong": ping} + + +def run_server(address): + with varlink.ThreadingServer(address, ServiceRequestHandler) as server: + print("Listening on", server.server_address) + server.serve_forever() + + +run_server("unix:@test")