def test_diffrent_color_place(self): p = Rectangle.parse( { 'x': 1, 'y': 2, 'height': 2, 'width': 3, 'color': "(0, 255, 0)" }, {}, Color("#123456")) self.assertEqual(p.color, Color("#00ff00")) p = Rectangle.parse( { 'x': 1, 'y': 2, 'height': 2, 'width': 3, 'color': "cos" }, {"cos": "#00ff00"}, Color("#123456")) self.assertEqual(p.color, Color("#00ff00"))
def test_parse(self): p = Rectangle.parse({ 'x': 1, 'y': 2, 'height': 2, 'width': 3 }, {}, Color("#123456")) self.assertEqual(p.x, 1) self.assertEqual(p.y, 2) self.assertEqual(p.height, 2) self.assertEqual(p.width, 3) self.assertEqual(p.color, Color("#123456"))
def test_errors(self): with self.assertRaises(ValueError): Rectangle.parse({ 'y': 2, 'height': 2, 'width': 3 }, {}, Color("#123456")) Rectangle.parse({ 'x': 1, 'height': 2, 'width': 3 }, {}, Color("#123456")) Rectangle.parse({'x': 1, 'y': 2, 'width': 3}, {}, Color("#123456")) Rectangle.parse({ 'x': 1, 'y': 2, 'height': 2 }, {}, Color("#123456")) Rectangle.parse({'x': 1, 'y': 2, 'height': 2, 'width': 3}, {}, 1) with self.assertRaises(TypeError): Rectangle.parse({ 'x': {}, 'y': 2, 'height': 2, 'width': 3 }, {}, Color("#123456")) Rectangle.parse( { 'x': 1, 'y': (), 'height': 1, 'width': 3, 'color': "(0, 255, 0)" }, {}, Color("#123456")) Rectangle.parse( { 'x': 1, 'y': 2, 'height': [], 'width': 3, 'color': "(0, 255, 0)" }, {}, Color("#123456")) Rectangle.parse( { 'x': 1, 'y': 2, 'height': 2, 'width': "", 'color': "(0, 255, 0)" }, {}, Color("#123456")) Rectangle.parse( { 'x': 1, 'y': 2, 'height': 2, 'width': 3, 'color': "(0, 255, 0)" }, {}, 1)