Beispiel #1
0
def neighbor_json(json):
    """Read neighbor game from json"""
    utils.check(
        json['type'].split('.', 1)[0] == 'neighbor', 'incorrect type')
    return _NeighborDeviationGame(
        gamereader.loadj(json['model']),
        num_neighbors=json.get('neighbors', json.get('devs', None)))
Beispiel #2
0
def test_restriction_extract_file(game, game_file):
    """Test restriction extraction"""
    rest = game.random_restriction()
    rest_str = json.dumps([game.restriction_to_json(rest)])
    with stdin(rest_str), stdout() as out, stderr() as err:
        assert run('rest', '-i', game_file, '-f', '-'), err.getvalue()
    rgame = gamereader.loadj(json.loads(out.getvalue())[0])
    assert rgame == game.restrict(rest)
Beispiel #3
0
def fix_game(jgame):
    """Return game"""
    return gamegen.gen_profiles(gamereader.loadj(jgame))
Beispiel #4
0
def point_json(json):
    """Read point game from json"""
    utils.check(
        json['type'].split('.', 1)[0] == 'point', 'incorrect type')
    return _PointDeviationGame(gamereader.loadj(json['model']))
Beispiel #5
0
def sample_json(json):
    """Read sample game from json"""
    utils.check(
        json['type'].split('.', 1)[0] == 'sample', 'incorrect type')
    return _SampleDeviationGame(
        gamereader.loadj(json['model']), num_samples=json['samples'])
Beispiel #6
0
def canon_json(jgame):
    """Read a canonicalized game from json"""
    return canon(gamereader.loadj(jgame['game']))
def test_parse_fail():
    """Test invalid games"""
    with pytest.raises(ValueError):
        gamereader.loads('')
    with pytest.raises(ValueError):
        gamereader.loadj({'type': 'unknown.0'})
Beispiel #8
0
def canon_json(jgame):
    """Read a canonicalized game from json"""
    return canon(gamereader.loadj(jgame['game']))
Beispiel #9
0
def test_parse_fail():
    """Test invalid games"""
    with pytest.raises(ValueError):
        gamereader.loads('')
    with pytest.raises(ValueError):
        gamereader.loadj({'type': 'unknown.0'})
Beispiel #10
0
def neighbor_json(json):
    """Read neighbor game from json"""
    utils.check(json['type'].split('.', 1)[0] == 'neighbor', 'incorrect type')
    return _NeighborDeviationGame(gamereader.loadj(json['model']),
                                  num_neighbors=json.get(
                                      'neighbors', json.get('devs', None)))
Beispiel #11
0
def point_json(json):
    """Read point game from json"""
    utils.check(json['type'].split('.', 1)[0] == 'point', 'incorrect type')
    return _PointDeviationGame(gamereader.loadj(json['model']))
Beispiel #12
0
def sample_json(json):
    """Read sample game from json"""
    utils.check(json['type'].split('.', 1)[0] == 'sample', 'incorrect type')
    return _SampleDeviationGame(gamereader.loadj(json['model']),
                                num_samples=json['samples'])