Test Autocomplete for BECIpython client
There should be test for autocompletion for related to gui. Example (do not work with current implementation):
import copy
import subprocess
import sys
import pytest
import yaml
from bec_ipython_client import main
from bec_lib.service_config import DEFAULT_SERVICE_CONFIG
@pytest.fixture
def service_config(tmpdir, bec_client_lib):
config = copy.deepcopy(DEFAULT_SERVICE_CONFIG)
port = bec_client_lib._service_config.redis.split(":")[-1]
config["redis"]["port"] = port
with open(tmpdir / "config.yaml", "w") as f:
yaml.dump(config, f)
return tmpdir / "config.yaml"
def test_cli_gui_autocompletion(tmpdir, service_config):
file_to_execute = tmpdir / "post_startup.py"
with open(file_to_execute, "w") as f:
f.write(
"""
try:
completer=get_ipython().Completer
import sys
fig.plot([1,2,3], [1,2,3])
dock = bec.gui.panels["default_figure"]
print(completer.all_completions('gui.pane'), flush=True)
print(completer.all_completions('gui.panels["default_figure"].wid'), flush=True)
print(completer.all_completions('gui.panels["default_figure"].widget_list[0].pl'), flush=True)
print(completer.all_completions('dock.atta'), flush=True)
print(completer.all_completions('fig.widget_list[0].cu'), flush=True)
print(completer.all_completions('fig.widget_list[0].curves[0].set_co'), flush=True)
finally:
import os
import signal
gui.close()
os.kill(os.getpid(), signal.SIGTERM)
"""
)
p = subprocess.Popen(
[
sys.executable,
main.__file__,
"--config",
service_config,
"--post-startup-file",
file_to_execute,
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
)
output, _ = p.communicate()
assert "gui" in output
assert "panels" in output
assert "widget_list" in output
assert "plot" in output
assert "attach" in output
assert "curves" in output
assert "set_color" in output
Edited by wyzula_j