Пример #1
0
 def test_count(self):
     assert self.obj.count(Str.green('o'), 2,
                           4) == self.raw.count('o', 2, 4)
     assert self.obj.count('x') == self.raw.count('x')
     assert self.obj.count(Str.red('x')) == 3
     assert self.obj.count(Str.red('x')) < self.raw.count('x')
     assert self.obj.count(Str.green('oo')) == 1
     assert self.obj.count(Str.red('o') + Str.green('o')) == 0
     assert self.obj.count(Str.green('o') + Str.red('o')) == 1
Пример #2
0
 def test_rpartition(self):
     assert self.obj.rpartition('x') == self.raw.rpartition('x')
     assert self.obj.rpartition(Str.red('x')) == (self.obj[:-1],
                                                  self.obj[-1], '')
     assert self.obj.rpartition(Str.red('x')) != self.obj.rpartition(
         Str.green('x'))
     assert self.obj.rpartition(Str.green('o')) == (self.obj[:8],
                                                    self.obj[8:-2],
                                                    self.obj[-2:])
     assert self.obj.rpartition(Str.blue('x')) == ('', '', self.obj[:])
Пример #3
0
 def test_partition(self):
     assert self.obj.partition('x') == self.raw.partition('x')
     assert self.obj.partition(Str.red('x')) == ('', self.obj[:1],
                                                 self.obj[1:])
     assert self.obj.partition(Str.red('x')) != self.obj.partition(
         Str.green('x'))
     assert self.obj.partition(Str.green('o')) == (self.obj[:2],
                                                   self.obj[2:3],
                                                   self.obj[3:])
     assert self.obj.partition(Str.blue('x')) == (self.obj[:], '', '')
Пример #4
0
 def test_rsplit(self):
     assert self.obj.rsplit('x') == self.raw.rsplit('x')
     assert self.obj.rsplit(Str.magenta('ß')) == self.raw.rsplit('ß')
     assert self.obj.rsplit(Str.red('o')) == [self.obj[:-2], self.obj[-1]]
     assert self.obj.rsplit(
         Str.green('o')) == [self.obj[:2], '', self.obj[4:8], self.obj[9:]]
     assert self.obj.rsplit(Str.green('o'), 1) != self.raw.rsplit('o', 1)
     assert self.obj.rsplit(Str.green('o'), 2) != self.raw.rsplit('o', 2)
     assert self.obj.rsplit(Str.green('o'), 3) != self.raw.rsplit('o', 3)
     assert self.obj.rsplit(Str.green('o'), 4) != self.raw.rsplit('o', 4)
Пример #5
0
 def test_replace(self):
     assert self.obj.replace('o', 'XX') == self.raw.replace('o', 'XX')
     assert self.obj.replace(Str.blue('A'),
                             'XX') == self.raw.replace('A', 'XX')
     assert self.obj.replace(Str.red('o'), 'XX') != self.raw.replace(
         'o', 'XX')
     assert self.obj.replace('o', Str.red('x')) == self.obj.replace(
         'o', Str.red('x'))
     assert self.obj.replace('o', Str.red('x')) != self.obj.replace(
         'o', Str.blue('x'))
     assert self.obj.replace(Str.red('x'), 'o') != self.obj.replace(
         Str.red('x'), Str.blue('o'))
     assert self.obj.replace(Str.red('x'), 'o') == self.obj.replace(
         Str.red('x'), Str('o'))
     assert self.obj.replace(Str.green('o'), 'x') != self.obj.replace(
         'o', 'x', 2)
     assert self.obj.replace(Str.green('o'),
                             'x') == self.obj.replace('o', 'x', 3)
Пример #6
0
 def test_endswith(self):
     assert self.obj.endswith('xxoo') is False
     assert self.obj.endswith('xoox') is True
     assert self.obj.endswith(Str.green('xo') + Str.red('ox')) is True
     assert self.obj.endswith(Str.red('xo') + Str.green('ox')) is False
Пример #7
0
 def test_strip(self):
     assert self.obj.strip(Str.green('o') +
                           Str.red('x')) != self.raw.strip('o' + 'x')
     assert self.obj.strip(Str.green('o') + Str.red('x')) == self.obj[4:-1]
Пример #8
0
 def test_rstrip(self):
     assert self.obj.rstrip(Str.green('o') +
                            Str.red('x')) == self.raw.rstrip('x')
     assert self.obj.rstrip(Str.green('o') + Str.red('x')) == self.obj[:-1]
Пример #9
0
 def test_rfind(self):
     assert self.obj.rfind('echoshoot') == -1
     assert self.obj.rfind(Str.green('xo')) == 7
     assert self.obj.rfind(Str.red('x') + Str.green('o')) == 1
     assert self.obj.rfind('xo') == 7
Пример #10
0
 def test_rindex(self):
     with pytest.raises(ValueError):
         self.obj.rindex('echoshoot')
     assert self.obj.rindex(Str.green('xo')) == 7
     assert self.obj.rindex(Str.red('x') + Str.green('o')) == 1
     assert self.obj.rindex('xo') == 7