Skip to content

Commit ed097dd

Browse files
committed
[FIX] tests/test_util: add fallback to test with astunparse
Old Python versions relying in astunparse will get a slightly different expression with extra parenthesis. closes #234 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 62f7445 commit ed097dd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/base/tests/test_util.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,8 @@ def test_SelfPrint(self, value, expected):
16191619
def test_SelfPrint_prepare(self, value, expected):
16201620
replaced_value, ctx = util.SelfPrintEvalContext.preprocess(value)
16211621
evaluated = safe_eval(replaced_value, ctx, nocopy=True)
1622-
self.assertEqual(str(evaluated), expected)
1622+
# extra fallback for old unparse from astunparse package
1623+
self.assertIn(str(evaluated), [expected, "({})".format(expected)])
16231624

16241625
@parametrize(
16251626
[
@@ -1642,6 +1643,7 @@ def test_SelfPrint_failure(self, value):
16421643
(
16431644
"[('company_id','in',allowed_company_ids or [False])]",
16441645
"[('company_id', 'in', companies.active_ids or [False])]",
1646+
"[('company_id', 'in', (companies.active_ids or [False]))]",
16451647
),
16461648
(
16471649
"[('company_id','in', user.other.allowed_company_ids)]",
@@ -1662,7 +1664,7 @@ def test_SelfPrint_failure(self, value):
16621664
]
16631665
)
16641666
@unittest.skipUnless(util.ast_unparse is not None, "`ast.unparse` available from Python3.9")
1665-
def test_literal_replace(self, orig, expected):
1667+
def test_literal_replace(self, orig, expected, old_unparse_fallback=None):
16661668
repl = util.literal_replace(
16671669
orig,
16681670
{
@@ -1672,7 +1674,10 @@ def test_literal_replace(self, orig, expected):
16721674
"(1, '=', 0)": "(0, '=', 1)",
16731675
},
16741676
)
1675-
self.assertEqual(repl, expected)
1677+
if old_unparse_fallback:
1678+
self.assertIn(repl, [expected, old_unparse_fallback])
1679+
else:
1680+
self.assertEqual(repl, expected)
16761681

16771682

16781683
def not_doing_anything_converter(el):

0 commit comments

Comments
 (0)