Exemple #1
0
    def test_extra_arguments(self):
        """Pass extra arguments"""
        with self.assertRaises(TypeError):
            base.Base(12, 12)

        with self.assertRaises(TypeError):
            base.Base("hello", 12, 34)
    def test_id_set(self):
        """ id can be set on instantiation
        """

        b1 = base.Base()
        b2 = base.Base(5)
        b3 = base.Base()
        self.assertEqual(b1.id, 1)
        self.assertEqual(b2.id, 5)
        self.assertEqual(b3.id, 2)
    def test_instance_counter(self):
        """should keep track of number of instances as id
        """

        b1 = base.Base()
        start = b1.id
        b2 = base.Base()
        b3 = base.Base()
        b4 = base.Base()
        b5 = base.Base()
        self.assertEqual(b2.id, start + 1)
        self.assertEqual(b3.id, start + 2)
        self.assertEqual(b5.id, start + 4)
    def test_inherits(self):
        """test if Rectangle inherits from Base"""

        b = base.Base()
        rect = rectangle.Rectangle(1, 1)

        self.assertTrue(issubclass(type(rect), type(b)))
Exemple #5
0
    def test_class_attributes(self):
        """Check class attributes"""
        b = base.Base(1001)

        with self.assertRaises(AttributeError):
            print(b.nb_objects)

        with self.assertRaises(AttributeError):
            print(b.__nb_objects)
Exemple #6
0
    def test_generate_multiple_bases(self):
        """Create multiple instances"""

        b1 = base.Base()
        self.assertEqual(b1.id, 1)

        b2 = base.Base()
        self.assertEqual(b2.id, 2)

        b3 = base.Base()
        self.assertEqual(b3.id, 3)

        b4 = base.Base(12)
        self.assertEqual(b4.id, 12)

        b5 = base.Base()
        self.assertEqual(b5.id, 4)

        nb_objects = 4
        for i in range(5, 10):
            # id_base is i if i is even, otherwise None
            id_base = i if i % 2 == 0 else None

            with self.subTest(i=i):
                b = base.Base(id_base)
                if i % 2 != 0:
                    nb_objects += 1
                    id_base = nb_objects

                self.assertIs(b.id, id_base)
Exemple #7
0
 def test_dictionary(self):
     """Test dictionary"""
     b = base.Base(12)
Exemple #8
0
 def test_attribute_not_exists(self):
     """Get an attribute that doesn't exists"""
     b = base.Base(14)
     with self.assertRaises(AttributeError):
         print(b.size)
Exemple #9
0
 def test_get_id(self):
     """Get the id of an instance"""
     b = base.Base(12)
     self.assertIs(b.id, 12)