コード例 #1
0
ファイル: test_strutils.py プロジェクト: zzzz123321/boltons
 def test_substitutions_in_word(self):
     """Test replacing multiple values that are substrings of a word."""
     m = strutils.MultiReplace({
         r'cat': 'kedi',
         r'purple': 'mor',
     })
     self.assertEqual(m.sub('Thecatispurple'), 'Thekediismor')
コード例 #2
0
ファイル: test_strutils.py プロジェクト: zzzz123321/boltons
 def test_simple_substitutions(self):
     """Test replacing multiple values."""
     m = strutils.MultiReplace({
         r'cat': 'kedi',
         r'purple': 'mor',
     })
     self.assertEqual(m.sub('The cat is purple'), 'The kedi is mor')
コード例 #3
0
ファイル: test_strutils.py プロジェクト: zzzz123321/boltons
 def test_substitutions_with_regex_chars(self):
     """Test replacing values that have special regex characters."""
     m = strutils.MultiReplace({
         'cat.+': 'kedi',
         r'purple': 'mor',
     })
     self.assertEqual(m.sub('The cat.+ is purple'), 'The kedi is mor')
コード例 #4
0
ファイル: test_strutils.py プロジェクト: zzzz123321/boltons
 def test_sub_with_list(self):
     """Test substitutions from an iterable instead of a dictionary."""
     m = strutils.MultiReplace([
         (r'cat', 'kedi'),
         (r'purple', 'mor'),
         (r'q\w+?t', 'dinglehopper'),
     ],
                               regex=True)
     self.assertEqual(m.sub('The purple cat ate a quart of jelly'),
                      'The mor kedi ate a dinglehopper of jelly')
コード例 #5
0
ファイル: test_strutils.py プロジェクト: zzzz123321/boltons
 def test_sub_with_compiled_regex(self):
     """Test substitutions where some regular expressiosn are compiled."""
     exp = re.compile(r'q\w+?t')
     m = strutils.MultiReplace([
         (r'cat', 'kedi'),
         (r'purple', 'mor'),
         (exp, 'dinglehopper'),
     ])
     self.assertEqual(m.sub('The purple cat ate a quart of jelly'),
                      'The mor kedi ate a dinglehopper of jelly')
コード例 #6
0
 def test_sub_with_regex(self):
     """Test substitutions with a regular expression."""
     m = strutils.MultiReplace({
         r'cat': 'kedi',
         r'purple': 'mor',
         r'q\w+?t': 'dinglehopper'
     }, regex=True)
     self.assertEqual(
         m.sub('The purple cat ate a quart of jelly'),
         'The mor kedi ate a dinglehopper of jelly'
     )