Skip to content

Commit

Permalink
port unicode tests to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
loechel committed Mar 6, 2017
1 parent 14ee5ed commit ab35bc1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 37 deletions.
37 changes: 0 additions & 37 deletions src/RestrictedPython/tests/testCompile.py

This file was deleted.

44 changes: 44 additions & 0 deletions tests/legacy/test_compile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2006 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################

from RestrictedPython._compat import IS_PY2
from RestrictedPython._compat import IS_PY3

import pytest

if IS_PY2:
from RestrictedPython.RCompile import _niceParse
import compiler

pytestmark = pytest.mark.skipif(
IS_PY3,
reason="legacy tests against old implementation")


source = u"u'Ä väry nice säntänce with umlauts.'"


def test_unicode_source_exec():
assert isinstance(_niceParse(source, "test.py", "exec"),
compiler.ast.Module)


def test_unicode_source_single():
assert isinstance(_niceParse(source, "test.py", "single"),
compiler.ast.Module)


def test_unicode_source_eval():
assert isinstance(_niceParse(source, "test.py", "eval"),
compiler.ast.Expression)
18 changes: 18 additions & 0 deletions tests/test_unicode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
import ast


# Port of file: tests/testCompile.py

def test_unicode_source():
"""
Test if the AST Parsing works with Unicode source.
"""
# TODO: Review is that is really somethin we want to test this way.
# ast.parse is a python core method and should be tested there.
# RestrictedPython.RCompile _niceParse is not reimplemented.
source = u"u'Ä väry nice säntänce with umlauts.'"

assert isinstance(ast.parse(source, "test.py", "exec"), ast.Module)
assert isinstance(ast.parse(source, "test.py", "single"), ast.Interactive)
assert isinstance(ast.parse(source, "test.py", "eval"), ast.Expression)

0 comments on commit ab35bc1

Please sign in to comment.