You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
5 months ago
|
# coding: utf-8
|
||
|
import unittest
|
||
|
import logging
|
||
|
import re #regular expressions
|
||
|
|
||
|
logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=logging.DEBUG)
|
||
|
|
||
|
class TestPLZ(unittest.TestCase):
|
||
|
|
||
|
# Korrektes Format der PLZ prüfen. Falsche Version
|
||
|
|
||
|
def checkPLZ_falsch(self,plz):
|
||
|
try:
|
||
|
if len(pl) == 5 and int(plz) > 0:
|
||
|
return True
|
||
|
except ValueError:
|
||
|
pass
|
||
|
|
||
|
return False
|
||
|
|
||
|
def checkPLZ_korrekt(self,plz):
|
||
|
#regulären Audruck aufbauen, genau 5 Ziffern.
|
||
|
pattern = re.compile('\d\d\d\d\d')
|
||
|
#Ausdruck auf String anwenden.
|
||
|
return pattern.match(plz)
|
||
|
|
||
|
|
||
|
# Die setUp() Methode wird zu Beginn jedes Testcases aufgrufen
|
||
|
def setUp(self):
|
||
|
logging.debug('setting up test')
|
||
|
self.testdaten = ['42287','42289','42119','42277','44139','-1111']
|
||
|
|
||
|
def test_false_positive(self):
|
||
|
|
||
|
for plz in self.testdaten:
|
||
|
self.assertTrue(self.checkPLZ_falsch(plz))
|
||
|
|
||
|
def test_plz(self):
|
||
|
|
||
|
logging.debug('starte test_plz()')
|
||
|
for plz in self.testdaten:
|
||
|
logging.debug(f'teste ${plz}')
|
||
|
self.assertTrue(self.checkPLZ_korrekt(plz))
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest.main()
|
||
|
|