コード例 #1
0
ファイル: test.py プロジェクト: pzeballos/python-bootcamp
 def test_cat_class(self):
     """Test case:
     * Cat's speak method should return 'meow'.
     * Cat's 'legs' method should return 2.
     """
     cat = Cat()
     self.assertEqual(cat.speak(), 'meow')
     self.assertEqual(cat.legs(), 2)
コード例 #2
0
ファイル: test.py プロジェクト: pzeballos/python-bootcamp
    def test_init_attr_not_accesible_when_preceded_by_double_underscore(self):
        """Test case:
        * test that illustrates an attribute defined in the `__init__` method of 'Mammal' is not
        accessible to Dog or Cat when preceded by a double-underscore, but an attribute
        preceded by a single-underscore or no underscore is.
        """
        mammal = Mammal()
        cat = Cat()
        dog = Dog()

        self.assertEqual(cat.info_type(), mammal.info_type())       # __type not accessible to Cat (is not able to overwrite it)
        self.assertNotEqual(cat.info_temp(), mammal.info_temp())    # _temp accessible to Cat (is able to overwrite it)
        self.assertNotEqual(cat.info_body(), mammal.info_body())    # body accessible to Cat (is able to overwrite it)

        self.assertEqual(dog.info_type(), mammal.info_type())       # __type not accessible to Dog (is not able to overwrite it)
        self.assertNotEqual(dog.info_temp(), mammal.info_temp())    # _temp accessible to Dog (is able to overwrite it)
        self.assertNotEqual(dog.info_body(), mammal.info_body())    # body accessible to Dog (is able to overwrite it)