Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Garulf committed Feb 19, 2024
1 parent 221f4f7 commit 9bacbe8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 46 deletions.
38 changes: 22 additions & 16 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,67 @@
from pyflowlauncher import api


def test_send_action():
assert api._send_action("Test", "Test") == {"method": "Flow.Launcher.Test", "parameters": ("Test",)}
def check_output(func, method, parameters):
req = func(*parameters)
assert req["method"] == method
assert req["parameters"] == parameters


def test_get_namespace():
assert api._get_namespace("Test") == "Flow.Launcher.Test"


def test_change_query():
assert api.change_query("Test", False) == {"method": "Flow.Launcher.ChangeQuery", "parameters": ("Test", False)}
check_output(api.change_query, "Flow.Launcher.ChangeQuery", ["Test", False])


def test_shell_run():
assert api.shell_run("Test", "Test") == {"method": "Flow.Launcher.ShellRun", "parameters": ("Test", "Test")}
check_output(api.shell_run, "Flow.Launcher.ShellRun", ["Test", "Test"])


def test_close_app():
assert api.close_app() == {"method": "Flow.Launcher.CloseApp", "parameters": ()}
check_output(api.close_app, "Flow.Launcher.CloseApp", [])


def test_hide_app():
assert api.hide_app() == {"method": "Flow.Launcher.HideApp", "parameters": ()}
check_output(api.hide_app, "Flow.Launcher.HideApp", [])


def test_show_app():
assert api.show_app() == {"method": "Flow.Launcher.ShowApp", "parameters": ()}
check_output(api.show_app, "Flow.Launcher.ShowApp", [])


def test_show_msg():
assert api.show_msg("Test", "Test", "Test") == {"method": "Flow.Launcher.ShowMsg", "parameters": ("Test", "Test", "Test")}
check_output(api.show_msg, "Flow.Launcher.ShowMsg", ["Test", "Test", "Test"])


def test_open_setting_dialog():
assert api.open_setting_dialog() == {"method": "Flow.Launcher.OpenSettingDialog", "parameters": ()}
check_output(api.open_setting_dialog, "Flow.Launcher.OpenSettingDialog", [])


def test_start_loading_bar():
assert api.start_loading_bar() == {"method": "Flow.Launcher.StartLoadingBar", "parameters": ()}
check_output(api.start_loading_bar, "Flow.Launcher.StartLoadingBar", [])


def test_stop_loading_bar():
assert api.stop_loading_bar() == {"method": "Flow.Launcher.StopLoadingBar", "parameters": ()}
check_output(api.stop_loading_bar, "Flow.Launcher.StopLoadingBar", [])


def test_reload_plugins():
assert api.reload_plugins() == {"method": "Flow.Launcher.ReloadPlugins", "parameters": ()}
check_output(api.reload_plugins, "Flow.Launcher.ReloadPlugins", [])


def test_copy_to_clipboard():
assert api.copy_to_clipboard("Test", False, True) == {"method": "Flow.Launcher.CopyToClipboard", "parameters": ("Test", False, True)}
check_output(api.copy_to_clipboard, "Flow.Launcher.CopyToClipboard", ["Test", False, True])


def test_open_directory():
assert api.open_directory("Test", "Test") == {"method": "Flow.Launcher.OpenDirectory", "parameters": ("Test", "Test")}
check_output(api.open_directory, "Flow.Launcher.OpenDirectory", ["Test", "Test"])


def test_open_url():
assert api.open_url("Test", False) == {"method": "Flow.Launcher.OpenUrl", "parameters": ("Test", False)}
check_output(api.open_url, "Flow.Launcher.OpenUrl", ["Test", False])


def test_open_uri():
assert api.open_uri("Test") == {"method": "Flow.Launcher.OpenAppUri", "parameters": ("Test",)}
check_output(api.open_uri, "Flow.Launcher.OpenUri", ["Test"])
7 changes: 7 additions & 0 deletions tests/test_id_generation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pyflowlauncher.jsonrpc import id_generation


def test_increment_int():
id_gen = id_generation.incremental_int(1)
assert next(id_gen) == 1
assert next(id_gen) == 2
30 changes: 0 additions & 30 deletions tests/test_jsonrpc.py

This file was deleted.

17 changes: 17 additions & 0 deletions tests/test_jsonrpc_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pyflowlauncher.jsonrpc import client


def test_create_request():
assert client.create_request("Test", ["Test", False], id=1) == {
"method": "Test", "parameters": ["Test", False], "id": 1, "jsonrpc": "2.0"}


def test_request_from_string():
assert client.request_from_string(
"Test", ["Test", False], id=1) == '{"jsonrpc": "2.0", "method": "Test", "parameters": ["Test", false], "id": 1}'


def test_send_request(capsys):
client.send_request(client.create_request("Test", ["Test", False], id=1))
captured = capsys.readouterr()
assert captured.out == '{"jsonrpc": "2.0", "method": "Test", "parameters": ["Test", false], "id": 1}\n'
23 changes: 23 additions & 0 deletions tests/test_jsonrpc_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pyflowlauncher.jsonrpc import server


def test_parse_request():
assert server.parse_request('{"jsonrpc": "2.0", "method": "Test", "params": ["Test", false], "id": 1}') == {
"jsonrpc": "2.0",
"method": "Test",
"params": ["Test", False],
"id": 1,
}


def test_create_response():
assert server.create_response("Test", 1) == {
"jsonrpc": "2.0",
"result": "Test",
"id": 1,
"SettingsChange": None,
}


def test_response():
assert server.response("Test", 1) == '{"jsonrpc": "2.0", "result": "Test", "id": 1, "SettingsChange": null}'

0 comments on commit 9bacbe8

Please sign in to comment.