From fa6095462add8a9fe37bf1dfe8ab06749b03d8cf Mon Sep 17 00:00:00 2001 From: loqusion <38332081+loqusion@users.noreply.github.com> Date: Mon, 6 May 2024 19:48:15 -0500 Subject: [PATCH] test(refactor): move duplicated test classes to single parameterized test class --- .../__snapshots__/test_vars_option.ambr | 179 ++++++++++ tests/cli/common/test_vars_option.py | 331 ++++++++++++++++++ tests/cli/on/__snapshots__/test_on.ambr | 90 ----- tests/cli/on/test_on.py | 312 +---------------- .../cli/toggle/__snapshots__/test_toggle.ambr | 90 ----- tests/cli/toggle/test_toggle.py | 309 ---------------- 6 files changed, 511 insertions(+), 800 deletions(-) create mode 100644 tests/cli/common/__snapshots__/test_vars_option.ambr create mode 100644 tests/cli/common/test_vars_option.py delete mode 100644 tests/cli/on/__snapshots__/test_on.ambr delete mode 100644 tests/cli/toggle/__snapshots__/test_toggle.ambr diff --git a/tests/cli/common/__snapshots__/test_vars_option.ambr b/tests/cli/common/__snapshots__/test_vars_option.ambr new file mode 100644 index 0000000..0f698de --- /dev/null +++ b/tests/cli/common/__snapshots__/test_vars_option.ambr @@ -0,0 +1,179 @@ +# serializer version: 1 +# name: TestVarOption.test[on] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int key = 3; + void main() {} + ''' +# --- +# name: TestVarOption.test[toggle] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int key = 3; + void main() {} + ''' +# --- +# name: TestVarOption.test_dot[on] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int bar = 3; + void main() {} + ''' +# --- +# name: TestVarOption.test_dot[toggle] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int bar = 3; + void main() {} + ''' +# --- +# name: TestVarOption.test_dot_deep_merge[on] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int bar = 1; + const int baz_qux = 2; + const int baz_baz_qux = 3; + void main() {} + ''' +# --- +# name: TestVarOption.test_dot_deep_merge[toggle] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int bar = 1; + const int baz_qux = 2; + const int baz_baz_qux = 3; + void main() {} + ''' +# --- +# name: TestVarOption.test_dot_shallow_merge[on] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int bar = 1; + const int baz = 2; + const int qux = 3; + void main() {} + ''' +# --- +# name: TestVarOption.test_dot_shallow_merge[toggle] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int bar = 1; + const int baz = 2; + const int qux = 3; + void main() {} + ''' +# --- +# name: TestVarOption.test_merge_with_config[on] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int r = 1; + const int g = 2; + const int b = 3; + void main() {} + ''' +# --- +# name: TestVarOption.test_merge_with_config[toggle] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int r = 1; + const int g = 2; + const int b = 3; + void main() {} + ''' +# --- +# name: TestVarOption.test_multiple[on] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int WORLD = 5; + const int key = WORLD; + void main() {} + ''' +# --- +# name: TestVarOption.test_multiple[toggle] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int WORLD = 5; + const int key = WORLD; + void main() {} + ''' +# --- +# name: TestVarOption.test_override[on] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int WORLD = 5; + const int key = WORLD; + void main() {} + ''' +# --- +# name: TestVarOption.test_override[toggle] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int WORLD = 5; + const int key = WORLD; + void main() {} + ''' +# --- +# name: TestVarOption.test_override_deep[on] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int foo_bar_baz = 1; + void main() {} + ''' +# --- +# name: TestVarOption.test_override_deep[toggle] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int foo_bar_baz = 1; + void main() {} + ''' +# --- +# name: TestVarOption.test_override_from_deep[on] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int foo_bar = 1; + void main() {} + ''' +# --- +# name: TestVarOption.test_override_from_deep[toggle] + ''' + // This file was generated by Hyprshade. + // Do not edit it directly. + + const int foo_bar = 1; + void main() {} + ''' +# --- diff --git a/tests/cli/common/test_vars_option.py b/tests/cli/common/test_vars_option.py new file mode 100644 index 0000000..b8c0476 --- /dev/null +++ b/tests/cli/common/test_vars_option.py @@ -0,0 +1,331 @@ +import pytest +from click.testing import CliRunner +from syrupy.assertion import SnapshotAssertion + +from hyprshade.cli import cli +from hyprshade.shader import hyprctl +from hyprshade.shader.core import Shader +from tests.types import ConfigFactory, ShaderPathFactory + +pytestmark = [ + pytest.mark.requires_hyprland(), +] + + +@pytest.mark.parametrize("subcommand", ["on", "toggle"]) +class TestVarOption: + def test( + self, + subcommand: str, + runner: CliRunner, + shader_path_factory: ShaderPathFactory, + snapshot: SnapshotAssertion, + ): + shader_path_factory( + "shader", + extension="glsl.mustache", + text=("""const int key = {{key}};\n""" """void main() {}"""), + ) + result = runner.invoke(cli, [subcommand, "shader", "--var", "key=3"]) + + assert result.exit_code == 0 + current_shader_path = hyprctl.get_screen_shader() + assert current_shader_path is not None + assert ( + Shader._get_template_instance_content_without_metadata(current_shader_path) + == snapshot + ) + + def test_multiple( + self, + subcommand: str, + runner: CliRunner, + shader_path_factory: ShaderPathFactory, + snapshot: SnapshotAssertion, + ): + shader_path_factory( + "shader", + extension="glsl.mustache", + text=( + """const int WORLD = {{world}};\n""" + """const int key = {{key}};\n""" + """void main() {}""" + ), + ) + result = runner.invoke( + cli, [subcommand, "shader", "--var", "key=world", "--var", "world=5"] + ) + + assert result.exit_code == 0 + current_shader_path = hyprctl.get_screen_shader() + assert current_shader_path is not None + assert ( + Shader._get_template_instance_content_without_metadata(current_shader_path) + == snapshot + ) + + def test_dot( + self, + subcommand: str, + runner: CliRunner, + shader_path_factory: ShaderPathFactory, + snapshot: SnapshotAssertion, + ): + shader_path_factory( + "shader", + extension="glsl.mustache", + text=("""const int bar = {{foo.bar}};\n""" """void main() {}"""), + ) + result = runner.invoke(cli, [subcommand, "shader", "--var", "foo.bar=3"]) + + assert result.exit_code == 0 + current_shader_path = hyprctl.get_screen_shader() + assert current_shader_path is not None + assert ( + Shader._get_template_instance_content_without_metadata(current_shader_path) + == snapshot + ) + + def test_dot_shallow_merge( + self, + subcommand: str, + runner: CliRunner, + shader_path_factory: ShaderPathFactory, + snapshot: SnapshotAssertion, + ): + shader_path_factory( + "shader", + extension="glsl.mustache", + text=( + """const int bar = {{foo.bar}};\n""" + """const int baz = {{foo.baz}};\n""" + """const int qux = {{foo.qux}};\n""" + """void main() {}""" + ), + ) + result = runner.invoke( + cli, + [ + subcommand, + "shader", + "--var", + "foo.bar=1", + "--var", + "foo.baz=2", + "--var", + "foo.qux=3", + ], + ) + + assert result.exit_code == 0 + current_shader_path = hyprctl.get_screen_shader() + assert current_shader_path is not None + assert ( + Shader._get_template_instance_content_without_metadata(current_shader_path) + == snapshot + ) + + def test_dot_deep_merge( + self, + subcommand: str, + runner: CliRunner, + shader_path_factory: ShaderPathFactory, + snapshot: SnapshotAssertion, + ): + shader_path_factory( + "shader", + extension="glsl.mustache", + text=( + """const int bar = {{foo.bar}};\n""" + """const int baz_qux = {{foo.baz.qux}};\n""" + """const int baz_baz_qux = {{foo.baz.baz.qux}};\n""" + """void main() {}""" + ), + ) + result = runner.invoke( + cli, + [ + subcommand, + "shader", + "--var", + "foo.bar=1", + "--var", + "foo.baz.qux=2", + "--var", + "foo.baz.baz.qux=3", + ], + ) + + assert result.exit_code == 0 + current_shader_path = hyprctl.get_screen_shader() + assert current_shader_path is not None + assert ( + Shader._get_template_instance_content_without_metadata(current_shader_path) + == snapshot + ) + + def test_override( + self, + subcommand: str, + runner: CliRunner, + shader_path_factory: ShaderPathFactory, + snapshot: SnapshotAssertion, + ): + shader_path_factory( + "shader", + extension="glsl.mustache", + text=( + """const int WORLD = {{world}};\n""" + """const int key = {{key}};\n""" + """void main() {}""" + ), + ) + result = runner.invoke( + cli, + [ + subcommand, + "shader", + "--var", + "key=planet", + "--var", + "key=world", + "--var", + "world=5", + ], + ) + + assert result.exit_code == 0 + current_shader_path = hyprctl.get_screen_shader() + assert current_shader_path is not None + assert ( + Shader._get_template_instance_content_without_metadata(current_shader_path) + == snapshot + ) + + def test_override_deep( + self, + subcommand: str, + runner: CliRunner, + shader_path_factory: ShaderPathFactory, + snapshot: SnapshotAssertion, + ): + shader_path_factory( + "shader", + extension="glsl.mustache", + text=( + """const int foo_bar_baz = {{foo.bar.baz}};\n""" """void main() {}""" + ), + ) + result = runner.invoke( + cli, + [ + subcommand, + "shader", + "--var", + "foo.bar=0", + "--var", + "foo.bar.baz=1", + ], + ) + + assert result.exit_code == 0 + current_shader_path = hyprctl.get_screen_shader() + assert current_shader_path is not None + assert ( + Shader._get_template_instance_content_without_metadata(current_shader_path) + == snapshot + ) + + def test_override_from_deep( + self, + subcommand: str, + runner: CliRunner, + shader_path_factory: ShaderPathFactory, + snapshot: SnapshotAssertion, + ): + shader_path_factory( + "shader", + extension="glsl.mustache", + text=("""const int foo_bar = {{foo.bar}};\n""" """void main() {}"""), + ) + result = runner.invoke( + cli, + [ + subcommand, + "shader", + "--var", + "foo.bar.baz=0", + "--var", + "foo.bar=1", + ], + ) + + assert result.exit_code == 0 + current_shader_path = hyprctl.get_screen_shader() + assert current_shader_path is not None + assert ( + Shader._get_template_instance_content_without_metadata(current_shader_path) + == snapshot + ) + + def test_merge_with_config( + self, + subcommand: str, + runner: CliRunner, + shader_path_factory: ShaderPathFactory, + config_factory: ConfigFactory, + snapshot: SnapshotAssertion, + ): + shader_path_factory( + "shader", + extension="glsl.mustache", + text=( + """const int r = {{balance.r}};\n""" + """const int g = {{balance.g}};\n""" + """const int b = {{balance.b}};\n""" + """void main() {}""" + ), + ) + config_factory.write( + { + "shaders": [ + { + "name": "shader", + "config": {"balance": {"r": 1, "g": 5}}, + } + ] + } + ) + result = runner.invoke( + cli, + [ + subcommand, + "shader", + "--var", + "balance.g=2", + "--var", + "balance.b=3", + ], + ) + + assert result.exit_code == 0 + current_shader_path = hyprctl.get_screen_shader() + assert current_shader_path is not None + assert ( + Shader._get_template_instance_content_without_metadata(current_shader_path) + == snapshot + ) + + def test_no_equals( + self, + subcommand: str, + runner: CliRunner, + shader_path_factory: ShaderPathFactory, + ): + shader_path_factory( + "shader", extension="glsl.mustache", text="""void main() {}""" + ) + result = runner.invoke(cli, [subcommand, "shader", "--var", "key"]) + + assert result.exit_code != 0 + assert "Invalid value for '--var' / '-V'" in result.stderr diff --git a/tests/cli/on/__snapshots__/test_on.ambr b/tests/cli/on/__snapshots__/test_on.ambr deleted file mode 100644 index adf07ca..0000000 --- a/tests/cli/on/__snapshots__/test_on.ambr +++ /dev/null @@ -1,90 +0,0 @@ -# serializer version: 1 -# name: TestVarOption.test - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int key = 3; - void main() {} - ''' -# --- -# name: TestVarOption.test_dot - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int bar = 3; - void main() {} - ''' -# --- -# name: TestVarOption.test_dot_deep_merge - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int bar = 1; - const int baz_qux = 2; - const int baz_baz_qux = 3; - void main() {} - ''' -# --- -# name: TestVarOption.test_dot_shallow_merge - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int bar = 1; - const int baz = 2; - const int qux = 3; - void main() {} - ''' -# --- -# name: TestVarOption.test_merge_with_config - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int r = 1; - const int g = 2; - const int b = 3; - void main() {} - ''' -# --- -# name: TestVarOption.test_multiple - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int WORLD = 5; - const int key = WORLD; - void main() {} - ''' -# --- -# name: TestVarOption.test_override - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int WORLD = 5; - const int key = WORLD; - void main() {} - ''' -# --- -# name: TestVarOption.test_override_deep - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int foo_bar_baz = 1; - void main() {} - ''' -# --- -# name: TestVarOption.test_override_from_deep - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int foo_bar = 1; - void main() {} - ''' -# --- diff --git a/tests/cli/on/test_on.py b/tests/cli/on/test_on.py index e730087..fc50006 100644 --- a/tests/cli/on/test_on.py +++ b/tests/cli/on/test_on.py @@ -2,12 +2,10 @@ import pytest from click.testing import CliRunner -from syrupy.assertion import SnapshotAssertion from hyprshade.cli import cli from hyprshade.shader import hyprctl -from hyprshade.shader.core import Shader -from tests.types import ConfigFactory, ShaderPathFactory +from tests.types import ShaderPathFactory pytestmark = [ pytest.mark.requires_hyprland(), @@ -56,311 +54,3 @@ def test_invalid_shader_dot(runner: CliRunner, shader_path_factory: ShaderPathFa assert result.exit_code != 0 assert isinstance(result.exception, ValueError) assert hyprctl.get_screen_shader() == initial_shader - - -class TestVarOption: - def test( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=("""const int key = {{key}};\n""" """void main() {}"""), - ) - result = runner.invoke(cli, ["on", "shader", "--var", "key=3"]) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_multiple( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int WORLD = {{world}};\n""" - """const int key = {{key}};\n""" - """void main() {}""" - ), - ) - result = runner.invoke( - cli, ["on", "shader", "--var", "key=world", "--var", "world=5"] - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_dot( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=("""const int bar = {{foo.bar}};\n""" """void main() {}"""), - ) - result = runner.invoke(cli, ["on", "shader", "--var", "foo.bar=3"]) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_dot_shallow_merge( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int bar = {{foo.bar}};\n""" - """const int baz = {{foo.baz}};\n""" - """const int qux = {{foo.qux}};\n""" - """void main() {}""" - ), - ) - result = runner.invoke( - cli, - [ - "on", - "shader", - "--var", - "foo.bar=1", - "--var", - "foo.baz=2", - "--var", - "foo.qux=3", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_dot_deep_merge( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int bar = {{foo.bar}};\n""" - """const int baz_qux = {{foo.baz.qux}};\n""" - """const int baz_baz_qux = {{foo.baz.baz.qux}};\n""" - """void main() {}""" - ), - ) - result = runner.invoke( - cli, - [ - "on", - "shader", - "--var", - "foo.bar=1", - "--var", - "foo.baz.qux=2", - "--var", - "foo.baz.baz.qux=3", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_override( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int WORLD = {{world}};\n""" - """const int key = {{key}};\n""" - """void main() {}""" - ), - ) - result = runner.invoke( - cli, - [ - "on", - "shader", - "--var", - "key=planet", - "--var", - "key=world", - "--var", - "world=5", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_override_deep( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int foo_bar_baz = {{foo.bar.baz}};\n""" """void main() {}""" - ), - ) - result = runner.invoke( - cli, - [ - "on", - "shader", - "--var", - "foo.bar=0", - "--var", - "foo.bar.baz=1", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_override_from_deep( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=("""const int foo_bar = {{foo.bar}};\n""" """void main() {}"""), - ) - result = runner.invoke( - cli, - [ - "on", - "shader", - "--var", - "foo.bar.baz=0", - "--var", - "foo.bar=1", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_merge_with_config( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - config_factory: ConfigFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int r = {{balance.r}};\n""" - """const int g = {{balance.g}};\n""" - """const int b = {{balance.b}};\n""" - """void main() {}""" - ), - ) - config_factory.write( - { - "shaders": [ - { - "name": "shader", - "config": {"balance": {"r": 1, "g": 5}}, - } - ] - } - ) - result = runner.invoke( - cli, - [ - "on", - "shader", - "--var", - "balance.g=2", - "--var", - "balance.b=3", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_no_equals( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - ): - shader_path_factory( - "shader", extension="glsl.mustache", text="""void main() {}""" - ) - result = runner.invoke(cli, ["on", "shader", "--var", "key"]) - - assert result.exit_code != 0 - assert "Invalid value for '--var' / '-V'" in result.stderr diff --git a/tests/cli/toggle/__snapshots__/test_toggle.ambr b/tests/cli/toggle/__snapshots__/test_toggle.ambr deleted file mode 100644 index adf07ca..0000000 --- a/tests/cli/toggle/__snapshots__/test_toggle.ambr +++ /dev/null @@ -1,90 +0,0 @@ -# serializer version: 1 -# name: TestVarOption.test - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int key = 3; - void main() {} - ''' -# --- -# name: TestVarOption.test_dot - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int bar = 3; - void main() {} - ''' -# --- -# name: TestVarOption.test_dot_deep_merge - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int bar = 1; - const int baz_qux = 2; - const int baz_baz_qux = 3; - void main() {} - ''' -# --- -# name: TestVarOption.test_dot_shallow_merge - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int bar = 1; - const int baz = 2; - const int qux = 3; - void main() {} - ''' -# --- -# name: TestVarOption.test_merge_with_config - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int r = 1; - const int g = 2; - const int b = 3; - void main() {} - ''' -# --- -# name: TestVarOption.test_multiple - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int WORLD = 5; - const int key = WORLD; - void main() {} - ''' -# --- -# name: TestVarOption.test_override - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int WORLD = 5; - const int key = WORLD; - void main() {} - ''' -# --- -# name: TestVarOption.test_override_deep - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int foo_bar_baz = 1; - void main() {} - ''' -# --- -# name: TestVarOption.test_override_from_deep - ''' - // This file was generated by Hyprshade. - // Do not edit it directly. - - const int foo_bar = 1; - void main() {} - ''' -# --- diff --git a/tests/cli/toggle/test_toggle.py b/tests/cli/toggle/test_toggle.py index 413e883..82362de 100644 --- a/tests/cli/toggle/test_toggle.py +++ b/tests/cli/toggle/test_toggle.py @@ -3,7 +3,6 @@ import pytest from click.testing import CliRunner -from syrupy.assertion import SnapshotAssertion from hyprshade.cli import cli from hyprshade.shader import hyprctl @@ -200,311 +199,3 @@ def test_multiple_fallback_options( assert result.exit_code != 0 assert "--fallback" in result.stderr or "--fallback" in str(result.exception) - - -class TestVarOption: - def test( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=("""const int key = {{key}};\n""" """void main() {}"""), - ) - result = runner.invoke(cli, ["toggle", "shader", "--var", "key=3"]) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_multiple( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int WORLD = {{world}};\n""" - """const int key = {{key}};\n""" - """void main() {}""" - ), - ) - result = runner.invoke( - cli, ["toggle", "shader", "--var", "key=world", "--var", "world=5"] - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_dot( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=("""const int bar = {{foo.bar}};\n""" """void main() {}"""), - ) - result = runner.invoke(cli, ["toggle", "shader", "--var", "foo.bar=3"]) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_dot_shallow_merge( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int bar = {{foo.bar}};\n""" - """const int baz = {{foo.baz}};\n""" - """const int qux = {{foo.qux}};\n""" - """void main() {}""" - ), - ) - result = runner.invoke( - cli, - [ - "toggle", - "shader", - "--var", - "foo.bar=1", - "--var", - "foo.baz=2", - "--var", - "foo.qux=3", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_dot_deep_merge( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int bar = {{foo.bar}};\n""" - """const int baz_qux = {{foo.baz.qux}};\n""" - """const int baz_baz_qux = {{foo.baz.baz.qux}};\n""" - """void main() {}""" - ), - ) - result = runner.invoke( - cli, - [ - "toggle", - "shader", - "--var", - "foo.bar=1", - "--var", - "foo.baz.qux=2", - "--var", - "foo.baz.baz.qux=3", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_override( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int WORLD = {{world}};\n""" - """const int key = {{key}};\n""" - """void main() {}""" - ), - ) - result = runner.invoke( - cli, - [ - "toggle", - "shader", - "--var", - "key=planet", - "--var", - "key=world", - "--var", - "world=5", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_override_deep( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int foo_bar_baz = {{foo.bar.baz}};\n""" """void main() {}""" - ), - ) - result = runner.invoke( - cli, - [ - "toggle", - "shader", - "--var", - "foo.bar=0", - "--var", - "foo.bar.baz=1", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_override_from_deep( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=("""const int foo_bar = {{foo.bar}};\n""" """void main() {}"""), - ) - result = runner.invoke( - cli, - [ - "toggle", - "shader", - "--var", - "foo.bar.baz=0", - "--var", - "foo.bar=1", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_merge_with_config( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - config_factory: ConfigFactory, - snapshot: SnapshotAssertion, - ): - shader_path_factory( - "shader", - extension="glsl.mustache", - text=( - """const int r = {{balance.r}};\n""" - """const int g = {{balance.g}};\n""" - """const int b = {{balance.b}};\n""" - """void main() {}""" - ), - ) - config_factory.write( - { - "shaders": [ - { - "name": "shader", - "config": {"balance": {"r": 1, "g": 5}}, - } - ] - } - ) - result = runner.invoke( - cli, - [ - "on", - "shader", - "--var", - "balance.g=2", - "--var", - "balance.b=3", - ], - ) - - assert result.exit_code == 0 - current_shader_path = hyprctl.get_screen_shader() - assert current_shader_path is not None - assert ( - Shader._get_template_instance_content_without_metadata(current_shader_path) - == snapshot - ) - - def test_no_equals( - self, - runner: CliRunner, - shader_path_factory: ShaderPathFactory, - ): - shader_path_factory( - "shader", extension="glsl.mustache", text="""void main() {}""" - ) - result = runner.invoke(cli, ["toggle", "shader", "--var", "key"]) - - assert result.exit_code != 0 - assert "Invalid value for '--var' / '-V'" in result.stderr