예제 #1
0
 def test_load_from_file_csv_rectangle_types(self):
     r1 = Rectangle(10, 7, 2, 8, 1)
     r2 = Rectangle(2, 4, 5, 6, 2)
     Rectangle.save_to_file_csv([r1, r2])
     output = Rectangle.load_from_file_csv()
     self.assertTrue(all(type(obj) == Rectangle for obj in output))
예제 #2
0
 def test_complex_height(self):
     with self.assertRaisesRegex(TypeError, "height must be an integer"):
         Rectangle(1, complex(5))
예제 #3
0
 def test_dict_height(self):
     with self.assertRaisesRegex(TypeError, "height must be an integer"):
         Rectangle(1, {"a": 1, "b": 2})
예제 #4
0
 def test_negative_width(self):
     with self.assertRaisesRegex(ValueError, "width must be > 0"):
         Rectangle(-1, 2)
예제 #5
0
 def test_str_height(self):
     with self.assertRaisesRegex(TypeError, "height must be an integer"):
         Rectangle(1, "invalid")
예제 #6
0
 def test_bytearray_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle(bytearray(b'abcdefg'), 2)
예제 #7
0
 def test_memoryview_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle(memoryview(b'abcedfg'), 2)
예제 #8
0
 def test_str_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle("invalid", 2)
예제 #9
0
 def test_float_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle(5.5, 1)
 def test_rect(self):
     """ test rectangle """
     r = Rectangle(10, 15)
     self.assertEqual(r.width, 10)
     self.assertEqual(r.height, 15)
 def test_rectangle_base(self):
     """ test rectangle base """
     self.assertIsInstance(Rectangle(10, 20), Base)
 def test_without_arg(self):
     """ test without arg """
     with self.assertRaises(TypeError):
         Rectangle()
예제 #13
0
#!/usr/bin/python3
""" 2-main """
from models.rectangle import Rectangle

if __name__ == "__main__":

    try:
        Rectangle(10, "2")
    except Exception as e:
        print("[{}] {}".format(e.__class__.__name__, e))

    try:
        r = Rectangle(10, 2)
        r.width = -10
    except Exception as e:
        print("[{}] {}".format(e.__class__.__name__, e))

    try:
        r = Rectangle(10, 2)
        r.x = {}
    except Exception as e:
        print("[{}] {}".format(e.__class__.__name__, e))

    try:
        Rectangle(10, 2, 3, -1)
    except Exception as e:
        print("[{}] {}".format(e.__class__.__name__, e))

    try:
        Rectangle(10, 2.0, 3, 4)
    except Exception as e:
예제 #14
0
 def test_to_json_string_rectangle_type(self):
     r = Rectangle(10, 7, 2, 8, 6)
     self.assertEqual(str, type(Base.to_json_string([r.to_dictionary()])))
예제 #15
0
 def test_range_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle(range(5), 2)
예제 #16
0
 def test_complex_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle(complex(5), 2)
예제 #17
0
 def test_bytes_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle(b'Python', 2)
예제 #18
0
 def test_dict_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle({"a": 1, "b": 2}, 2)
예제 #19
0
 def test_no_args(self):
     with self.assertRaises(TypeError):
         Rectangle()
예제 #20
0
 def test_rectangle_is_base(self):
     self.assertIsInstance(Rectangle(10, 2), Base)
예제 #21
0
 def test_nan_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle(float('nan'), 2)
예제 #22
0
 def test_bool_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle(True, 2)
예제 #23
0
 def test_zero_width(self):
     with self.assertRaisesRegex(ValueError, "width must be > 0"):
         Rectangle(0, 2)
예제 #24
0
 def test_set_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle({1, 2, 3}, 2)
예제 #25
0
 def test_float_height(self):
     with self.assertRaisesRegex(TypeError, "height must be an integer"):
         Rectangle(1, 5.5)
예제 #26
0
 def test_tuple_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle((1, 2, 3), 2)
예제 #27
0
 def test_one_arg(self):
     with self.assertRaises(TypeError):
         Rectangle(1)
예제 #28
0
 def test_frozenset_width(self):
     with self.assertRaisesRegex(TypeError, "width must be an integer"):
         Rectangle(frozenset({1, 2, 3, 1}), 2)
예제 #29
0
 def test_list_height(self):
     with self.assertRaisesRegex(TypeError, "height must be an integer"):
         Rectangle(1, [1, 2, 3])
예제 #30
0
 def test_load_from_file_csv_second_rectangle(self):
     r1 = Rectangle(10, 7, 2, 8, 1)
     r2 = Rectangle(2, 4, 5, 6, 2)
     Rectangle.save_to_file_csv([r1, r2])
     list_rectangles_output = Rectangle.load_from_file_csv()
     self.assertEqual(str(r2), str(list_rectangles_output[1]))