def test_parse_unsupported(self): tests = [ # malformed pairs '(1,1', '1,1)', '[1,1', '1,1]', # unsupported pairs '1 1', '(1 1)', '[1 1]', '(,)', '(1,)', '(,1)', '(spam,spam)', # extra numbers '1,1,1', # not pairs '1', '1.0', 'spam', # malformed complex '1+1jj', 'x+1j', # non-strings object(), None, True, False, 0, 1, 1.0, [1, 1], (1, 1), { 1: 1 }, ] for raw in tests: with self.subTest(repr(raw)): with self.assertRaises(ValueError): Point2D.parse(raw)
def test_parse_supported(self): tests = { '1, 1': Point2D(1, 1), '1,1': Point2D(1, 1), '(1, 1)': Point2D(1, 1), '(1,1)': Point2D(1, 1), '[1, 1]': Point2D(1, 1), '[1,1]': Point2D(1, 1), '1.0,1.0': Point2D(1.0, 1.0), '1+1i': Point2D(1, 1), '1+1j': Point2D(1, 1), '-1,-1': Point2D(-1, -1), } for raw, expected in tests.items(): with self.subTest(repr(raw)): p = Point2D.parse(raw) self.assertEqual(p, expected)
def test_parse_empty(self): p = Point2D.parse('') self.assertEqual(p, Point2D())