~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/module/_sre/test/support_test_app_sre.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Support functions for app-level _sre tests."""
 
2
import locale, _sre
 
3
from sre_constants import OPCODES, ATCODES, CHCODES
 
4
 
 
5
def encode_literal(string):
 
6
    opcodes = []
 
7
    for character in string:
 
8
        opcodes.extend([OPCODES["literal"], ord(character)])
 
9
    return opcodes
 
10
 
 
11
def assert_match(opcodes, strings):
 
12
    assert_something_about_match(lambda x: x, opcodes, strings)
 
13
 
 
14
def assert_no_match(opcodes, strings):
 
15
    assert_something_about_match(lambda x: not x, opcodes, strings)
 
16
 
 
17
def assert_something_about_match(assert_modifier, opcodes, strings):
 
18
    if isinstance(strings, str):
 
19
        strings = [strings]
 
20
    for string in strings:
 
21
        assert assert_modifier(search(opcodes, string))
 
22
 
 
23
def search(opcodes, string):
 
24
    pattern = _sre.compile("ignore", 0, opcodes, 0, {}, None)
 
25
    return pattern.search(string)
 
26
 
 
27
def void_locale():
 
28
    locale.setlocale(locale.LC_ALL, (None, None))
 
29
 
 
30
def assert_lower_equal(tests, flags):
 
31
    for arg, expected in tests:
 
32
        assert ord(expected) == _sre.getlower(ord(arg), flags)