mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00
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:
parent
01dc8858e6
commit
1653faaeee
2 changed files with 33 additions and 0 deletions
|
@ -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",
|
||||
[
|
||||
|
|
|
@ -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
|
||||
#
|
||||
(
|
||||
|
|
Loading…
Add table
Reference in a new issue