Esempio n. 1
0
 def test_plugin_registration(self):
     # Not comparing as sets to be able to confirm there are no duplicates
     # in the plugin registry
     assert_equal(
         sorted(self.HTTPMethod._plugin_registry),
         sorted(self.desired_http_method_plugins.classes)
     )
Esempio n. 2
0
 def test_flag_ignorecase(self):
     rgx_ci = cffi_re2.compile(r'a(b+)$', flags=cffi_re2.IGNORECASE)
     rgx_cs = cffi_re2.compile(r'a(b+)$')
     # Check case sensitive
     assert_is_none(rgx_cs.match("AB"))
     assert_is_none(rgx_cs.match("Ab"))
     assert_is_none(rgx_cs.match("aB"))
     assert_is_none(rgx_cs.match("aBb"))
     assert_is_none(rgx_cs.match("abB"))
     assert_is_not_none(rgx_cs.match("ab"))
     assert_is_not_none(rgx_cs.match("abb"))
     # Check case insensitive
     assert_is_not_none(rgx_ci.match("AB"))
     assert_is_not_none(rgx_ci.match("Ab"))
     assert_is_not_none(rgx_ci.match("aB"))
     assert_is_not_none(rgx_ci.match("aBb"))
     assert_is_not_none(rgx_ci.match("abB"))
     assert_is_not_none(rgx_ci.match("ab"))
     assert_is_not_none(rgx_ci.match("abb"))
     # Official example
     assert_equal(
         cffi_re2.sub(r'\sAND\s',
                      ' & ',
                      'Baked Beans And Spam',
                      flags=cffi_re2.IGNORECASE), 'Baked Beans & Spam')
Esempio n. 3
0
 def test_module_level_functions(self):
     """
     Quick test of module-level functions.
     These are generally expected to call the compiled counterparts,
      so these tests do not check all aspects
     """
     assert_equal(cffi_re2.findall(r'a(b+)', "abbcdefabbbbca"), ["bb", "bbbb"])
     assert_equal(cffi_re2.sub(r'b+', '', 'abbcbbd'), 'acd')
     assert_is_not_none(cffi_re2.search(r'b+', 'abbcbbd'))
     assert_is_none(cffi_re2.match(r'b+', 'abbcbbd'))
     assert_is_not_none(cffi_re2.match(r'b+', 'bbbbb'))
Esempio n. 4
0
 def test_module_level_functions(self):
     """
     Quick test of module-level functions.
     These are generally expected to call the compiled counterparts,
      so these tests do not check all aspects
     """
     assert_equal(cffi_re2.findall(r'a(b+)', "abbcdefabbbbca"),
                  ["bb", "bbbb"])
     assert_equal(cffi_re2.sub(r'b+', '', 'abbcbbd'), 'acd')
     assert_is_not_none(cffi_re2.search(r'b+', 'abbcbbd'))
     assert_is_none(cffi_re2.match(r'b+', 'abbcbbd'))
     assert_is_not_none(cffi_re2.match(r'b+', 'bbbbb'))
Esempio n. 5
0
    def test_sub_function(self):
        # Python re example
        def dashrepl(matchobj):
            if matchobj.group(0) == '-':
                return ' '
            else:
                return '-'

        assert_equal(cffi_re2.sub(r'-{1,2}', dashrepl, 'pro-gram--files'),
                     'pro gram-files')
        #
        print()
        assert_equal(cffi_re2.sub(r'-{1,2}', dashrepl, 'pro----gram-files'),
                     'pro--gram files')
Esempio n. 6
0
    def test_sub_function(self):
        # Python re example
        def dashrepl(matchobj):
            if matchobj.group(0) == '-':
                return ' '
            else:
                return '-'

        assert_equal(cffi_re2.sub(r'-{1,2}', dashrepl, 'pro-gram--files'),
                     'pro gram-files')
        #
        print()
        assert_equal(cffi_re2.sub(r'-{1,2}', dashrepl, 'pro----gram-files'),
                     'pro--gram files')
Esempio n. 7
0
 def test_findall_overlapping(self):
     """Check overlapping matches with findall"""
     # Prerequisited
     assert_equal(cffi_re2.findall(r'-{1,2}', 'program-files'), ['-'])
     assert_equal(cffi_re2.findall(r'-{1,2}', 'pro--gram-files'), ['--', '-'])
     assert_equal(cffi_re2.findall(r'-{1,2}', 'pro---gram-files'), ['--', '-', '-'])
     # Actual test
     assert_equal(cffi_re2.findall(r'-{1,2}', 'pro----gram-files'), ['--', '--', '-'])
Esempio n. 8
0
 def test_findall_subgroups(self):
     mo = cffi_re2.findall(r'ab+', "abbcdefabbbbca")
     assert_equal(mo, ["abb", "abbbb"])
     mo = cffi_re2.findall(r'a(b+)', "abbcdefabbbbca")
     assert_equal(mo, ["bb", "bbbb"])
     mo = cffi_re2.findall(r'(a)(b+)', "abbcdefabbbbca")
     assert_equal(mo, [("a", "bb"), ("a", "bbbb")])
     mo = cffi_re2.findall(r'(a)(b)(b+)', "abbcdefabbbbca")
     assert_equal(mo, [("a", "b", "b"), ("a", "b", "bbb")])
Esempio n. 9
0
 def test_findall_subgroups(self):
     mo = cffi_re2.findall(r'ab+', "abbcdefabbbbca")
     assert_equal(mo, ["abb", "abbbb"])
     mo = cffi_re2.findall(r'a(b+)', "abbcdefabbbbca")
     assert_equal(mo, ["bb", "bbbb"])
     mo = cffi_re2.findall(r'(a)(b+)', "abbcdefabbbbca")
     assert_equal(mo, [("a", "bb"), ("a", "bbbb")])
     mo = cffi_re2.findall(r'(a)(b)(b+)', "abbcdefabbbbca")
     assert_equal(mo, [("a", "b", "b"), ("a", "b", "bbb")])
Esempio n. 10
0
 def test_findall_overlapping(self):
     """Check overlapping matches with findall"""
     # Prerequisited
     assert_equal(cffi_re2.findall(r'-{1,2}', 'program-files'), ['-'])
     assert_equal(cffi_re2.findall(r'-{1,2}', 'pro--gram-files'),
                  ['--', '-'])
     assert_equal(cffi_re2.findall(r'-{1,2}', 'pro---gram-files'),
                  ['--', '-', '-'])
     # Actual test
     assert_equal(cffi_re2.findall(r'-{1,2}', 'pro----gram-files'),
                  ['--', '--', '-'])
def test_integrate_options():
    integral = BaseIntegral.coerce(1)  #@UndefinedVariable
    beam_type = BaseBeamType.coerce(1)  #@UndefinedVariable

    def base_integrate(**kwargs):
        return integrate(integral,
                         beam_type,
                         a=1.,
                         m=1,
                         n=1,
                         decimal_precision=tests.DECIMAL_PRECISION,
                         **kwargs)

    # When called with `error=True` `integrate` should return a `(result, error)` tuple
    result_with_error_info = base_integrate(error=True)
    assert_is(type(result_with_error_info), tuple)

    # `integrate` should return the same `result` regardless of the `error` flag
    assert_equal(base_integrate(), result_with_error_info[0])
Esempio n. 12
0
 def test_flag_ignorecase(self):
     rgx_ci = cffi_re2.compile(r'a(b+)$', flags=cffi_re2.IGNORECASE)
     rgx_cs = cffi_re2.compile(r'a(b+)$')
     # Check case sensitive
     assert_is_none(rgx_cs.match("AB"))
     assert_is_none(rgx_cs.match("Ab"))
     assert_is_none(rgx_cs.match("aB"))
     assert_is_none(rgx_cs.match("aBb"))
     assert_is_none(rgx_cs.match("abB"))
     assert_is_not_none(rgx_cs.match("ab"))
     assert_is_not_none(rgx_cs.match("abb"))
     # Check case insensitive
     assert_is_not_none(rgx_ci.match("AB"))
     assert_is_not_none(rgx_ci.match("Ab"))
     assert_is_not_none(rgx_ci.match("aB"))
     assert_is_not_none(rgx_ci.match("aBb"))
     assert_is_not_none(rgx_ci.match("abB"))
     assert_is_not_none(rgx_ci.match("ab"))
     assert_is_not_none(rgx_ci.match("abb"))
     # Official example
     assert_equal(cffi_re2.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=cffi_re2.IGNORECASE),
                  'Baked Beans & Spam')
Esempio n. 13
0
    def test_plugin_info(self):
        actual_plugins = self.HTTPMethod.plugins.copy()

        # Special case for any instances related information
        assert_equal(
            set(type(obj) for obj in actual_plugins.pop('instances')),
            self.desired_http_method_plugins.classes
        )
        assert_equal(
            dict((k, type(v)) for k, v in actual_plugins.pop('id_to_instance').items()),
            self.desired_http_method_plugins.id_to_class
        )
        assert_equal(
            [type(obj) for obj in actual_plugins.pop('instances_sorted_by_id')],
            self.desired_http_method_plugins.pop('classes_sorted_by_id')
        )

        # Compare the remaining plugin information directly
        assert_equal(actual_plugins, self.desired_http_method_plugins)
Esempio n. 14
0
 def test_basic_findall(self):
     robj = cffi_re2.compile(r'a(b+)')
     mo = robj.findall("abbcdefabbbbca")
     assert_is_not_none(mo)
     assert_equal(mo, ["bb", "bbbb"])
Esempio n. 15
0
 def test_basic_groups(self):
     robj = cffi_re2.compile(r'a(b+)')
     mo = robj.search("abbc")
     assert_is_not_none(mo)
     assert_equal(mo.groups(), ("bb", ))
Esempio n. 16
0
 def test_sub_basic(self):
     robj = cffi_re2.compile(r'b+')
     assert_equal(robj.sub('', 'abbcbbd'), 'acd')
Esempio n. 17
0
 def test_re_compatibility(self):
     """Test compatibility with the Python re library"""
     #
     cm = cffi_re2.search(r'a(b+)', "abbc")
     rm = pyre.search(r'a(b+)', "abbc")
     assert_equal(cm.groups(), rm.groups())
     #
     cm = cffi_re2.match(r'b+', 'abbcd')
     rm = pyre.match(r'b+', 'abbcd')
     assert_equal(cm, rm)
     # Match without groups
     cm = cffi_re2.match(r'[abc]+', 'abbcd')
     rm = pyre.match(r'[abc]+', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     # Full match regex should match
     cm = cffi_re2.match(r'([abc]+)', 'abbcd')
     rm = pyre.match(r'([abc]+)', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     assert_equal(cm.group(0), rm.group(0))
     assert_equal(cm.group(1), rm.group(1))
     cm = cffi_re2.match(r'([ab]+)(c+)', 'abbcd')
     rm = pyre.match(r'([ab]+)(c+)', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     assert_equal(cm.group(0), rm.group(0))
     assert_equal(cm.group(1), rm.group(1))
     assert_equal(cm.group(2), rm.group(2))
Esempio n. 18
0
 def test_sub_chinese(self):
     robj = cffi_re2.compile('梦[^一-龥]*幻[^一-龥]*西[^一-龥]*游')
     assert_equal(robj.sub('倩女', '梦幻西游好玩吗?'), u'倩女好玩吗?')
Esempio n. 19
0
 def test_optional_groups(self):
     assert_equal(cffi_re2.findall(r"(foo)?bar", "bar"), [''])
Esempio n. 20
0
 def test_basic_groups(self):
     robj = cffi_re2.compile(r'a(b+)')
     mo = robj.search("abbc")
     assert_is_not_none(mo)
     assert_equal(mo.groups(), ("bb",))
Esempio n. 21
0
 def test_optional_groups(self):
     assert_equal(cffi_re2.findall(r"(foo)?bar", "bar"), [''])
Esempio n. 22
0
 def test_more_x(self):
     assert_is_none(cffi_re2.search(r"<(a|span|div|table)", "Kapazitäten"))
     assert_equal(cffi_re2.findall(r"<(a|span|div|table)", "Kapazitäten"),
                  [])
Esempio n. 23
0
 def test_optional_groups(self):
     result = cffi_re2.search(r"(foo)?bar", "bar")
     print(result.ranges)
     assert_equal(result.group(0), "bar")
     assert_is_none(result.group(1))
     assert_equal(result.groups(), (None,))
Esempio n. 24
0
 def test_sub_chinese(self):
     robj = cffi_re2.compile('梦[^一-龥]*幻[^一-龥]*西[^一-龥]*游')
     assert_equal(robj.sub('倩女', '梦幻西游好玩吗?'), u'倩女好玩吗?')
Esempio n. 25
0
 def test_re_compatibility(self):
     """Test compatibility with the Python re library"""
     #
     cm = cffi_re2.search(r'a(b+)', "abbc")
     rm = pyre.search(r'a(b+)', "abbc")
     assert_equal(cm.groups(), rm.groups())
     #
     cm = cffi_re2.match(r'b+', 'abbcd')
     rm = pyre.match(r'b+', 'abbcd')
     assert_equal(cm, rm)
     # Match without groups
     cm = cffi_re2.match(r'[abc]+', 'abbcd')
     rm = pyre.match(r'[abc]+', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     # Full match regex should match
     cm = cffi_re2.match(r'([abc]+)', 'abbcd')
     rm = pyre.match(r'([abc]+)', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     assert_equal(cm.group(0), rm.group(0))
     assert_equal(cm.group(1), rm.group(1))
     cm = cffi_re2.match(r'([ab]+)(c+)', 'abbcd')
     rm = pyre.match(r'([ab]+)(c+)', 'abbcd')
     assert_equal(cm.groups(), rm.groups())
     assert_equal(cm.group(0), rm.group(0))
     assert_equal(cm.group(1), rm.group(1))
     assert_equal(cm.group(2), rm.group(2))
Esempio n. 26
0
 def test_sub_basic(self):
     robj = cffi_re2.compile(r'b+')
     assert_equal(robj.sub('', 'abbcbbd'), 'acd')
Esempio n. 27
0
 def test_more_x(self):
     assert_is_none(cffi_re2.search(r"<(a|span|div|table)", "Kapazitäten"))
     assert_equal(cffi_re2.findall(r"<(a|span|div|table)", "Kapazitäten"), [])
Esempio n. 28
0
 def test_optional_groups(self):
     result = cffi_re2.search(r"(foo)?bar", "bar")
     print(result.ranges)
     assert_equal(result.group(0), "bar")
     assert_is_none(result.group(1))
     assert_equal(result.groups(), (None, ))
Esempio n. 29
0
 def test_basic_findall(self):
     robj = cffi_re2.compile(r'a(b+)')
     mo = robj.findall("abbcdefabbbbca")
     assert_is_not_none(mo)
     assert_equal(mo, ["bb", "bbbb"])