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)))
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)
def fix_game(jgame): """Return game""" return gamegen.gen_profiles(gamereader.loadj(jgame))
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']))
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'])
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'})
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)))
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']))
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'])