Пример #1
0
    def test_cc_example(self):
        """
        Searches for Credit Cards
        """

        easy = Easy() \
                .digit().digit().digit().digit() \
                .then('-') \
                .digit().digit().digit().digit() \
                .then('-') \
                .digit().digit().digit().digit() \
                .then('-') \
                .digit().digit().digit().digit()

        test_s = "4444-5555-6666-7777"
        self.assertTrue(easy.test(test_s))

        test_s = "444-555-666-777"
        self.assertFalse(easy.test(test_s))

        test_s = "Hey Joe! The credit card number for the invoice is 4444-5555-6666-7777. Thanks!"
        self.assertTrue(easy.test(test_s))

        test_s = "Hey JoeBot4444-5555-! Your PIN number is 2222-3333."
        self.assertFalse(easy.test(test_s))
Пример #2
0
    def test_of_any(self):
        """
        Test ofAny
        """
        easy = Easy() \
                .startOfLine() \
                .exactly(3).ofAny() \
                .endOfLine()

        self.assertTrue(easy.test("abc"))
        self.assertFalse(easy.test("ac"))
Пример #3
0
    def test_of_any(self):
        """
        Test ofAny
        """
        easy = Easy() \
                .startOfLine() \
                .exactly(3).ofAny() \
                .endOfLine()

        self.assertTrue(easy.test("abc"))
        self.assertFalse(easy.test("ac"))
Пример #4
0
    def test_of(self):
        """
        Test of
        """
        easy = Easy() \
                .startOfLine() \
                .exactly(2).of("p p p ") \
                .endOfLine()

        test = "p p p p p p "
        self.assertTrue(easy.test(test))
        test = "p p p p pp"
        self.assertFalse(easy.test(test))
Пример #5
0
    def test_from(self):
        """
        Test asGroup and ofGroup
        """
        easy = Easy() \
                .startOfLine() \
                .exactly(3).of("p").asGroup() \
                .exactly(1).of("q") \
                .exactly(1).ofGroup(1) \
                .endOfLine()

        self.assertTrue(easy.test("pppqppp"))
        self.assertFalse(easy.test("pxpqppp"))
Пример #6
0
    def test_of(self):
        """
        Test of
        """
        easy = Easy() \
                .startOfLine() \
                .exactly(2).of("p p p ") \
                .endOfLine()

        test = "p p p p p p "
        self.assertTrue(easy.test(test))
        test = "p p p p pp"
        self.assertFalse(easy.test(test))
Пример #7
0
    def test_from(self):
        """
        Test asGroup and ofGroup
        """
        easy = Easy() \
                .startOfLine() \
                .exactly(3).of("p").asGroup() \
                .exactly(1).of("q") \
                .exactly(1).ofGroup(1) \
                .endOfLine()

        self.assertTrue(easy.test("pppqppp"))
        self.assertFalse(easy.test("pxpqppp"))
Пример #8
0
    def test_us_phone_numbers(self):
        """
        Searches for US phone numbers.
        """

        easy = Easy() \
                .find('(') \
                .digit().digit().digit() \
                .then(')') \
                .then(' ') \
                .digit().digit().digit() \
                .then('-') \
                .digit().digit().digit().digit() \

        test_s = "Hey Mike, give me a call at (123) 555-1234. Thanks!"
        self.assertTrue(easy.test(test_s))

        test_s = "Hey Joe! The credit card number for the invoice is 4444-5555-6666-7777. Thanks!"
        self.assertFalse(easy.test(test_s))
Пример #9
0
    def test_us_phone_numbers(self):
        """
        Searches for US phone numbers.
        """

        easy = Easy() \
                .find('(') \
                .digit().digit().digit() \
                .then(')') \
                .then(' ') \
                .digit().digit().digit() \
                .then('-') \
                .digit().digit().digit().digit() \

        test_s = "Hey Mike, give me a call at (123) 555-1234. Thanks!"
        self.assertTrue(easy.test(test_s))

        test_s = "Hey Joe! The credit card number for the invoice is 4444-5555-6666-7777. Thanks!"
        self.assertFalse(easy.test(test_s))
Пример #10
0
    def test_names(self):
        """
        Searches for possible names.
        """

        easy = Easy() \
                .upperCaseLetter() \
                .lowerCaseLetters() \
                .then(' ') \
                .upperCaseLetter() \
                .lowerCaseLetters() \

        test_s = "The two rappers who really run the south are Paul Wall and Slim Thug."
        self.assertTrue(easy.test(test_s))

        test_s = "Philadelphia."
        self.assertFalse(easy.test(test_s))

        test_s = "Hey lol this isnt a name. Test."
        self.assertFalse(easy.test(test_s))
Пример #11
0
    def test_names(self):
        """
        Searches for possible names.
        """

        easy = Easy() \
                .upperCaseLetter() \
                .lowerCaseLetters() \
                .then(' ') \
                .upperCaseLetter() \
                .lowerCaseLetters() \

        test_s = "The two rappers who really run the south are Paul Wall and Slim Thug."
        self.assertTrue(easy.test(test_s))

        test_s = "Philadelphia."
        self.assertFalse(easy.test(test_s))

        test_s = "Hey lol this isnt a name. Test."
        self.assertFalse(easy.test(test_s))
Пример #12
0
    def test_startOfLine(self):
        """
        Start of Line test.
        """

        reg = Easy().startOfLine().exactly(1).of("p").getRegex()

        test = "p"
        self.assertTrue(len(re.findall(reg, test)) == 1)

        test = "qp"
        self.assertTrue(len(re.findall(reg, test)) == 0)
Пример #13
0
    def test_cc_example(self):
        """
        Searches for Credit Cards
        """

        easy = Easy() \
                .digit().digit().digit().digit() \
                .then('-') \
                .digit().digit().digit().digit() \
                .then('-') \
                .digit().digit().digit().digit() \
                .then('-') \
                .digit().digit().digit().digit()

        test_s = "4444-5555-6666-7777"
        self.assertTrue(easy.test(test_s))

        test_s = "444-555-666-777"
        self.assertFalse(easy.test(test_s))

        test_s = "Hey Joe! The credit card number for the invoice is 4444-5555-6666-7777. Thanks!"
        self.assertTrue(easy.test(test_s))

        test_s = "Hey JoeBot4444-5555-! Your PIN number is 2222-3333."
        self.assertFalse(easy.test(test_s))
Пример #14
0
    def test_max(self):
        """
        Test 'max'
        """
        reg = Easy() \
                .startOfLine() \
                .max(3).of("x") \
                .endOfLine() \
                .getRegex()

        test = "xx"
        self.assertTrue(len(re.findall(reg, test)) == 1)
        test = "xxx"
        self.assertTrue(len(re.findall(reg, test)) == 1)
        test = "xxxx"
        self.assertTrue(len(re.findall(reg, test)) == 0)
Пример #15
0
    def test_min_max(self):
        """
        Test joined Min and Max
        """
        reg = Easy() \
                .startOfLine() \
                .min(3).max(5).of("x") \
                .endOfLine() \
                .getRegex()

        test = "xx"
        self.assertTrue(len(re.findall(reg, test)) == 0)
        test = "xxx"
        self.assertTrue(len(re.findall(reg, test)) == 1)
        test = "xxxx"
        self.assertTrue(len(re.findall(reg, test)) == 1)
        test = "xxxxx"
        self.assertTrue(len(re.findall(reg, test)) == 1)
        test = "xxxxxx"
        self.assertTrue(len(re.findall(reg, test)) == 0)
Пример #16
0
    def test_dollars_example(self):
        """
        The first example from the README.
        """

        reg = Easy() \
                .find("$") \
                .min(1) \
                .digits() \
                .then(".") \
                .digit() \
                .digit() \
                .getRegex()

        test = "$10.00"
        self.assertTrue(len(re.findall(reg, test)) == 1)

        test = "$1X.00"
        self.assertFalse(len(re.findall(reg, test)) == 1)

        test = "Dollar $ign. 12. Hello. 99."
        self.assertFalse(len(re.findall(reg, test)) == 1)
Пример #17
0
 def test_search(self):
     easy = Easy().startOfLine().exactly(1).of("p")
     self.assertTrue(easy.search('q') is None)
     self.assertTrue(easy.search('p') is not None)
Пример #18
0
 def test_easy_test(self):
     easy = Easy().startOfLine().exactly(1).of("p")
     self.assertTrue(easy.test('p'))
     self.assertFalse(easy.test('qp'))
Пример #19
0
 def test_easy_test(self):
     easy = Easy().startOfLine().exactly(1).of("p")
     self.assertTrue(easy.test('p'))
     self.assertFalse(easy.test('qp'))
Пример #20
0
 def test_search(self):
     easy = Easy().startOfLine().exactly(1).of("p")
     self.assertTrue(easy.search('q') is None)
     self.assertTrue(easy.search('p') is not None)