예제 #1
0
    def test_invalid_range(self):
        with self.assertRaises(ValueError):
            sorted(expand_alphanumeric_pattern('r[8-]a'))

        with self.assertRaises(ValueError):
            sorted(expand_alphanumeric_pattern('r[-8]a'))

        with self.assertRaises(ValueError):
            sorted(expand_alphanumeric_pattern('r[8--9]a'))
예제 #2
0
    def test_invalid_set(self):
        with self.assertRaises(ValueError):
            sorted(expand_alphanumeric_pattern('r[a]a'))

        with self.assertRaises(ValueError):
            sorted(expand_alphanumeric_pattern('r[a,]a'))

        with self.assertRaises(ValueError):
            sorted(expand_alphanumeric_pattern('r[,a]a'))

        with self.assertRaises(ValueError):
            sorted(expand_alphanumeric_pattern('r[a,,b]a'))
예제 #3
0
    def test_set_multichar(self):
        input = '[ra,tb]1a'
        output = sorted([
            'ra1a',
            'tb1a',
        ])

        self.assertEqual(sorted(expand_alphanumeric_pattern(input)), output)
예제 #4
0
    def test_set(self):
        input = '[r,t]1a'
        output = sorted([
            'r1a',
            't1a',
        ])

        self.assertEqual(sorted(expand_alphanumeric_pattern(input)), output)
예제 #5
0
    def test_range_numberic(self):
        input = 'r[9-11]a'
        output = sorted([
            'r9a',
            'r10a',
            'r11a',
        ])

        self.assertEqual(sorted(expand_alphanumeric_pattern(input)), output)
예제 #6
0
    def test_multiple_sets(self):
        input = '[ra,tb]1[ax,by]'
        output = sorted([
            'ra1ax',
            'ra1by',
            'tb1ax',
            'tb1by',
        ])

        self.assertEqual(sorted(expand_alphanumeric_pattern(input)), output)
예제 #7
0
    def test_set_and_range(self):
        input = '[ra,tb]1[a-c]'
        output = sorted([
            'ra1a',
            'ra1b',
            'ra1c',
            'tb1a',
            'tb1b',
            'tb1c',
        ])

        self.assertEqual(sorted(expand_alphanumeric_pattern(input)), output)
예제 #8
0
    def test_multiple_ranges(self):
        input = '[r-t]1[a-b]'
        output = sorted([
            'r1a',
            'r1b',
            's1a',
            's1b',
            't1a',
            't1b',
        ])

        self.assertEqual(sorted(expand_alphanumeric_pattern(input)), output)
예제 #9
0
def expand_pattern(value):
    if not value:
        return ['']
    if re.search(ALPHANUMERIC_EXPANSION_PATTERN, value):
        return list(expand_alphanumeric_pattern(value))
    return [value]
예제 #10
0
 def test_invalid_range_len(self):
     with self.assertRaises(forms.ValidationError):
         sorted(expand_alphanumeric_pattern('r[a-bb]a'))
예제 #11
0
 def test_invalid_range_bounds(self):
     self.assertEqual(sorted(expand_alphanumeric_pattern('r[9-8]a')), [])
     self.assertEqual(sorted(expand_alphanumeric_pattern('r[b-a]a')), [])
예제 #12
0
 def test_invalid_range_alphanumeric(self):
     self.assertEqual(sorted(expand_alphanumeric_pattern('r[9-a]a')), [])
     self.assertEqual(sorted(expand_alphanumeric_pattern('r[a-9]a')), [])
예제 #13
0
 def test_invalid_non_pattern(self):
     with self.assertRaises(ValueError):
         sorted(expand_alphanumeric_pattern('r9a'))