コード例 #1
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
    def test_maxsplit__positive(self):
        maxsplit = self.MAXSPLIT  # just to make expressions fit

        self.assertEquals(
            self.WORDS[:maxsplit] + [' '.join(self.WORDS[maxsplit:])],
            __unit__.split(self.TEXT, maxsplit=maxsplit))
        self.assertEquals(
            self.SPLIT_BY_X[:maxsplit] +
            ['X'.join(self.SPLIT_BY_X[maxsplit:])],
            __unit__.split(self.STRING, by='X', maxsplit=maxsplit))

        # this works because the first split to perform at 'X' rather than 'a'
        self.assertEquals(
            self.SPLIT_BY_X[:maxsplit] +
            ['X'.join(self.SPLIT_BY_X[maxsplit:])],
            __unit__.split(self.STRING, by=('a', 'X'), maxsplit=maxsplit))

        # here, first split is at 'bar'
        sep_index = self.STRING.find('bar')
        string_sans_sep = self.STRING.replace('bar', '')
        self.assertEquals(
            [self.STRING[:sep_index], string_sans_sep[sep_index:]],
            __unit__.split(self.STRING,
                           by=re.compile(self.REGEX),
                           maxsplit=maxsplit))
コード例 #2
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_maxsplit__none(self):
     self.assertEquals(self.WORDS, __unit__.split(self.TEXT, maxsplit=None))
     self.assertEquals(
         self.SPLIT_BY_A_OR_X,
         __unit__.split(self.STRING, by=('a', 'X'), maxsplit=None))
     self.assertEquals(
         self.SPLIT_BY_REGEX,
         __unit__.split(self.STRING,
                        by=re.compile(self.REGEX), maxsplit=None))
コード例 #3
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_maxsplit__none(self):
     self.assertEquals(self.WORDS, __unit__.split(self.TEXT, maxsplit=None))
     self.assertEquals(
         self.SPLIT_BY_A_OR_X,
         __unit__.split(self.STRING, by=('a', 'X'), maxsplit=None))
     self.assertEquals(
         self.SPLIT_BY_REGEX,
         __unit__.split(self.STRING,
                        by=re.compile(self.REGEX),
                        maxsplit=None))
コード例 #4
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_maxsplit__zero(self):
     self.assertEquals(
         [self.TEXT], __unit__.split(self.TEXT, by=None, maxsplit=0))
     self.assertEquals(
         [self.STRING], __unit__.split(self.STRING, by='X', maxsplit=0))
     self.assertEquals(
         [self.STRING],
         __unit__.split(self.STRING, by=('a', 'X'), maxsplit=0))
     self.assertEquals(
         [self.STRING],
         __unit__.split(self.STRING, by=re.compile(self.REGEX), maxsplit=0))
コード例 #5
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_maxsplit__zero(self):
     self.assertEquals([self.TEXT],
                       __unit__.split(self.TEXT, by=None, maxsplit=0))
     self.assertEquals([self.STRING],
                       __unit__.split(self.STRING, by='X', maxsplit=0))
     self.assertEquals([self.STRING],
                       __unit__.split(self.STRING,
                                      by=('a', 'X'),
                                      maxsplit=0))
     self.assertEquals([self.STRING],
                       __unit__.split(self.STRING,
                                      by=re.compile(self.REGEX),
                                      maxsplit=0))
コード例 #6
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_maxsplit__non_integer(self):
     with self.assertRaises(TypeError):
         __unit__.split(self.TEXT, maxsplit=object())
     with self.assertRaises(TypeError):
         __unit__.split(self.STRING, by='X', maxsplit=object())
     with self.assertRaises(TypeError):
         __unit__.split(self.STRING, by=('a', 'X'), maxsplit=object())
     with self.assertRaises(TypeError):
         __unit__.split(
             self.STRING, by=re.compile(self.REGEX), maxsplit=object())
コード例 #7
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_maxsplit__non_integer(self):
     with self.assertRaises(TypeError):
         __unit__.split(self.TEXT, maxsplit=object())
     with self.assertRaises(TypeError):
         __unit__.split(self.STRING, by='X', maxsplit=object())
     with self.assertRaises(TypeError):
         __unit__.split(self.STRING, by=('a', 'X'), maxsplit=object())
     with self.assertRaises(TypeError):
         __unit__.split(self.STRING,
                        by=re.compile(self.REGEX),
                        maxsplit=object())
コード例 #8
0
ファイル: test_strings.py プロジェクト: Xion/taipan
    def test_maxsplit__positive(self):
        maxsplit = self.MAXSPLIT  # just to make expressions fit

        self.assertEquals(
            self.WORDS[:maxsplit] + [' '.join(self.WORDS[maxsplit:])],
            __unit__.split(self.TEXT, maxsplit=maxsplit))
        self.assertEquals(
            self.SPLIT_BY_X[:maxsplit] + ['X'.join(self.SPLIT_BY_X[maxsplit:])],
            __unit__.split(self.STRING, by='X', maxsplit=maxsplit))

        # this works because the first split to perform at 'X' rather than 'a'
        self.assertEquals(
            self.SPLIT_BY_X[:maxsplit] + ['X'.join(self.SPLIT_BY_X[maxsplit:])],
            __unit__.split(self.STRING, by=('a', 'X'), maxsplit=maxsplit))

        # here, first split is at 'bar'
        sep_index = self.STRING.find('bar')
        string_sans_sep = self.STRING.replace('bar', '')
        self.assertEquals(
            [self.STRING[:sep_index], string_sans_sep[sep_index:]],
            __unit__.split(
                self.STRING, by=re.compile(self.REGEX), maxsplit=maxsplit))
コード例 #9
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_by__none__one_word(self):
     self.assertEquals([self.STRING], __unit__.split(self.STRING, by=None))
コード例 #10
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_string__some_string__no_separator(self):
     self.assertEquals([self.STRING], __unit__.split(self.STRING))
コード例 #11
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_by__none__words(self):
     self.assertEquals(self.WORDS, __unit__.split(self.TEXT, by=None))
コード例 #12
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_by__invalid_tuple(self):
     with self.assertRaises(TypeError):
         __unit__.split(self.STRING, by=(42, 'a', 'X'))
コード例 #13
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_string__empty__no_separator(self):
     # result contingent on TODO inside the ``split`` function
     self.assertEquals([], __unit__.split(''))
コード例 #14
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_by__empty_generator(self):
     with self.assertRaises(ValueError) as r:
         __unit__.split(self.STRING, by=(x for x in ()))
     self.assertIn("empty", str(r.exception))
コード例 #15
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_by__multiple_strings(self):
     self.assertEquals(self.SPLIT_BY_A_OR_X,
                       __unit__.split(self.STRING, by=('a', 'X')))
コード例 #16
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_string__some_string__no_separator(self):
     self.assertEquals([self.STRING], __unit__.split(self.STRING))
コード例 #17
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_by__empty_tuple(self):
     with self.assertRaises(ValueError) as r:
         __unit__.split(self.STRING, by=())
     self.assertIn("empty", str(r.exception))
コード例 #18
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_by__allegedly_regex_string(self):
     # regex supplied as string should be treated as string,
     # (in this case, it results in no splits whatsoever)
     self.assertEquals(
         [self.STRING], __unit__.split(self.STRING, by=self.REGEX))
コード例 #19
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_by__none__words(self):
     self.assertEquals(self.WORDS, __unit__.split(self.TEXT, by=None))
コード例 #20
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_by__empty_regex(self):
     with self.assertRaises(ValueError) as r:
         __unit__.split(self.STRING, by=re.compile(''))
     self.assertIn("empty", str(r.exception))
コード例 #21
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_by__regex_object(self):
     self.assertEquals(
         self.SPLIT_BY_REGEX,
         __unit__.split(self.STRING, by=re.compile(self.REGEX)))
コード例 #22
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_by__multiple_strings(self):
     self.assertEquals(
         self.SPLIT_BY_A_OR_X, __unit__.split(self.STRING, by=('a', 'X')))
コード例 #23
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_by__single_string(self):
     self.assertEquals(self.SPLIT_BY_X, __unit__.split(self.STRING, by='X'))
コード例 #24
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_by__empty_regex(self):
     with self.assertRaises(ValueError) as r:
         __unit__.split(self.STRING, by=re.compile(''))
     self.assertIn("empty", str(r.exception))
コード例 #25
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_by__empty_tuple(self):
     with self.assertRaises(ValueError) as r:
         __unit__.split(self.STRING, by=())
     self.assertIn("empty", str(r.exception))
コード例 #26
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_string__empty__no_separator(self):
     # result contingent on TODO inside the ``split`` function
     self.assertEquals([], __unit__.split(''))
コード例 #27
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_by__invalid_tuple(self):
     with self.assertRaises(TypeError):
         __unit__.split(self.STRING, by=(42, 'a', 'X'))
コード例 #28
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_by__single_string(self):
     self.assertEquals(self.SPLIT_BY_X, __unit__.split(self.STRING, by='X'))
コード例 #29
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_by__regex_object(self):
     self.assertEquals(
         self.SPLIT_BY_REGEX,
         __unit__.split(self.STRING, by=re.compile(self.REGEX)))
コード例 #30
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_by__empty_generator(self):
     with self.assertRaises(ValueError) as r:
         __unit__.split(self.STRING, by =(x for x in ()))
     self.assertIn("empty", str(r.exception))
コード例 #31
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_by__allegedly_regex_string(self):
     # regex supplied as string should be treated as string,
     # (in this case, it results in no splits whatsoever)
     self.assertEquals([self.STRING],
                       __unit__.split(self.STRING, by=self.REGEX))
コード例 #32
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_string__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.split(object())
コード例 #33
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_string__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.split(object())
コード例 #34
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_by__none__one_word(self):
     self.assertEquals([self.STRING], __unit__.split(self.STRING, by=None))
コード例 #35
0
ファイル: test_strings.py プロジェクト: movermeyer/taipan
 def test_string__none(self):
     with self.assertRaises(TypeError):
         __unit__.split(None)
コード例 #36
0
ファイル: test_strings.py プロジェクト: Xion/taipan
 def test_string__none(self):
     with self.assertRaises(TypeError):
         __unit__.split(None)