Exemplo 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', [""]), True)
    tc.assertEqual(p9.interpret('SZ', ["9"]), 9)
    tc.assertRaisesRegexp(ValueError, "multiple values", p9.interpret, 'SZ',
                          ["9", "blah"])
    tc.assertEqual(p9.interpret('CR', ["ab", "cd"]), set([(5, 2), (7, 0)]))
    tc.assertRaises(ValueError, p9.interpret, 'SZ', [])
    tc.assertRaises(ValueError, p9.interpret, 'CR', [])
    tc.assertEqual(p9.interpret('DD', [""]), set())
    # all lists are treated like elists
    tc.assertEqual(p9.interpret('CR', [""]), set())
Exemplo n.º 2
0
 def __new__(cls, size, encoding="UTF-8", *args, **kwargs):
     # To complete initialisation after this, you need to set 'root'.
     if not 1 <= size <= 26:
         raise ValueError("size out of range: %s" % size)
     game = super(Sgf_game, cls).__new__(cls)
     game.size = size
     game.presenter = sgf_properties.Presenter(size, encoding)
     return game
Exemplo n.º 3
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), [""])
    tc.assertEqual(p9.serialise('SZ', 9), ["9"])
    tc.assertEqual(p9.serialise('KM', 3.5), ["3.5"])
    tc.assertEqual(p9.serialise('C', "foo\\:b]ar\n"), ["foo\\\\:b\\]ar\n"])
    tc.assertEqual(p19.serialise('B', (1, 2)), ["cr"])
    tc.assertEqual(p9.serialise('B', None), ["tt"])
    tc.assertEqual(p19.serialise('AW', set([(17, 1), (18, 0)])), ["aa", "bb"])
    tc.assertEqual(p9.serialise('DD', [(1, 2), (3, 4)]), ["ch", "ef"])
    tc.assertEqual(p9.serialise('DD', []), [""])
    tc.assertRaisesRegexp(ValueError, "empty list", p9.serialise, 'CR', [])
    tc.assertEqual(p9.serialise('AP', ("na:me", "2.3")), ["na\\:me:2.3"])
    tc.assertEqual(p9.serialise('FG', (515, "th]is")), ["515:th\\]is"])
    tc.assertEqual(p9.serialise('XX', "foo\\bar"), ["foo\\\\bar"])

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