Olli Graf
4 months ago
1 changed files with 47 additions and 0 deletions
@ -0,0 +1,47 @@ |
|||
# 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() |
|||
|
Loading…
Reference in new issue