diff options
author | Aarni Koskela <akx@iki.fi> | 2017-08-21 16:25:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-21 16:25:51 +0300 |
commit | 231d337b569b15b9437cfefee6584ad8d54d0cd3 (patch) | |
tree | 141b07954798ee16a819475cfa458664a0d76a61 /tests/test_util.py | |
parent | 1da04fd0af20162fe4e2b503a5fcae8f25267010 (diff) | |
download | babel-231d337b569b15b9437cfefee6584ad8d54d0cd3.tar.gz |
Parse multi-line __future__ imports better (#519)
Augments #426
Augments #427
Augments #510
Diffstat (limited to 'tests/test_util.py')
-rw-r--r-- | tests/test_util.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_util.py b/tests/test_util.py index 068a102..4c769be 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -13,8 +13,11 @@ import unittest +import pytest + from babel import util from babel._compat import BytesIO +from babel.util import parse_future_flags def test_distinct(): @@ -69,3 +72,34 @@ def test_parse_encoding_undefined(): def test_parse_encoding_non_ascii(): assert parse_encoding(u'K\xf6ln') is None + + +@pytest.mark.parametrize('source, result', [ + (''' +from __future__ import print_function, + division, with_statement, + unicode_literals +''', 0x10000 | 0x2000 | 0x8000 | 0x20000), + (''' +from __future__ import print_function, division +print('hello') +''', 0x10000 | 0x2000), + (''' +from __future__ import print_function, division, unknown,,,,, +print 'hello' +''', 0x10000 | 0x2000), + (''' +from __future__ import ( + print_function, + division) +''', 0x10000 | 0x2000), + (''' +from __future__ import \\ + print_function, \\ + division +''', 0x10000 | 0x2000), +]) +def test_parse_future(source, result): + fp = BytesIO(source.encode('latin-1')) + flags = parse_future_flags(fp) + assert flags == result |