async def boot(self, port=DEFAULT_PORT, *, scsynth_path=None, options=None, **kwargs): if self._is_running: raise supriya.exceptions.ServerOnline port = port or DEFAULT_PORT loop = asyncio.get_running_loop() self._boot_future = loop.create_future() self._quit_future = loop.create_future() self._options = new(options or Options(), **kwargs) scsynth_path = scsynth.find(scsynth_path) self._process_protocol = AsyncProcessProtocol() await self._process_protocol.boot(self._options, scsynth_path, port) if not await self._process_protocol.boot_future: self._boot_future.set_result(False) self._quit_future.set_result(True) raise supriya.exceptions.ServerCannotBoot self._ip_address = "127.0.0.1" self._is_owner = True self._port = port await self._connect() return self
def _build_render_command( self, input_file_path, output_file_path, session_osc_file_path, *, scsynth_path=None, server_options=None, ): cwd = pathlib.Path.cwd() scsynth_path = scsynth.find(scsynth_path) server_options = server_options or scsynth.Options() if os.environ.get("TRAVIS", None): server_options = new(server_options, load_synthdefs=True) if session_osc_file_path.is_absolute(): session_osc_file_path = session_osc_file_path.relative_to(cwd) parts = [scsynth_path, "-N", session_osc_file_path] if input_file_path: parts.append(input_file_path) else: parts.append("_") if output_file_path.is_absolute() and cwd in output_file_path.parents: output_file_path = output_file_path.relative_to(cwd) parts.append(output_file_path) parts.append(self.sample_rate) parts.append(self.header_format.name.lower()) # Must be lowercase. parts.append(self.sample_format.name.lower()) # Must be lowercase. server_options = server_options.as_options_string(realtime=False) if server_options: parts.append(server_options) command = " ".join(str(_) for _ in parts) return command
def test_connect_and_reconnect(): try: options = scsynth.Options(maximum_logins=4) protocol = SyncProcessProtocol() protocol.boot(options, scsynth.find(), 57110) server = Server() server.connect(port=57110) assert server.is_running and not server.is_owner assert server.client_id == 0 assert str(server.query_local_nodes(True)) == normalize(""" NODE TREE 0 group 1 group 2 group 3 group 4 group """) server.disconnect() server.connect(port=57110) assert server.is_running and not server.is_owner assert server.client_id == 1 assert str(server.query_local_nodes(True)) == normalize(""" NODE TREE 0 group 1 group 2 group 3 group 4 group """) finally: protocol.quit()
def test_ThreadedOscProtocol(): def on_healthcheck_failed(): healthcheck_failed.append(True) healthcheck_failed = [] options = Options() port = find_free_port() healthcheck = HealthCheck(["/status"], ["/status.reply"], on_healthcheck_failed) process_protocol = SyncProcessProtocol() process_protocol.boot(options, find(), port) assert process_protocol.is_running osc_protocol = ThreadedOscProtocol() osc_protocol.connect("127.0.0.1", port, healthcheck=healthcheck) assert osc_protocol.is_running assert not healthcheck_failed time.sleep(1) process_protocol.quit() assert not process_protocol.is_running assert osc_protocol.is_running assert not healthcheck_failed for _ in range(20): time.sleep(1) if not osc_protocol.is_running: break assert healthcheck_failed assert not osc_protocol.is_running
async def boot( self, *, ip_address: str = DEFAULT_IP_ADDRESS, port: int = DEFAULT_PORT, scsynth_path: Optional[str] = None, options: Optional[Options] = None, **kwargs, ) -> "AsyncServer": if self._is_running: raise supriya.exceptions.ServerOnline port = port or DEFAULT_PORT loop = asyncio.get_running_loop() self._boot_future = loop.create_future() self._quit_future = loop.create_future() self._options = new(options or Options(), **kwargs) scsynth_path = find(scsynth_path) self._process_protocol = AsyncProcessProtocol() await self._process_protocol.boot(self._options, scsynth_path, port) if not await self._process_protocol.boot_future: self._boot_future.set_result(False) self._quit_future.set_result(True) raise supriya.exceptions.ServerCannotBoot self._ip_address = ip_address self._is_owner = True self._port = port await self._connect() return self
def _build_render_command( self, output_filename, *, input_file_path=None, server_options=None, sample_rate=44100, header_format=HeaderFormat.AIFF, sample_format=SampleFormat.INT24, scsynth_path=None, ): server_options = server_options or scsynth.Options() scsynth_path = scsynth.find(scsynth_path) parts = [str(scsynth_path), "-N", "{}"] if input_file_path: parts.append(os.path.expanduser(input_file_path)) else: parts.append("_") parts.append(os.path.expanduser(output_filename)) parts.append(str(int(sample_rate))) header_format = HeaderFormat.from_expr(header_format) parts.append(header_format.name.lower()) # Must be lowercase. sample_format = SampleFormat.from_expr(sample_format) parts.append(sample_format.name.lower()) # Must be lowercase. server_options = server_options.as_options_string(realtime=False) if server_options: parts.append(server_options) command = " ".join(parts) return command
async def test_AsyncOscProtocol(): def on_healthcheck_failed(): healthcheck_failed.append(True) try: healthcheck_failed = [] options = Options() port = find_free_port() healthcheck = HealthCheck(["/status"], ["/status.reply"], on_healthcheck_failed) process_protocol = AsyncProcessProtocol() await process_protocol.boot(options, find(), port) assert await process_protocol.boot_future osc_protocol = AsyncOscProtocol() await osc_protocol.connect("127.0.0.1", port, healthcheck=healthcheck) assert osc_protocol.is_running assert not healthcheck_failed await asyncio.sleep(1) process_protocol.quit() for _ in range(20): await asyncio.sleep(1) if not osc_protocol.is_running: break assert healthcheck_failed assert not osc_protocol.is_running finally: process_protocol.quit()
def test_find_env_var(mock_env_scsynth_path, monkeypatch): with NamedTemporaryFile() as tmp: expected = pathlib.Path(tmp.name).absolute() expected.chmod(expected.stat().st_mode | stat.S_IEXEC) monkeypatch.setenv("SCSYNTH_PATH", str(expected)) got = scsynth.find() assert got == expected
def test_find_from_fallback_paths(mock_env_scsynth_path, mocker): with NamedTemporaryFile() as tmp: expected = pathlib.Path(tmp.name).absolute() expected.chmod(expected.stat().st_mode | stat.S_IEXEC) mock = mocker.patch.object(scsynth, "_fallback_scsynth_path") mock.return_value = expected got = scsynth.find() assert got == expected
def test_find_on_path(mock_env_scsynth_path, monkeypatch): with TemporaryDirectory() as tmp_dir: scsynth_path = pathlib.Path(tmp_dir) / "scsynth" with open(scsynth_path, "w"): scsynth_path.chmod(scsynth_path.stat().st_mode | stat.S_IEXEC) monkeypatch.setenv("PATH", os.pathsep + tmp_dir) got = scsynth.find() expected = scsynth_path.absolute() assert got == expected
def boot(self, port=DEFAULT_PORT, *, scsynth_path=None, options=None, **kwargs): if self.is_running: raise supriya.exceptions.ServerOnline port = port or DEFAULT_PORT self._options = new(options or Options(), **kwargs) scsynth_path = scsynth.find(scsynth_path) self._process_protocol = SyncProcessProtocol() self._process_protocol.boot(self._options, scsynth_path, port) self._ip_address = "127.0.0.1" self._is_owner = True self._port = port self._connect() return self
def boot( self, *, ip_address: str = DEFAULT_IP_ADDRESS, port: int = DEFAULT_PORT, scsynth_path: Optional[str] = None, options: Optional[Options] = None, **kwargs, ) -> "Server": if self.is_running: raise supriya.exceptions.ServerOnline port = port or DEFAULT_PORT self._options = new(options or Options(), **kwargs) scsynth_path = find(scsynth_path) self._process_protocol = SyncProcessProtocol() self._process_protocol.boot(self._options, scsynth_path, port) self._ip_address = ip_address self._is_owner = True self._port = port self._connect() return self
def test_find_argument(mock_env_scsynth_path): with NamedTemporaryFile() as tmp: expected = pathlib.Path(tmp.name).absolute() expected.chmod(expected.stat().st_mode | stat.S_IEXEC) got = scsynth.find(expected) assert got == expected