Skip to content

Commit

Permalink
Fixed test failure on pypy
Browse files Browse the repository at this point in the history
Code was working, just test was broken, due to placing test method
in wrong test class where UseConcatJoinMixin wasn't being used
  • Loading branch information
spookylukey committed Apr 2, 2024
1 parent 9152a25 commit 19aa241
Showing 1 changed file with 39 additions and 38 deletions.
77 changes: 39 additions & 38 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,45 @@ def foo(message_args, errors):
)
self.assertEqual(errs, [])

def test_variable_reuse_for_arg_lookup(self):
code, errs = compile_messages_to_python(
"""
example = My name is { $name ->
[Peter] Peter11
*[other] Jane11
}
My gender is { $name ->
[Peter] Male
*[other] Female
}
""",
self.locale,
)
assert not errs
# $name should only be looked up once
self.assertCodeEqual(
code,
"""
def example(message_args, errors):
try:
_arg = message_args['name']
except (LookupError, TypeError):
errors.append(FluentReferenceError('<string>:2:24: Unknown external: name'))
_arg = FluentNone('name')
_plural_form = plural_form_for_number(_arg)
if _arg == 'Peter':
_ret = 'Peter11'
else:
_ret = 'Jane11'
_plural_form2 = plural_form_for_number(_arg)
if _arg == 'Peter':
_ret2 = 'Male'
else:
_ret2 = 'Female'
return 'My name is ' + _ret + '\\nMy gender is ' + _ret2
""",
)

# TODO - eliminate unused assignments e.g. `_plural_form = plural_form_for_number(_arg)` is unneeded
# def test_unused_assignments(self):
# code, errs = compile_messages_to_python("""
Expand Down Expand Up @@ -1278,41 +1317,3 @@ def test_non_unique_escaper(self):
self.locale,
escapers=[html_escaper, html_escaper],
)

def test_variable_reuse_for_arg_lookup(self):
code, errs = self.compile_messages(
"""
example = My name is { $name ->
[Peter] Peter11
*[other] Jane11
}
My gender is { $name ->
[Peter] Male
*[other] Female
}
"""
)
assert not errs
# $name should only be looked up once
self.assertCodeEqual(
code,
"""
def example(message_args, errors):
try:
_arg = message_args['name']
except (LookupError, TypeError):
errors.append(FluentReferenceError('<string>:2:24: Unknown external: name'))
_arg = FluentNone('name')
_plural_form = plural_form_for_number(_arg)
if _arg == 'Peter':
_ret = 'Peter11'
else:
_ret = 'Jane11'
_plural_form2 = plural_form_for_number(_arg)
if _arg == 'Peter':
_ret2 = 'Male'
else:
_ret2 = 'Female'
return f'My name is {_ret}\\nMy gender is {_ret2}'
""",
)

0 comments on commit 19aa241

Please sign in to comment.