예제 #1
0
class TestRstr(unittest.TestCase):
    def setUp(self) -> None:
        self.rs = Rstr()

    def test_specific_length(self) -> None:
        assert_matches('^A{5}$', self.rs.rstr('A', 5))

    def test_length_range(self) -> None:
        assert_matches('^A{11,20}$', self.rs.rstr('A', 11, 20))

    def test_custom_alphabet(self) -> None:
        assert_matches('^A{1,10}$', self.rs.rstr('AA'))

    def test_alphabet_as_list(self) -> None:
        assert_matches('^A{1,10}$', self.rs.rstr(['A', 'A']))

    def test_include(self) -> None:
        assert_matches('^[ABC]*@[ABC]*$', self.rs.rstr('ABC', include='@'))

    def test_include_specific_length(self) -> None:
        '''
        Verify including characters doesn't make the string longer than intended.
        '''
        assert_matches('^[ABC@]{5}$', self.rs.rstr('ABC', 5, include='@'))

    def test_exclude(self) -> None:
        for _ in range(0, 100):
            assert 'C' not in self.rs.rstr('ABC', exclude='C')

    def test_include_as_list(self) -> None:
        assert_matches('^[ABC]*@[ABC]*$', self.rs.rstr('ABC', include=['@']))

    def test_exclude_as_list(self) -> None:
        for _ in range(0, 100):
            assert 'C' not in self.rs.rstr('ABC', exclude=['C'])
예제 #2
0
class TestNondigits(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_nondigits(self):
        assert re.match('^\D{1,10}$', self.rs.nondigits())

    def test_nondigits_include(self):
        assert re.match('^\D*@\D*$', self.rs.nondigits(include='@'))

    def test_nondigits_exclude(self):
        for _ in xrange(0, 100):
            assert 'A' not in self.rs.nondigits(exclude='A')
예제 #3
0
class TestLetters(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_letters(self):
        assert re.match('^[a-zA-Z]{1,10}$', self.rs.letters())

    def test_letters_include(self):
        assert re.match('^[a-zA-Z]*@[a-zA-Z]*$', self.rs.letters(include='@'))

    def test_letters_exclude(self):
        for _ in xrange(0, 100):
            assert 'A' not in self.rs.letters(exclude='A')
예제 #4
0
파일: test_rstr.py 프로젝트: sakti/dummygen
class TestLetters(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_letters(self):
        assert re.match('^[a-zA-Z]{1,10}$', self.rs.letters())

    def test_letters_include(self):
        assert re.match('^[a-zA-Z]*@[a-zA-Z]*$', self.rs.letters(include='@'))

    def test_letters_exclude(self):
        for _ in xrange(0, 100):
            assert 'A' not in self.rs.letters(exclude='A')
예제 #5
0
class TestDigits(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_all_digits(self):
        assert re.match('^\d{1,10}$', self.rs.digits())

    def test_digits_include(self):
        assert re.match('^\d*@\d*$', self.rs.digits(include='@'))

    def test_digits_exclude(self):
        for _ in xrange(0, 100):
            assert '5' not in self.rs.digits(exclude='5')
예제 #6
0
파일: test_rstr.py 프로젝트: sakti/dummygen
class TestNondigits(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_nondigits(self):
        assert re.match('^\D{1,10}$', self.rs.nondigits())

    def test_nondigits_include(self):
        assert re.match('^\D*@\D*$', self.rs.nondigits(include='@'))

    def test_nondigits_exclude(self):
        for _ in xrange(0, 100):
            assert 'A' not in self.rs.nondigits(exclude='A')
예제 #7
0
파일: test_rstr.py 프로젝트: sakti/dummygen
class TestDigits(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_all_digits(self):
        assert re.match('^\d{1,10}$', self.rs.digits())

    def test_digits_include(self):
        assert re.match('^\d*@\d*$', self.rs.digits(include='@'))

    def test_digits_exclude(self):
        for _ in xrange(0, 100):
            assert '5' not in self.rs.digits(exclude='5')
예제 #8
0
파일: test_rstr.py 프로젝트: sakti/dummygen
class TestRstr(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_specific_length(self):
        assert re.match('^A{5}$', self.rs.rstr('A', 5))

    def test_length_range(self):
        assert re.match('^A{11,20}$', self.rs.rstr('A', 11, 20))

    def test_custom_alphabet(self):
        assert re.match('^A{1,10}$', self.rs.rstr('AA'))

    def test_alphabet_as_list(self):
        assert re.match('^A{1,10}$', self.rs.rstr(['A', 'A']))

    def test_include(self):
        assert re.match('^[ABC]*@[ABC]*$', self.rs.rstr('ABC', include='@'))

    def test_exclude(self):
        for _ in xrange(0, 100):
            assert 'C' not in self.rs.rstr('ABC', exclude='C')

    def test_include_as_list(self):
        assert re.match('^[ABC]*@[ABC]*$', self.rs.rstr('ABC', include=["@"]))

    def test_exclude_as_list(self):
        for _ in xrange(0, 100):
            assert 'C' not in self.rs.rstr('ABC', exclude=['C'])
예제 #9
0
class TestRstr(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_specific_length(self):
        assert re.match('^A{5}$', self.rs.rstr('A', 5))

    def test_length_range(self):
        assert re.match('^A{11,20}$', self.rs.rstr('A', 11, 20))

    def test_custom_alphabet(self):
        assert re.match('^A{1,10}$', self.rs.rstr('AA'))

    def test_alphabet_as_list(self):
        assert re.match('^A{1,10}$', self.rs.rstr(['A', 'A']))

    def test_include(self):
        assert re.match('^[ABC]*@[ABC]*$', self.rs.rstr('ABC', include='@'))

    def test_exclude(self):
        for _ in xrange(0, 100):
            assert 'C' not in self.rs.rstr('ABC', exclude='C')

    def test_include_as_list(self):
        assert re.match('^[ABC]*@[ABC]*$', self.rs.rstr('ABC', include=["@"]))

    def test_exclude_as_list(self):
        for _ in xrange(0, 100):
            assert 'C' not in self.rs.rstr('ABC', exclude=['C'])
class TestUnambiguous(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_unambiguous(self):
        assert re.match('^[a-km-zA-HJ-NP-Z2-9]{1,10}$', self.rs.unambiguous())

    def test_unambiguous_include(self):
        assert re.match('^[a-km-zA-HJ-NP-Z2-9@]{1,10}$',
                        self.rs.unambiguous(include='@'))

    def test_unambiguous_exclude(self):
        for _ in xrange(0, 100):
            assert 'A' not in self.rs.unambiguous(exclude='A')
예제 #11
0
파일: test_rstr.py 프로젝트: sakti/dummygen
 def setUp(self):
     self.rs = Rstr()
예제 #12
0
 def test_add_alphabet(self):
     rs = Rstr()
     rs.add_alphabet('evens', '02468')
     assert re.match('^[02468]{1,10}$', rs.evens())
예제 #13
0
 def test_add_alphabet(self) -> None:
     rs = Rstr()
     rs.add_alphabet('evens', '02468')
     assert_matches('^[02468]{1,10}$', rs.evens())
예제 #14
0
class TestXeger(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_literals(self):
        pattern = r'foo'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_dot(self):
        """
        Verify that the dot character doesn't produce newlines.
        See: https://bitbucket.org/leapfrogdevelopment/rstr/issue/1/
        """
        pattern = r'.+'
        for i in range(100):
            assert re.match(pattern, self.rs.xeger(pattern))

    def test_digit(self):
        pattern = r'\d'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_nondigits(self):
        pattern = r'\D'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_literal_with_repeat(self):
        pattern = r'A{3}'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_literal_with_range_repeat(self):
        pattern = r'A{2, 5}'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_word(self):
        pattern = r'\w'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_nonword(self):
        pattern = r'\W'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_or(self):
        pattern = r'foo|bar'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_or_with_subpattern(self):
        pattern = r'(foo|bar)'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_range(self):
        pattern = r'[A-F]'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_character_group(self):
        pattern = r'[ABC]'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_carot(self):
        pattern = r'^foo'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_dollarsign(self):
        pattern = r'foo$'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_not_literal(self):
        pattern = r'[^a]'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_negation_group(self):
        pattern = r'[^AEIOU]'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_lookahead(self):
        pattern = r'foo(?=bar)'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_lookbehind(self):
        pattern = r'(?<=foo)bar'
        assert re.search(pattern, self.rs.xeger(pattern))

    def test_backreference(self):
        pattern = r'(foo|bar)baz\1'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_zero_or_more_greedy(self):
        pattern = r'a*'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_zero_or_more_non_greedy(self):
        pattern = r'a*?'
        assert re.match(pattern, self.rs.xeger(pattern))
예제 #15
0
파일: test_rstr.py 프로젝트: sakti/dummygen
 def test_alphabet_at_instantiation(self):
     rs = Rstr(vowels='AEIOU')
     assert re.match('^[AEIOU]{1,10}$', rs.vowels())
예제 #16
0
 def setUp(self):
     self.rs = Rstr(random.SystemRandom())
예제 #17
0
class TestXeger(unittest.TestCase):
    def setUp(self):
        self.rs = Rstr()

    def test_literals(self):
        pattern = r'foo'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_digit(self):
        pattern = r'\d'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_nondigits(self):
        pattern = r'\D'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_literal_with_repeat(self):
        pattern = r'A{3}'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_literal_with_range_repeat(self):
        pattern = r'A{2, 5}'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_word(self):
        pattern = r'\w'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_nonword(self):
        pattern = r'\W'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_or(self):
        pattern = r'foo|bar'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_or_with_subpattern(self):
        pattern = r'(foo|bar)'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_range(self):
        pattern = r'[A-F]'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_character_group(self):
        pattern = r'[ABC]'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_carot(self):
        pattern = r'^foo'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_dollarsign(self):
        pattern = r'foo$'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_not_literal(self):
        pattern = r'[^a]'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_negation_group(self):
        pattern = r'[^AEIOU]'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_lookahead(self):
        pattern = r'foo(?=bar)'
        assert re.match(pattern, self.rs.xeger(pattern))

    def test_lookbehind(self):
        pattern = r'(?<=foo)bar'
        assert re.search(pattern, self.rs.xeger(pattern))

    def test_backreference(self):
        pattern = r'(foo|bar)baz\1'
        assert re.match(pattern, self.rs.xeger(pattern))
예제 #18
0
 def setUp(self) -> None:
     self.rs = Rstr()
예제 #19
0
파일: test_rstr.py 프로젝트: sakti/dummygen
 def test_add_alphabet(self):
     rs = Rstr()
     rs.add_alphabet('evens', '02468')
     assert re.match('^[02468]{1,10}$', rs.evens())
예제 #20
0
 def test_alphabet_at_instantiation(self):
     rs = Rstr(vowels='AEIOU')
     assert re.match('^[AEIOU]{1,10}$', rs.vowels())
예제 #21
0
 def setUp(self):
     self.rs = Rstr()
예제 #22
0
 def test_alphabet_at_instantiation(self) -> None:
     rs = Rstr(vowels='AEIOU')
     assert_matches('^[AEIOU]{1,10}$', rs.vowels())