class TestAnimal(unittest.TestCase): '''docstring for TestAnimal''' def setUp(self): call('py create_animals_database.py',shell=True) self.db_conn = sqlite3.connect('animals.db') def test_get_name(self): self.animal = Animal(self.db_conn, 'tiger', 12, 'Pol', 'male') self.assertEqual('Pol',self.animal.get_name()) def test_grow_young_animal(self): self.animal = Animal(self.db_conn, 'tiger', 12, 'Pol', 'male') self.animal.grow() self.assertEqual(13, self.animal.age) self.assertEqual(156, self.animal.weight) def test_grow_old_animal(self): self.animal = Animal(self.db_conn, 'lion', 180, 'John', 'male') self.animal.grow() self.assertEqual(200, self.animal.weight) self.assertEqual(181, self.animal.age) def test_die(self): self.animal = Animal(self.db_conn, 'raccoon', 36, 'Cohnen', 'male') self.assertEqual(True, self.animal.die()) def test_get_gestation_period(self): self.animal = Animal(self.db_conn, 'lion', 12, 'Pol', 'female') self.assertEqual(3, self.animal.get_gestation_period()) def test_get_id(self): self.animal = Animal(self.db_conn, 'lion', 12, 'Pol', 'female') self.assertEqual(-1, self.animal.get_id()) def test_food_for_day(self): self.animal = Animal(self.db_conn, 'lion', 12, 'Pol', 'female') self.assertEqual(3.15, self.animal.food_for_day()) def test_type_food(self): self.animal = Animal(self.db_conn, 'lion', 12, 'Pol', 'female') self.assertEqual('carnivore', self.animal.type_food()) def test_expenses_for_food(self): self.animal = Animal(self.db_conn, 'lion', 1, 'Pol', 'female') self.assertEqual(1.04, self.animal.expenses_for_food()) def tearDown(self): self.db_conn.commit() self.db_conn.close() call('rm -f animals.db', shell=True)
class TestAnimal(unittest.TestCase): """docstring for ZooTest""" def setUp(self): self.conn = sqlite3.connect('animal_types.db') cursor = self.conn.cursor() create_tables(cursor) self.conn.commit() tiger_stats = cursor.execute("SELECT * FROM animal_types\ WHERE species = 'tiger'").fetchall()[0] # print(tiger_stats) # print(tiger_stats[1]) self.tiger = Animal(tiger_stats[1], 18, "Pencho", 'male', 19) lion_stats = cursor.execute("SELECT * FROM animal_types\ WHERE species = 'lion'").fetchall()[0] self.lion = Animal(lion_stats[1], 24, "Svetla", "female", 17) def test_get_name(self): self.assertEqual("Pencho", self.tiger.get_name()) self.assertEqual("Svetla", self.lion.get_name()) def test_get_gender(self): self.assertEqual("female", self.lion.get_gender()) self.assertEqual("male", self.tiger.get_gender()) def test_get_weight(self): self.assertEqual(19, self.tiger.get_weight()) self.assertEqual(17, self.lion.get_weight()) def test_get_species(self): self.assertEqual("tiger", self.tiger.get_species()) self.assertEqual("lion", self.lion.get_species()) def test_get_age(self): self.assertEqual(18, self.tiger.get_age()) self.assertEqual(24, self.lion.get_age()) def test_max_weight(self): self.assertEqual(250, self.tiger.get_max_weight()) self.assertEqual(200, self.lion.get_max_weight()) def test_max_age(self): self.assertEqual(20, self.tiger.get_max_age()) self.assertEqual(15, self.lion.get_max_age()) def test_update_weight(self): self.assertEqual(31, self.tiger.update_weight(1)) self.assertEqual(24.5, self.lion.update_weight(1)) # testing weight limit self.assertEqual(250, self.tiger.update_weight(30)) self.assertEqual(200, self.lion.update_weight(100)) def test_grow(self): self.tiger.grow(12) self.assertEqual(163, self.tiger.get_weight()) self.assertEqual(19, self.tiger.get_age()) self.lion.grow(0) self.assertEqual(17, self.lion.get_weight()) self.assertEqual(24, self.lion.get_age()) # because of the chance_of_dying this test sometimes fails, as it should do # so it is commented """ def test_die(self): self.tiger.grow(180) # his new age is 198 months (max is 20 years = 240 months) self.assertEqual(False, self.tiger.die(0)) self.assertEqual(True, self.tiger.die(22)) # surely DEAD self.assertEqual(True, self.tiger.die(50)) """ def tearDown(self): conn = sqlite3.connect("animal_types.db") cursor = conn.cursor() drop_query = "DROP TABLE IF EXISTS animal_types" cursor.execute(drop_query)