Exemple #1
0
 def test_create_id_equality(self):
     """Test the create method
     """
     types = (int, float, str, tuple, list, dict, set, bool)
     self.assertNotEqual(self.base.id, Base.create().id)
     for value in (t() for t in types):
         self.assertEqual(Base.create(id=value).id, value)
Exemple #2
0
 def test_create_type(self):
     """Test the create method
     """
     types = (int, float, str, tuple, list, dict, set, bool)
     self.assertIsInstance(Base.create(), Base)
     for value in [t() for t in types] + [None, type]:
         self.assertIsInstance(Base.create(id=value), Base)
Exemple #3
0
    def test_wrong(self):
        """Wrong number of args"""
        with self.assertRaises(TypeError):
            Rectangle.create("Hi")

        with self.assertRaises(TypeError):
            Square.create("Go")
        self.assertEqual(Base.create(), None)
 def test_to_dictionary_and_create(self):
     s4 = Square(5, 8, 9, 3)
     s4_dictionary = s4.to_dictionary()
     self.assertIsInstance(s4_dictionary, dict)
     s5 = s4.create(**s4_dictionary)
     self.assertIsInstance(s5, Square)
     self.assertEqual(s5.width, 5)
     dummy_dictionary = {}
     self.assertEqual(Base.create(**dummy_dictionary), None)
Exemple #5
0
 def test_to_dictionary_and_create(self):
     r4 = Rectangle(5, 5, 8, 9, 3)
     r4_dictionary = r4.to_dictionary()
     self.assertIsInstance(r4_dictionary, dict)
     r5 = r4.create(**r4_dictionary)
     self.assertIsInstance(r5, Rectangle)
     self.assertEqual(r5.width, 5)
     self.assertEqual(r5.height, 5)
     dummy_dictionary = {}
     self.assertEqual(Base.create(**dummy_dictionary), None)
Exemple #6
0
    def test_09_create(self):
        """Tests possible values for create method
        """
        with self.assertRaises(TypeError):
            Base.create([])
        with self.assertRaises(TypeError):
            Base.create(())
        with self.assertRaises(TypeError):
            Base.create(True)
        with self.assertRaises(TypeError):
            Base.create(2.5)
        with self.assertRaises(TypeError):
            Rectangle.create([])
        with self.assertRaises(TypeError):
            Rectangle.create(())
        with self.assertRaises(TypeError):
            Rectangle.create(True)
        with self.assertRaises(TypeError):
            Rectangle.create(2.5)
        with self.assertRaises(TypeError):
            Square.create([])
        with self.assertRaises(TypeError):
            Square.create(())
        with self.assertRaises(TypeError):
            Square.create(True)
        with self.assertRaises(TypeError):
            Square.create(2.5)

        with self.assertRaises(TypeError):
            Rectangle.create(None)
        with self.assertRaises(TypeError):
            Square.create(None)
        with self.assertRaises(TypeError):
            Rectangle.create([], **{})
        with self.assertRaises(TypeError):
            Square.create([], **{})

        b1 = Base.create()
        self.assertEqual(b1.id, 8)

        r1 = Rectangle.create()
        self.assertEqual(r1.id, 9)

        r1 = Rectangle.create(**{})
        self.assertEqual(r1.id, 10)
        self.assertEqual(r1.width, 1)
        self.assertEqual(r1.height, 1)
        self.assertEqual(r1.x, 0)
        self.assertEqual(r1.y, 0)

        r1 = Rectangle.create(**({'width': 2, 'height': 3, 'x': 1, 'y': 0, 'i\
d': 100}))
        self.assertEqual(r1.width, 2)
        self.assertEqual(r1.height, 3)
        self.assertEqual(r1.x, 1)
        self.assertEqual(r1.y, 0)
        self.assertEqual(r1.id, 100)

        s1 = Square.create()
        self.assertEqual(s1.id, 12)

        s1 = Square.create(**{})
        self.assertEqual(s1.id, 13)
        self.assertEqual(s1.size, 1)
        self.assertEqual(s1.x, 0)
        self.assertEqual(s1.y, 0)

        s1 = Square.create(**({'size': 5, 'x': 2, 'y': 3, 'id': 98}))
        self.assertEqual(s1.width, 5)
        self.assertEqual(s1.height, 5)
        self.assertEqual(s1.size, 5)
        self.assertEqual(s1.x, 2)
        self.assertEqual(s1.y, 3)
        self.assertEqual(s1.id, 98)

        s1 = Square.create(**({'size': 5}))
        self.assertEqual(s1.width, 5)
        self.assertEqual(s1.height, 5)
        self.assertEqual(s1.size, 5)
        self.assertEqual(s1.x, 0)
        self.assertEqual(s1.y, 0)
        self.assertEqual(s1.id, 15)

        r1 = Rectangle.create(**({'height': 3}))
        self.assertEqual(r1.width, 1)
        self.assertEqual(r1.height, 3)
        self.assertEqual(r1.x, 0)
        self.assertEqual(r1.y, 0)
        self.assertEqual(r1.id, 16)

        s1 = Square.create(**({'hi': 5}))
        self.assertEqual(s1.width, 1)
        self.assertEqual(s1.height, 1)
        self.assertEqual(s1.size, 1)
        self.assertEqual(s1.x, 0)
        self.assertEqual(s1.y, 0)
        self.assertEqual(s1.id, 17)

        r1 = Rectangle.create(**({'height': 3, 'hi': 5}))
        self.assertEqual(r1.width, 1)
        self.assertEqual(r1.height, 3)
        self.assertEqual(r1.x, 0)
        self.assertEqual(r1.y, 0)
        self.assertEqual(r1.id, 18)
Exemple #7
0
 def test_create_id_type(self):
     """Test the create method
     """
     self.assertIsInstance(Base.create().id, int)
Exemple #8
0
 def test_create_id_identity(self):
     """Test the create method
     """
     self.assertIsNone(Base.create(id=None).id)
     self.assertIs(Base.create(id=type).id, type)