コード例 #1
0
 def test_from_raw_unsupported(self):
     tests = [
         '(1,1',
         object(),
         [],
         (1, ),
         (1, 1, 1),
     ]
     for raw in tests:
         with self.subTest(repr(raw)):
             with self.assertRaises(ValueError):
                 Point2D.from_raw(raw)
コード例 #2
0
    def test_from_raw_supported(self):
        tests = {
            None:
            None,
            Point2D():
            None,
            '1,1':
            Point2D(1, 1),
            1:
            Point2D(1, 0),
            # 1.0 collids with 1, so we check separately below.
            #1.0: Point2D(1.0, 0),
            1 + 1j:
            Point2D(1, 1),
            (1, 1):
            Point2D(1, 1),
        }
        for raw, expected in tests.items():
            with self.subTest(repr(raw)):
                p = Point2D.from_raw(raw)
                self.assertEqual(p, expected or raw)

        p = Point2D.from_raw(1.0)
        self.assertEqual(p, Point2D(1.0, 0))