Skip to content

Commit 8b1e220

Browse files
committed
nose test & fixture for unittest (setup - teardown)
1 parent 8f1c66c commit 8b1e220

6 files changed

Lines changed: 61 additions & 0 deletions

File tree

File renamed without changes.

person.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Person:
2+
3+
def __init__(self, fname, lname):
4+
self.fname = fname
5+
self.lname = lname
6+
7+
def fullname(self):
8+
return f"{self.fname} {self.lname}"
9+
10+
def email(self):
11+
return f"{self.fullname()}@email.com".replace(' ', '')

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nose==1.3.7

test_nose.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sample_func
2+
3+
4+
def test_add():
5+
assert sample_func.add(3, 4) == 7
6+
assert sample_func.add(-1, 4) == 3
7+
assert sample_func.add(0, 4) == 4
8+
9+
10+
def subtract(x, y):
11+
assert sample_func.subtract(3, 4) == -1
12+
assert sample_func.subtract(-1, 4) == -5
13+
assert sample_func.subtract(0, 4) == -4
14+
15+
16+
def multiply(x, y):
17+
assert sample_func.multiply(3, 4) == 12
18+
assert sample_func.multiply(3, 4) != 11
19+
assert sample_func.multiply(-1, 4) == -4
20+
assert sample_func.multiply(0, 4) == 0
21+
22+
23+
def division(x, y):
24+
assert sample_func.multiply(12, 4) == 3
File renamed without changes.

test_unit_person.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest
2+
3+
from person import Person
4+
5+
6+
class PersonTest(unittest.TestCase):
7+
8+
def setUp(self):
9+
self.p1 = Person('rezoo', 'mob')
10+
self.p2 = Person('mik', 'raz')
11+
12+
def tearDown(self) -> None:
13+
print('Done. . .')
14+
15+
def test_fullname(self):
16+
self.assertEqual(self.p1.fullname(), 'rezoo mob')
17+
self.assertEqual(self.p2.fullname(), 'mik raz')
18+
19+
def test_email(self):
20+
self.assertEqual(self.p1.email(), 'rezoomob@email.com')
21+
self.assertEqual(self.p2.email(), 'mikraz@email.com')
22+
23+
24+
if __name__ == '__main__':
25+
unittest.main()

0 commit comments

Comments
 (0)