def test_tojson(self): x = -200 y = -100 width = 600 height = 300 rect = DOMRect(x, y, width, height) json = rect.tojson() self.assertEqual(x, json['x']) self.assertEqual(y, json['y']) self.assertEqual(width, json['width']) self.assertEqual(height, json['height']) o = DOMRect.from_rect(json) self.assertEqual(o, rect) self.assertEqual(x, o.x) self.assertEqual(y, o.y) self.assertEqual(width, o.width) self.assertEqual(height, o.height)
def test_from_rect(self): x = -200 y = -100 width = 600 height = 300 rect = DOMRect.from_rect({'x': x, 'y': y, 'width': width, 'height': height, }) self.assertIsInstance(rect, DOMRect) self.assertFalse(rect.isempty()) self.assertTrue(rect.isvalid()) self.assertEqual(x, rect.x) self.assertEqual(x, rect.left) self.assertEqual(y, rect.y) self.assertEqual(y, rect.top) self.assertEqual(x + width, rect.right) self.assertEqual(y + height, rect.bottom) self.assertEqual(width, rect.width) self.assertEqual(height, rect.height)