Exemplo n.º 1
0
def test_one_line():
    short = "This is a short string, so it won't get truncated"
    assert utils.one_line(short, 100) == short, \
        "short string still got truncated"
    long_str = "This is relatively long"
    expected = "This is rela...g"
    assert utils.one_line(long_str, 16) == expected, \
        "one_line didn't truncate as expected"
Exemplo n.º 2
0
def _game_from_json(json_):
    """Returns constructor arguments for a game from parsed json"""
    if 'players' in json_ and 'strategies' in json_:
        return _ga_game_from_json(json_)
    elif not json_.get('profiles', ()):
        return _roles_from_json(json_)
    elif ('symmetry_groups' in json_['profiles'][0] and
          'observations' in json_['profiles'][0]):
        return _new_game_from_json(json_, _samples_profile_v4_from_json)
    elif 'symmetry_groups' in json_['profiles'][0]:
        return _new_game_from_json(json_, _profile_v3_from_json)
    elif 'observations' in json_['profiles'][0]:
        return _new_game_from_json(json_, _samples_profile_v3_from_json)
    elif 'strategy_array' in json_['roles'][0]:
        return _old_game_from_json(json_)
    elif 'strategies' in json_['roles'][0]:
        return _new_game_from_json(json_, _profile_v2_from_json)
    else:
        raise IOError(utils.one_line('invalid game JSON: {}'.format(json_),
                                     71))