Esempio n. 1
0
def test_presenter_interpret(tc):
    p9 = sgf_properties.Presenter(9, "UTF-8")
    p19 = sgf_properties.Presenter(19, "UTF-8")
    tc.assertEqual(p9.interpret('KO', [b""]), True)
    tc.assertEqual(p9.interpret('SZ', [b"9"]), 9)
    tc.assertRaisesRegex(ValueError, "multiple values", p9.interpret, 'SZ',
                         [b"9", b"blah"])
    tc.assertEqual(p9.interpret('CR', [b"ab", b"cd"]), {(5, 2), (7, 0)})
    tc.assertRaises(ValueError, p9.interpret, 'SZ', [])
    tc.assertRaises(ValueError, p9.interpret, 'CR', [])
    tc.assertEqual(p9.interpret('DD', [b""]), set())
    # all lists are treated like elists
    tc.assertEqual(p9.interpret('CR', [b""]), set())
Esempio n. 2
0
def test_presenter_serialise(tc):
    p9 = sgf_properties.Presenter(9, "UTF-8")
    p19 = sgf_properties.Presenter(19, "UTF-8")

    tc.assertEqual(p9.serialise('KO', True), [b""])
    tc.assertEqual(p9.serialise('SZ', 9), [b"9"])
    tc.assertEqual(p9.serialise('KM', 3.5), [b"3.5"])
    tc.assertEqual(p9.serialise('C', "foo\\:b]ar\n"), [b"foo\\\\:b\\]ar\n"])
    tc.assertEqual(p19.serialise('B', (1, 2)), [b"cr"])
    tc.assertEqual(p9.serialise('B', None), [b"tt"])
    tc.assertEqual(p19.serialise('AW', {(17, 1), (18, 0)}), [b"aa", b"bb"])
    tc.assertEqual(p9.serialise('DD', [(1, 2), (3, 4)]), [b"ch", b"ef"])
    tc.assertEqual(p9.serialise('DD', []), [b""])
    tc.assertRaisesRegex(ValueError, "empty list", p9.serialise, 'CR', [])
    tc.assertEqual(p9.serialise('AP', ("na:me", "2.3")), [b"na\\:me:2.3"])
    tc.assertEqual(p9.serialise('FG', (515, "th]is")), [b"515:th\\]is"])
    tc.assertEqual(p9.serialise('XX', "foo\\bar"), [b"foo\\\\bar"])

    tc.assertRaises(ValueError, p9.serialise, 'B', (1, 9))
Esempio n. 3
0
def test_presenter_private_properties(tc):
    p9 = sgf_properties.Presenter(9, "UTF-8")
    tc.assertEqual(p9.serialise('XX', "9"), [b"9"])
    tc.assertEqual(p9.interpret('XX', [b"9"]), "9")
    p9.set_private_property_type(p9.get_property_type("SZ"))
    tc.assertEqual(p9.serialise('XX', 9), [b"9"])
    tc.assertEqual(p9.interpret('XX', [b"9"]), 9)
    p9.set_private_property_type(None)
    tc.assertRaisesRegex(ValueError, "unknown property",
                         p9.serialise, 'XX', "foo\\bar")
    tc.assertRaisesRegex(ValueError, "unknown property",
                         p9.interpret, 'XX', [b"asd"])