class TestPandaClass(unittest.TestCase):

    def setUp(self):
        self.test_obj = Panda("Ivo", "*****@*****.**", "male")
        self.test_obj2 = Panda("Rado", "*****@*****.**", "male")
        self.test_obj3 = Panda("Ivo", "*****@*****.**", "male")

    def test_init(self):
        self.assertTrue(isinstance(self.test_obj, Panda))

    def test_wrong_init(self):
        with self.assertRaises(ValueError):
            wrong_answ = Panda("mitio", "mitko.com", "male")

    def test_str_method(self):
        self.assertEqual(str(self.test_obj), "Ivo")

    def test_eq_method(self):
        self.assertFalse(self.test_obj == self.test_obj2)
        self.assertEqual(self.test_obj, self.test_obj3)

    def test_get_name(self):
        self.assertEqual(self.test_obj.get_name(), "Ivo")

    def test_get_email(self):
        self.assertEqual(self.test_obj.get_email(), "*****@*****.**")

    def test_is_Female(self):
        self.assertFalse(self.test_obj.isFemale())

    def test_is_Male(self):
        self.assertTrue(self.test_obj.isMale())

    def test_gender(self):
        self.assertEqual(self.test_obj.get_gender(), "male")
示例#2
0
class Test_Panda(unittest.TestCase):
    def setUp(self):
        self.ivo = Panda("Ivo", "*****@*****.**", "male")

    def test_init(self):
        self.assertTrue(isinstance(self.ivo, Panda))
        self.assertEqual(self.ivo.get_name(), self.ivo.name)
        self.assertEqual(self.ivo.get_email(), self.ivo.email)
        self.assertEqual(self.ivo.get_gender(), self.ivo.gender)
        self.assertEqual(self.ivo.check_isMale(), True)
        self.assertEqual(self.ivo.check_isFemale(), False)
        # email exception
        with self.assertRaises(ValueError):
            ivo = Panda("Ivo", "BLAAAAA", "male")

    def test_eq(self):
        rado = Panda("Rado", "*****@*****.**", "male")
        self.assertFalse(self.ivo == rado)

    def test_hashed(self):
        self.assertTrue(isinstance(self.ivo.__hash__(), int))

    def test_get_name(self):
        self.assertEqual(self.ivo.get_name(), self.ivo.name)

    def test_get_email(self):
        self.assertEqual(self.ivo.get_email(), self.ivo.email)

    def test_get_gender(self):
        self.assertEqual(self.ivo.get_gender(), self.ivo.gender)

    def test_check_isMale(self):
        self.assertTrue(self.ivo.check_isMale())

    def test_check_isFemale(self):
        self.assertFalse(self.ivo.check_isFemale())
class TestPanda(unittest.TestCase):
    def setUp(self):
        self.peshko_panda = Panda("Peshko", "*****@*****.**", "male")

    def test_create_new_panda(self):
        self.assertTrue(isinstance(self.peshko_panda, Panda))

        with self.assertRaises(WrongEmailError):
            self.marto_panda = Panda("Marto", "martopandaemail.com", "male")

    def test_get_name(self):
        self.assertEqual(self.peshko_panda.name, self.peshko_panda.get_name())

    def test_get_gender(self):
        self.assertEqual(self.peshko_panda.gender,
                         self.peshko_panda.get_gender())

    def test_get_email(self):
        self.assertEqual(self.peshko_panda.email,
                         self.peshko_panda.get_email())

    def test_is_male(self):
        self.assertTrue(self.peshko_panda.is_male())

    def test_is_female(self):
        self.assertFalse(self.peshko_panda.is_female())

    def test_equal_objects(self):
        peshko_panda_2 = Panda("Peshko", "*****@*****.**", "male")
        self.assertEqual(self.peshko_panda, peshko_panda_2)

    def test_object_to_str(self):
        peshko_panda_2 = Panda("Peshko", "*****@*****.**", "male")
        message = "My panda with name {} is with email {} and gender {}".format(
            peshko_panda_2.name, peshko_panda_2.email, peshko_panda_2.gender)

        self.assertEqual(str(peshko_panda_2), message)

    def test_object_to_hash(self):
        self.assertTrue(int(hash(self.peshko_panda)))