Esempio n. 1
0
    def testForDate(self):
        regexp = regexpgen.auto("%Y")
        self.assertTrue(re.match(regexp, "1990"))
        self.assertFalse(re.match(regexp, "-67.3"))

        regexp = regexpgen.auto("%d/%m/%Y")
        self.assertTrue(re.match(regexp, "22/10/2010"))
        self.assertFalse(re.match(regexp, "2.3"))

        regexp = regexpgen.auto("%m-%d")
        self.assertTrue(re.match(regexp, "02-12"))
        self.assertFalse(re.match(regexp, "22-34"))
Esempio n. 2
0
    def testForTime(self):
        regexp = regexpgen.auto("%H")
        self.assertTrue(re.match(regexp, "00"))
        self.assertFalse(re.match(regexp, "67"))

        regexp = regexpgen.auto("%H:%M")
        self.assertTrue(re.match(regexp, "22:45"))
        self.assertFalse(re.match(regexp, "2.3"))

        regexp = regexpgen.auto("%I:%M %P")
        self.assertTrue(re.match(regexp, "02:45 PM"))
        self.assertFalse(re.match(regexp, "22:34 pm"))
Esempio n. 3
0
    def testForInteger(self):
        regexp = regexpgen.auto("%0d")
        self.assertTrue(re.match(regexp, "-2345"))
        self.assertFalse(re.match(regexp, "0045"))

        regexp = regexpgen.auto("%d")
        self.assertTrue(re.match(regexp, "-002345"))
        self.assertFalse(re.match(regexp, "0045.7"))

        regexp = regexpgen.auto("%05d")
        self.assertTrue(re.match(regexp, "-02345"))
        self.assertFalse(re.match(regexp, "0457"))
Esempio n. 4
0
    def testForReal(self):
        regexp = regexpgen.auto("%lf")
        self.assertTrue(re.match(regexp, "-2.5"))
        self.assertFalse(re.match(regexp, "0045"))

        regexp = regexpgen.auto("%0lf")
        self.assertTrue(re.match(regexp, "45.7"))
        self.assertFalse(re.match(regexp, "0045.7"))

        regexp = regexpgen.auto("%05.2lf")
        self.assertTrue(re.match(regexp, "-22.45"))
        self.assertFalse(re.match(regexp, "2.3"))
Esempio n. 5
0
	def testPhase3Stage3(self):
		# 8 May 2013: auto-detection, concatenate

		# concatenate

		self.assertTrue (re.match(regexpgen.concatenate([
				('int', "%d", 100, 105),
				('\.',),
				('int', "%d", 250, 255),
				('\.',),
				('int', "%d", 122, 122),
				('\.',),
				('int', "%d", 0, 240)
		]), "100.250.122.10"))

		self.assertFalse(re.match(regexpgen.concatenate([
				('int', "%d", 100, 105),
				('\.',),
				('int', "%d", 250, 255),
				('\.',),
				('int', "%d", 122, 122),
				('\.',),
				('int', "%d", 0, 240)
		]), "99.250.122.10"))

		self.assertTrue(re.match(regexpgen.concatenate([
				('int', "%04d", 99, 105),
				('\.',),
				('int', "%d", 250, 255),
				('\.',),
				('int', "%d", 122, 122),
				('\.',),
				('int', "%d", 0, 240)
		]), "0099.250.122.10"))

		self.assertFalse(re.match(regexpgen.concatenate([
				('int', "%04d", 99, 105),
				('\.',),
				('int', "%d", 250, 255),
				('\.',),
				('int', "%d", 122, 122),
				('\.',),
				('int', "%d", 0, 240)
		]), "99.250.122.10"))

		# auto
		self.assertTrue  (re.match(regexpgen.auto("%d", 1, None), "1"))
		self.assertTrue  (re.match(regexpgen.auto("%03d", 0, 100), "099"))
		self.assertFalse (re.match(regexpgen.auto("%lf", -0.01, 1.5), "1.51"))
		self.assertFalse (re.match(regexpgen.auto("%0.1lf", -100.0, 100.0), "-100.00"))
		self.assertTrue  (re.match(regexpgen.auto("%016.10lf"), "15600001.0123456789"))
		self.assertFalse (re.match(regexpgen.auto("%H:%M"), "24:23"))
		self.assertRaises(ValueError, regexpgen.auto, "%I?%M?%p", "12:24am", "5:59 pm")