Skip to content

Commit

Permalink
test(cli.toggle): --fallback-auto tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loqusion committed Apr 22, 2024
1 parent b572e7a commit a37a072
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/cli/toggle/test_toggle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from collections.abc import Sequence
from datetime import time

import pytest
from click.testing import CliRunner

from hyprshade.cli import cli
from hyprshade.shader import hyprctl
from hyprshade.shader.core import Shader
from tests.helpers import freeze_time
from tests.types import ConfigFactory, ShaderPathFactory

pytestmark = [
Expand Down Expand Up @@ -86,6 +89,70 @@ def test_fallback_default(
assert hyprctl.get_screen_shader() is None


@pytest.mark.parametrize(
("time_str", "expected"),
[
("00:00:00", "default"),
("12:00:00", "default"),
("19:59:30", "default"),
("20:00:00", "test1"),
("20:30:00", "test1"),
("20:59:30", "test1"),
("21:00:00", "test2"),
("22:00:00", "test2"),
("22:59:30", "test2"),
("23:00:00", "test3"),
("23:30:00", "test3"),
("23:59:30", "test3"),
],
)
def test_fallback_auto(
time_str: str,
expected: str,
runner: CliRunner,
shader_path_factory: ShaderPathFactory,
config_factory: ConfigFactory,
):
config_factory.write(
{
"shaders": [
{
"name": "test1",
"start_time": time.fromisoformat("20:00"),
"end_time": time.fromisoformat("21:00"),
},
{
"name": "test2",
"start_time": time.fromisoformat("21:00"),
},
{
"name": "test3",
"start_time": time.fromisoformat("23:00"),
"end_time": time.fromisoformat("00:00"),
},
{
"name": "default",
"default": True,
},
]
}
)
shader_path_factory("test1")
shader_path_factory("test2")
shader_path_factory("test3")
shader_path_factory("default")
initial_shader_path = shader_path_factory("initial")
hyprctl.set_screen_shader(str(initial_shader_path))

with freeze_time(time_str):
result = runner.invoke(cli, ["toggle", "initial", "--fallback-auto"])

assert result.exit_code == 0
current_screen_shader_path = hyprctl.get_screen_shader()
assert current_screen_shader_path is not None
assert Shader.path_to_name(current_screen_shader_path) == expected


def test_no_config_no_positional_argument(runner: CliRunner):
result = runner.invoke(cli, ["toggle"])

Expand Down

0 comments on commit a37a072

Please sign in to comment.