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>
This commit is contained in:
Andy Kipp 2024-07-05 23:23:36 +02:00 committed by GitHub
parent 01dc8858e6
commit 1653faaeee
Failed to generate hash of commit
2 changed files with 33 additions and 0 deletions

View file

@ -576,6 +576,21 @@ def test_env_get_defaults():
assert "TEST_REG_DNG" not in env 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( @pytest.mark.parametrize(
"val,validator", "val,validator",
[ [

View file

@ -498,6 +498,24 @@ else:
0, 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 # test logical subprocess operators
# #
( (