Olli Graf
5 months ago
4 changed files with 57 additions and 0 deletions
@ -0,0 +1,17 @@ |
|||
|
|||
class Name: |
|||
def __init__(self,vorname,name): |
|||
self.vorname = vorname |
|||
self.name = name |
|||
|
|||
def __getattr__(self,attr): |
|||
if attr == 'fullname': |
|||
return self.vorname + ' ' + self.name |
|||
elif attr == 'sortname': |
|||
return self.name + ',' + self.vorname |
|||
else: |
|||
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{attr}'") |
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,28 @@ |
|||
import unittest |
|||
import logging |
|||
from name import Name |
|||
|
|||
__LOGLEVEL__ = logging.DEBUG |
|||
|
|||
logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=__LOGLEVEL__) |
|||
|
|||
class TestName(unittest.TestCase): |
|||
|
|||
def setUp(self): |
|||
logging.debug('setting up test') |
|||
self.name = Name('Homer', 'Simpson') |
|||
|
|||
def test_getattr(self): |
|||
fullname = self.name.fullname |
|||
sortname = self.name.sortname |
|||
|
|||
|
|||
self.assertEqual('Homer Simpson', fullname) |
|||
self.assertEqual('Simpson,Homer', sortname) |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
logging.debug('Test startet.') |
|||
unittest.main() |
|||
|
|||
|
@ -0,0 +1,7 @@ |
|||
|
|||
|
|||
def square(x): |
|||
return x** 2 |
|||
|
|||
sq5 = square(5) |
|||
print(f'{sq5}') |
@ -0,0 +1,5 @@ |
|||
|
|||
|
|||
|
|||
square = lambda x: x** 2 |
|||
print(f'{square(5)}') |
Loading…
Reference in new issue