Skip to content

Commit

Permalink
fix tests when using Python 3.9a6
Browse files Browse the repository at this point in the history
In Python 3.9a6 integer values for future flags were changed to prevent
collision with compiler flags. We need to retrieve these at runtime so
the test suite works with Python <= 3.8 as well as Python 3.9.
  • Loading branch information
FelixSchwarz authored and akx committed May 5, 2020
1 parent 167b714 commit 7bdaa28
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://babel.edgewall.org/log/.

import __future__
import unittest

import pytest
Expand All @@ -20,6 +21,12 @@
from babel.util import parse_future_flags


class _FF:
division = __future__.division.compiler_flag
print_function = __future__.print_function.compiler_flag
with_statement = __future__.with_statement.compiler_flag
unicode_literals = __future__.unicode_literals.compiler_flag

def test_distinct():
assert list(util.distinct([1, 2, 1, 3, 4, 4])) == [1, 2, 3, 4]
assert list(util.distinct('foobar')) == ['f', 'o', 'b', 'a', 'r']
Expand Down Expand Up @@ -70,25 +77,25 @@ def test_parse_encoding_non_ascii():
from __future__ import print_function,
division, with_statement,
unicode_literals
''', 0x10000 | 0x2000 | 0x8000 | 0x20000),
''', _FF.print_function | _FF.division | _FF.with_statement | _FF.unicode_literals),
('''
from __future__ import print_function, division
print('hello')
''', 0x10000 | 0x2000),
''', _FF.print_function | _FF.division),
('''
from __future__ import print_function, division, unknown,,,,,
print 'hello'
''', 0x10000 | 0x2000),
''', _FF.print_function | _FF.division),
('''
from __future__ import (
print_function,
division)
''', 0x10000 | 0x2000),
''', _FF.print_function | _FF.division),
('''
from __future__ import \\
print_function, \\
division
''', 0x10000 | 0x2000),
''', _FF.print_function | _FF.division),
])
def test_parse_future(source, result):
fp = BytesIO(source.encode('latin-1'))
Expand Down

0 comments on commit 7bdaa28

Please sign in to comment.