From 1653faaeeec3b27630625c8a4016ef0f413d7735 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Fri, 5 Jul 2024 23:23:36 +0200 Subject: [PATCH] refactoring: tests for case when env var is class with repr. (#5583) * tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: a <1@1.1> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- tests/test_environ.py | 15 +++++++++++++++ tests/test_integrations.py | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/test_environ.py b/tests/test_environ.py index 9bf551c2e..e40a195e1 100644 --- a/tests/test_environ.py +++ b/tests/test_environ.py @@ -576,6 +576,21 @@ def test_env_get_defaults(): assert "TEST_REG_DNG" not in env +def test_env_class_repr(): + """Class with repr return string if env var.""" + + class Cls: + def __init__(self, var): + self.var = var + + def __repr__(self): + return self.var + + env = Env(CLS=Cls("hello")) + assert str(env.get("CLS")) == "hello" + assert str(env.__getitem__("CLS")) == "hello" + + @pytest.mark.parametrize( "val,validator", [ diff --git a/tests/test_integrations.py b/tests/test_integrations.py index 79231a681..5970d845d 100644 --- a/tests/test_integrations.py +++ b/tests/test_integrations.py @@ -498,6 +498,24 @@ else: 0, ), # + # test env with class + # + ( + """ +class Cls: + def __init__(self, var): + self.var = var + def __repr__(self): + return self.var + +$VAR = Cls("hello") +print($VAR) +echo $VAR +""", + "hello\nhello\n", + 0, + ), + # # test logical subprocess operators # (