rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
raise CmpetitionError( | raise CompetitionError( | def scale_parameters(self, optimiser_parameters): l = [] for pspec, v in zip(self.parameter_specs, optimiser_parameters): try: l.append(pspec.scale_fn(v)) except Exception: raise CmpetitionError( "error from scale_fn for %s\n%s" % (pspec.code, compact_tracebacks.format_traceback(skip=1))) return tuple(l) |
desribes what 0 values mean). time_settings None means the information isn't available. | describes what 0 values mean). time_settings None means the information isn't available. | def is_pass(self): return (self.coords is None) |
fx.ringmaster.set_clean_status() fx.ringmaster._open_files() fx.ringmaster._initialise_presenter() fx.ringmaster._initialise_terminal_reader() job = fx.ringmaster.get_job() | job = fx.get_job() | def test_get_job(tc): vals = { 'cmdline1' : "", 'cmdline2' : "sing song", } fx = Ringmaster_fixture(tc, simple_ctl.substitute(vals)) fx.ringmaster.set_clean_status() fx.ringmaster._open_files() fx.ringmaster._initialise_presenter() fx.ringmaster._initialise_terminal_reader() job = fx.ringmaster.get_job() tc.assertEqual... |
fx.ringmaster.set_clean_status() fx.ringmaster._open_files() fx.ringmaster._initialise_presenter() fx.ringmaster._initialise_terminal_reader() job = fx.ringmaster.get_job() | job = fx.get_job() | def test_settings(tc): vals = { 'cmdline1' : "", 'cmdline2' : "", } extra = "\n".join([ "handicap = 9", "handicap_style = 'free'", "record_games = True", "scorer = 'players'" ]) fx = Ringmaster_fixture(tc, simple_ctl.substitute(vals) + extra) fx.ringmaster.enable_gtp_logging() fx.ringmaster.set_clean_status() fx.ringma... |
fx.ringmaster.set_clean_status() fx.ringmaster._open_files() fx.ringmaster._initialise_presenter() fx.ringmaster._initialise_terminal_reader() job = fx.ringmaster.get_job() | job = fx.get_job() | def test_stderr_settings(tc): vals = { 'cmdline1' : "", 'cmdline2' : "", } extra = "\n".join([ "players['p1'] = Player('test')\n" ]) fx = Ringmaster_fixture(tc, simple_ctl.substitute(vals) + extra) fx.ringmaster.set_clean_status() fx.ringmaster._open_files() fx.ringmaster._initialise_presenter() fx.ringmaster._initiali... |
fx.ringmaster.set_clean_status() fx.ringmaster._open_files() fx.ringmaster._initialise_presenter() fx.ringmaster._initialise_terminal_reader() job = fx.ringmaster.get_job() | job = fx.get_job() | def test_stderr_settings_nolog(tc): vals = { 'cmdline1' : "", 'cmdline2' : "", } extra = "\n".join([ "players['p1'] = Player('test')\n" "stderr_to_log = False\n" ]) fx = Ringmaster_fixture(tc, simple_ctl.substitute(vals) + extra) fx.ringmaster.set_clean_status() fx.ringmaster._open_files() fx.ringmaster._initialise_pre... |
engine_names -- map colour -> string engine_descriptions -- map colour -> string | engine_names -- map player code -> string engine_descriptions -- map player code -> string | def __init__(self): self.gtp_translations = {} |
self.write_status() | def process_response(self, response): """Job response function for the job manager.""" self.log("response from game %s" % response.game_id) self.competition.process_game_result(response) del self.games_in_progress[response.game_id] if not self.stopping_quietly: self.write_status() self.update_display() if self.chatty: ... | |
stderr_b = open(self.player_b.stderr_pathname, "wa") | stderr_b = open(self.player_b.stderr_pathname, "a") | def run(self): game = gtp_games.Game( {'b' : self.player_b.code, 'w' : self.player_w.code}, {'b' : self.player_b.cmd_args, 'w' : self.player_w.cmd_args}, self.board_size, self.komi, self.move_limit) if self.use_internal_scorer: game.use_internal_scorer() else: if self.player_b.is_reliable_scorer: game.allow_scorer('b')... |
stderr_w = open(self.player_w.stderr_pathname, "wa") | stderr_w = open(self.player_w.stderr_pathname, "a") | def run(self): game = gtp_games.Game( {'b' : self.player_b.code, 'w' : self.player_w.code}, {'b' : self.player_b.cmd_args, 'w' : self.player_w.cmd_args}, self.board_size, self.komi, self.move_limit) if self.use_internal_scorer: game.use_internal_scorer() else: if self.player_b.is_reliable_scorer: game.allow_scorer('b')... |
"""Interpret Python code from a string. source -- string | """Interpret Python code from a unicode string. source -- unicode object | def interpret_python(source, provided_globals): """Interpret Python code from a string. source -- string provided_globals -- dict The string is executed with a copy of provided_globals as the global and local namespace. Returns that namespace. """ result = provided_globals.copy() exec source in result retu... |
exec source in result | code = compile(source, "<control file>", 'exec', division.compiler_flag, True) exec code in result | def interpret_python(source, provided_globals): """Interpret Python code from a string. source -- string provided_globals -- dict The string is executed with a copy of provided_globals as the global and local namespace. Returns that namespace. """ result = provided_globals.copy() exec source in result retu... |
control_s, self.competition.control_file_globals()) | control_u, self.competition.control_file_globals()) | def _load_control_file(self): """Main implementation for __init__.""" |
return ValueError | raise ValueError | def opponent_of(colour): """Return the opponent colour. colour -- 'b' or 'w' Returns 'b' or 'w'. """ try: return _opponents[colour] except KeyError: return ValueError |
commands -- map colour -> command used to launch the program | def __repr__(self): return "<Game_result: %s>" % self.describe() | |
expanded node in this tree has dimension*branching_factor children. | expanded node in this tree has branching_factor**dimension children. | def __repr__(self): return "<Node:%.2f{%s}>" % (self.value, repr(self.children)) |
In particular, this rejects unicode objects and strings contaning spaces. | In particular, this rejects unicode objects and strings containing spaces. | def is_well_formed_gtp_word(s): """Check whether 's' is well-formed as a single GTP word. In particular, this rejects unicode objects and strings contaning spaces. """ if not isinstance(s, str): return False if not _gtp_word_characters_re.search(s): return False return True |
player = game_jobs.Player() player.code = 'test' player.cmd_args = ['test'] check = game_jobs.Player_check() check.player = player check.board_size = 9 check.komi = 7.0 game_jobs.check_player(check) | ck = Player_check_fixture(tc) game_jobs.check_player(ck.check) | def test_check_player(tc): fx = gtp_engine_fixtures.Mock_subprocess_fixture(tc) player = game_jobs.Player() player.code = 'test' player.cmd_args = ['test'] check = game_jobs.Player_check() check.player = player check.board_size = 9 check.komi = 7.0 game_jobs.check_player(check) |
player = game_jobs.Player() player.code = 'test' player.cmd_args = ['no_boardsize'] check = game_jobs.Player_check() check.player = player check.board_size = 9 check.komi = 7.0 | ck = Player_check_fixture(tc) ck.player.cmd_args = ['no_boardsize'] | def test_check_player_boardsize_fails(tc): fx = gtp_engine_fixtures.Mock_subprocess_fixture(tc) engine = gtp_engine_fixtures.get_test_engine() fx.register_engine('no_boardsize', engine) player = game_jobs.Player() player.code = 'test' player.cmd_args = ['no_boardsize'] check = game_jobs.Player_check() check.player = ... |
game_jobs.check_player(check) | game_jobs.check_player(ck.check) | def test_check_player_boardsize_fails(tc): fx = gtp_engine_fixtures.Mock_subprocess_fixture(tc) engine = gtp_engine_fixtures.get_test_engine() fx.register_engine('no_boardsize', engine) player = game_jobs.Player() player.code = 'test' player.cmd_args = ['no_boardsize'] check = game_jobs.Player_check() check.player = ... |
def do_run(ringmaster, worker_count=None, max_games=None): | def do_run(ringmaster, options): if options.log_gtp: ringmaster.enable_gtp_logging() if options.quiet: ringmaster.set_quiet_mode() | def do_run(ringmaster, worker_count=None, max_games=None): if ringmaster.status_file_exists(): ringmaster.load_status() else: ringmaster.set_clean_status() if worker_count is not None: ringmaster.set_parallel_worker_count(worker_count) ringmaster.run(max_games) ringmaster.report() |
if worker_count is not None: ringmaster.set_parallel_worker_count(worker_count) ringmaster.run(max_games) | if options.parallel is not None: ringmaster.set_parallel_worker_count(options.parallel) ringmaster.run(options.max_games) | def do_run(ringmaster, worker_count=None, max_games=None): if ringmaster.status_file_exists(): ringmaster.load_status() else: ringmaster.set_clean_status() if worker_count is not None: ringmaster.set_parallel_worker_count(worker_count) ringmaster.run(max_games) ringmaster.report() |
def do_show(ringmaster): if not ringmaster.status_file_exists(): raise RingmasterError("no status file") ringmaster.load_status() ringmaster.print_status_report() def do_report(ringmaster): if not ringmaster.status_file_exists(): raise RingmasterError("no status file") ringmaster.load_status() ringmaster.report() def... | def do_stop(ringmaster, options): | def do_show(ringmaster): if not ringmaster.status_file_exists(): raise RingmasterError("no status file") ringmaster.load_status() ringmaster.print_status_report() |
def do_reset(ringmaster): | def do_show(ringmaster, options): if not ringmaster.status_file_exists(): raise RingmasterError("no status file") ringmaster.load_status() ringmaster.print_status_report() def do_report(ringmaster, options): if not ringmaster.status_file_exists(): raise RingmasterError("no status file") ringmaster.load_status() ringma... | def do_reset(ringmaster): ringmaster.delete_state_and_output() |
if command not in ("run", "stop", "show", "report", "reset", "check", "debugstatus"): parser.error("no such command: %s" % command) | try: action = _actions[command] except KeyError: parser.error("no such command: %s" % command) | def run(argv, ringmaster_class): usage = ("%prog [options] <control file> [command]\n\n" "commands: run (default), stop, show, report, reset, check") parser = OptionParser(usage=usage, prog="ringmaster") parser.add_option("--max-games", "-g", type="int", help="maximum number of games to play in this run") parser.add_op... |
exit_status = 0 | def run(argv, ringmaster_class): usage = ("%prog [options] <control file> [command]\n\n" "commands: run (default), stop, show, report, reset, check") parser = OptionParser(usage=usage, prog="ringmaster") parser.add_option("--max-games", "-g", type="int", help="maximum number of games to play in this run") parser.add_op... | |
if command == "run": if options.log_gtp: ringmaster.enable_gtp_logging() if options.quiet: ringmaster.set_quiet_mode() do_run(ringmaster, options.parallel, options.max_games) elif command == "show": do_show(ringmaster) elif command == "stop": do_stop(ringmaster) elif command == "report": do_report(ringmaster) elif comm... | exit_status = action(ringmaster, options) | def run(argv, ringmaster_class): usage = ("%prog [options] <control file> [command]\n\n" "commands: run (default), stop, show, report, reset, check") parser = OptionParser(usage=usage, prog="ringmaster") parser.add_option("--max-games", "-g", type="int", help="maximum number of games to play in this run") parser.add_op... |
game_id -- int | game_id -- short string | def __init__(self): self.gtp_translations = {} |
self.issued -= len(self.to_reissue) | def rollback(self): """Make issued-but-not-fixed tokens available again.""" self.to_reissue.update(self.outstanding) self.outstanding = set() self.issued -= len(self.to_reissue) | |
A copy of tournament_globals is used as the global namespace. Returns this | A copy of control_file_globals is used as the global namespace. Returns this | def read_tourn_file(pathname): """Read the specified file as a .tourn file. A copy of tournament_globals is used as the global namespace. Returns this namespace as a dict. """ result = control_file_globals.copy() f = open(pathname) exec f in result f.close() return result |
files_to_remove.append() | files_to_remove.append(pathname) | def run(self): files_to_remove = [] dirs_to_remove = [] |
Returns the result text from the engine as a string with no leading or trailing whitespace. (This doesn't include the leading =[id] bit.) | Returns the result text from the engine as a string with no trailing whitespace. It may contain newlines, but there are no empty lines except perhaps the first. There is no leading whitespace on the first line. (It doesn't include the leading =[id] bit.) | def do_command(self, channel_id, command, *arguments): """Send a command over a channel and return the response. |
def test_basic_config(tc): comp = playoffs.Playoff('test') config = { | def check_screen_report(tc, comp, expected): """Check that a competition's screen report is as expected.""" out = StringIO() comp.write_screen_report(out) tc.assertMultiLineEqual(out.getvalue(), expected) class Playoff_fixture(test_framework.Fixture): """Fixture setting up a Playoff. attributes: comp -- Playoff... | def test_basic_config(tc): comp = playoffs.Playoff('test') config = { 'players' : { 't1' : Player_config("test"), 't2' : Player_config("test"), }, 'board_size' : 13, 'komi' : 7.5, 'matchups' : [ Matchup_config( 't1', 't2', board_size=9, komi=0.5, alternating=True, handicap=6, handicap_style='free', move_limit=50, scor... |
't1' : Player_config("test"), 't2' : Player_config("test"), | 't1' : Player_config("test1"), 't2' : Player_config("test2"), | def test_basic_config(tc): comp = playoffs.Playoff('test') config = { 'players' : { 't1' : Player_config("test"), 't2' : Player_config("test"), }, 'board_size' : 13, 'komi' : 7.5, 'matchups' : [ Matchup_config( 't1', 't2', board_size=9, komi=0.5, alternating=True, handicap=6, handicap_style='free', move_limit=50, scor... |
], } | ] | def test_basic_config(tc): comp = playoffs.Playoff('test') config = { 'players' : { 't1' : Player_config("test"), 't2' : Player_config("test"), }, 'board_size' : 13, 'komi' : 7.5, 'matchups' : [ Matchup_config( 't1', 't2', board_size=9, komi=0.5, alternating=True, handicap=6, handicap_style='free', move_limit=50, scor... |
comp = playoffs.Playoff('test') config = { 'players' : { 't1' : Player_config("test"), 't2' : Player_config("test"), }, 'board_size' : 12, 'handicap' : 6, 'komi' : 7.5, 'matchups' : [ Matchup_config('t1', 't2'), ], } | comp = playoffs.Playoff('testcomp') config = default_config() config['board_size'] = 12 config['handicap'] = 6 | def test_global_handicap_validation(tc): comp = playoffs.Playoff('test') config = { 'players' : { 't1' : Player_config("test"), 't2' : Player_config("test"), }, 'board_size' : 12, 'handicap' : 6, 'komi' : 7.5, 'matchups' : [ Matchup_config('t1', 't2'), ], } with tc.assertRaises(ControlFileError) as ar: comp.initialise... |
comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't1', number_of_games=1000), ], } comp.initialise_from_control_file(config) comp.set_clean_status() tc.assertEqual(comp.get_game().game_id, '0_000') | config = default_config() config['matchups'][0] = Matchup_config('t1', 't2', number_of_games=1000) fx = Playoff_fixture(tc, config) tc.assertEqual(fx.comp.get_game().game_id, '0_000') | def test_game_id_format(tc): comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't1', number_of_games=1000), ], } comp.initialise_from_control_file(config) comp.set_clean_status() tc.assertEqual(comp.get_gam... |
comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], } comp.initialise_from_control_file(config) comp.set_clean_status() job1 = comp.get_game() | fx = Playoff_fixture(tc) job1 = fx.comp.get_game() | def test_play(tc): comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], } comp.initialise_from_control_file(config) comp.set_clean_status() job1 = co... |
tc.assertEqual(job1.board_size, 12) tc.assertEqual(job1.komi, 3.5) | tc.assertEqual(job1.board_size, 13) tc.assertEqual(job1.komi, 7.5) | def test_play(tc): comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], } comp.initialise_from_control_file(config) comp.set_clean_status() job1 = co... |
job2 = comp.get_game() | job2 = fx.comp.get_game() | def test_play(tc): comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], } comp.initialise_from_control_file(config) comp.set_clean_status() job1 = co... |
comp.process_game_result(response1) out = StringIO() comp.write_screen_report(out) tc.assertMultiLineEqual( out.getvalue(), | fx.comp.process_game_result(response1) fx.check_screen_report( | def test_play(tc): comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], } comp.initialise_from_control_file(config) comp.set_clean_status() job1 = co... |
"board size: 12 komi: 3.5\n" | "board size: 13 komi: 7.5\n" | def test_play(tc): comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], } comp.initialise_from_control_file(config) comp.set_clean_status() job1 = co... |
tc.assertListEqual(comp.get_matchup_results('0'), [('0_0', result1)]) | tc.assertListEqual(fx.comp.get_matchup_results('0'), [('0_0', result1)]) | def test_play(tc): comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], } comp.initialise_from_control_file(config) comp.set_clean_status() job1 = co... |
comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], } comp.initialise_from_control_file(config) comp.set_clean_status() jobs = [comp.get_game() for ... | fx = Playoff_fixture(tc) jobs = [fx.comp.get_game() for _ in range(8)] | def test_play_many(tc): comp = playoffs.Playoff('testcomp') config = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], } comp.initialise_from_control_file(config) comp.set_clean_status() jobs... |
comp.process_game_result(response) jobs += [comp.get_game() for _ in range(3)] | fx.comp.process_game_result(response) jobs += [fx.comp.get_game() for _ in range(3)] | def fake_response(job, winner): result = Game_result({'b' : 't1', 'w' : 't2'}, winner) response = Game_job_result() response.game_id = job.game_id response.game_result = result response.engine_names = {} response.engine_descriptions = {} response.game_data = job.game_data return response |
comp.process_game_result(response) out = StringIO() comp.write_screen_report(out) tc.assertMultiLineEqual( out.getvalue(), | fx.comp.process_game_result(response) fx.check_screen_report( | def fake_response(job, winner): result = Game_result({'b' : 't1', 'w' : 't2'}, winner) response = Game_job_result() response.game_id = job.game_id response.game_result = result response.engine_names = {} response.engine_descriptions = {} response.game_data = job.game_data return response |
"board size: 12 komi: 3.5\n" | "board size: 13 komi: 7.5\n" | def fake_response(job, winner): result = Game_result({'b' : 't1', 'w' : 't2'}, winner) response = Game_job_result() response.game_id = job.game_id response.game_result = result response.engine_names = {} response.engine_descriptions = {} response.game_data = job.game_data return response |
tc.assertEqual(len(comp.get_matchup_results('0')), 6) config2 = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't2', alternating=True), ], } | tc.assertEqual(len(fx.comp.get_matchup_results('0')), 6) | def fake_response(job, winner): result = Game_result({'b' : 't1', 'w' : 't2'}, winner) response = Game_job_result() response.game_id = job.game_id response.game_result = result response.engine_names = {} response.engine_descriptions = {} response.game_data = job.game_data return response |
comp2.initialise_from_control_file(config2) comp2.set_status(comp.get_status()) | comp2.initialise_from_control_file(default_config()) status = pickle.loads(pickle.dumps(fx.comp.get_status())) comp2.set_status(status) | def fake_response(job, winner): result = Game_result({'b' : 't1', 'w' : 't2'}, winner) response = Game_job_result() response.game_id = job.game_id response.game_result = result response.engine_names = {} response.engine_descriptions = {} response.game_data = job.game_data return response |
jobs2 = [comp.get_game() for _ in range(4)] | jobs2 = [comp2.get_game() for _ in range(4)] | def fake_response(job, winner): result = Game_result({'b' : 't1', 'w' : 't2'}, winner) response = Game_job_result() response.game_id = job.game_id response.game_result = result response.engine_names = {} response.engine_descriptions = {} response.game_data = job.game_data return response |
config2 = { 'players' : { 't1' : Player_config("test1"), 't2' : Player_config("test2"), 't3' : Player_config("test3"), }, 'board_size' : 12, 'komi' : 3.5, 'matchups' : [ Matchup_config('t1', 't3', alternating=True), ], } | config2 = default_config() config2['players']['t3'] = Player_config("test3") config2['matchups'][0] = Matchup_config('t1', 't3', alternating=True) | def fake_response(job, winner): result = Game_result({'b' : 't1', 'w' : 't2'}, winner) response = Game_job_result() response.game_id = job.game_id response.game_result = result response.engine_names = {} response.engine_descriptions = {} response.game_data = job.game_data return response |
comp2.set_status(comp.get_status()) | comp2.set_status(status) | def fake_response(job, winner): result = Game_result({'b' : 't1', 'w' : 't2'}, winner) response = Game_job_result() response.game_id = job.game_id response.game_result = result response.engine_names = {} response.engine_descriptions = {} response.game_data = job.game_data return response |
def _make_proxy(): channel = gtp_engine_fixtures.get_test_channel() controller = gtp_controller.Gtp_controller(channel, 'testbackend') proxy = gtp_proxy.Gtp_proxy() proxy.set_back_end_controller(controller) proxy._commands_handled = controller.channel.engine.commands_handled return proxy | class Proxy_fixture(test_framework.Fixture): """Fixture managing a Gtp_proxy with the test engine as its back-end. attributes: proxy -- Gtp_proxy controller -- Gtp_controller channel -- Testing_gtp_channel (like get_test_channel()) engine -- the proxy engine underlying_engine --... | def _make_proxy(): channel = gtp_engine_fixtures.get_test_channel() controller = gtp_controller.Gtp_controller(channel, 'testbackend') proxy = gtp_proxy.Gtp_proxy() proxy.set_back_end_controller(controller) # Make the commands from the underlying Recording_gtp_engine_protocol # available to tests proxy._commands_handle... |
proxy = _make_proxy() check_engine(tc, proxy.engine, 'test', ['ab', 'cd'], "args: ab cd") proxy.close() | fx = Proxy_fixture(tc) fx.check_command('test', ['ab', 'cd'], "args: ab cd") fx.proxy.close() | def test_proxy(tc): proxy = _make_proxy() check_engine(tc, proxy.engine, 'test', ['ab', 'cd'], "args: ab cd") proxy.close() tc.assertEqual( proxy._commands_handled, [('list_commands', []), ('test', ['ab', 'cd']), ('quit', [])]) tc.assertTrue(proxy.controller.channel.is_closed) |
proxy._commands_handled, | fx.commands_handled, | def test_proxy(tc): proxy = _make_proxy() check_engine(tc, proxy.engine, 'test', ['ab', 'cd'], "args: ab cd") proxy.close() tc.assertEqual( proxy._commands_handled, [('list_commands', []), ('test', ['ab', 'cd']), ('quit', [])]) tc.assertTrue(proxy.controller.channel.is_closed) |
tc.assertTrue(proxy.controller.channel.is_closed) | tc.assertTrue(fx.controller.channel.is_closed) | def test_proxy(tc): proxy = _make_proxy() check_engine(tc, proxy.engine, 'test', ['ab', 'cd'], "args: ab cd") proxy.close() tc.assertEqual( proxy._commands_handled, [('list_commands', []), ('test', ['ab', 'cd']), ('quit', [])]) tc.assertTrue(proxy.controller.channel.is_closed) |
proxy = _make_proxy() check_engine(tc, proxy.engine, 'quit', [], "", expect_end=True) proxy.close() | fx = Proxy_fixture(tc) fx.check_command('quit', [], "", expect_end=True) fx.proxy.close() | def test_close_after_quit(tc): proxy = _make_proxy() check_engine(tc, proxy.engine, 'quit', [], "", expect_end=True) proxy.close() tc.assertEqual( proxy._commands_handled, [('list_commands', []), ('quit', [])]) tc.assertTrue(proxy.controller.channel.is_closed) |
proxy._commands_handled, | fx.commands_handled, | def test_close_after_quit(tc): proxy = _make_proxy() check_engine(tc, proxy.engine, 'quit', [], "", expect_end=True) proxy.close() tc.assertEqual( proxy._commands_handled, [('list_commands', []), ('quit', [])]) tc.assertTrue(proxy.controller.channel.is_closed) |
tc.assertTrue(proxy.controller.channel.is_closed) | tc.assertTrue(fx.channel.is_closed) | def test_close_after_quit(tc): proxy = _make_proxy() check_engine(tc, proxy.engine, 'quit', [], "", expect_end=True) proxy.close() tc.assertEqual( proxy._commands_handled, [('list_commands', []), ('quit', [])]) tc.assertTrue(proxy.controller.channel.is_closed) |
proxy = _make_proxy() | fx = Proxy_fixture(tc) | def test_list_commands(tc): proxy = _make_proxy() tc.assertListEqual( proxy.engine.list_commands(), ['error', 'fatal', 'gomill-passthrough', 'known_command', 'list_commands', 'multiline', 'protocol_version', 'quit', 'test']) proxy.close() |
proxy.engine.list_commands(), | fx.engine.list_commands(), | def test_list_commands(tc): proxy = _make_proxy() tc.assertListEqual( proxy.engine.list_commands(), ['error', 'fatal', 'gomill-passthrough', 'known_command', 'list_commands', 'multiline', 'protocol_version', 'quit', 'test']) proxy.close() |
proxy.close() | fx.proxy.close() | def test_list_commands(tc): proxy = _make_proxy() tc.assertListEqual( proxy.engine.list_commands(), ['error', 'fatal', 'gomill-passthrough', 'known_command', 'list_commands', 'multiline', 'protocol_version', 'quit', 'test']) proxy.close() |
proxy = _make_proxy() tc.assertTrue(proxy.back_end_has_command('test')) tc.assertFalse(proxy.back_end_has_command('xyzzy')) tc.assertFalse(proxy.back_end_has_command('gomill-passthrough')) | fx = Proxy_fixture(tc) tc.assertTrue(fx.proxy.back_end_has_command('test')) tc.assertFalse(fx.proxy.back_end_has_command('xyzzy')) tc.assertFalse(fx.proxy.back_end_has_command('gomill-passthrough')) | def test_back_end_has_command(tc): proxy = _make_proxy() tc.assertTrue(proxy.back_end_has_command('test')) tc.assertFalse(proxy.back_end_has_command('xyzzy')) tc.assertFalse(proxy.back_end_has_command('gomill-passthrough')) |
proxy = _make_proxy() check_engine(tc, proxy.engine, 'known_command', ['gomill-passthrough'], "true") check_engine(tc, proxy.engine, 'gomill-passthrough', ['test', 'ab', 'cd'], "args: ab cd") check_engine(tc, proxy.engine, 'gomill-passthrough', ['known_command', 'gomill-passthrough'], "false") check_engine(tc, proxy.en... | fx = Proxy_fixture(tc) fx.check_command('known_command', ['gomill-passthrough'], "true") fx.check_command('gomill-passthrough', ['test', 'ab', 'cd'], "args: ab cd") fx.check_command( 'gomill-passthrough', ['known_command', 'gomill-passthrough'], "false") fx.check_command('gomill-passthrough', [], "invalid arguments", e... | def test_passthrough(tc): proxy = _make_proxy() check_engine(tc, proxy.engine, 'known_command', ['gomill-passthrough'], "true") check_engine(tc, proxy.engine, 'gomill-passthrough', ['test', 'ab', 'cd'], "args: ab cd") check_engine(tc, proxy.engine, 'gomill-passthrough', ['known_command', 'gomill-passthrough'], "false")... |
proxy._commands_handled, | fx.commands_handled, | def test_passthrough(tc): proxy = _make_proxy() check_engine(tc, proxy.engine, 'known_command', ['gomill-passthrough'], "true") check_engine(tc, proxy.engine, 'gomill-passthrough', ['test', 'ab', 'cd'], "args: ab cd") check_engine(tc, proxy.engine, 'gomill-passthrough', ['known_command', 'gomill-passthrough'], "false")... |
proxy = _make_proxy() tc.assertEqual(proxy.pass_command("test", ["ab", "cd"]), "args: ab cd") | fx = Proxy_fixture(tc) tc.assertEqual(fx.proxy.pass_command("test", ["ab", "cd"]), "args: ab cd") | def test_pass_command(tc): proxy = _make_proxy() tc.assertEqual(proxy.pass_command("test", ["ab", "cd"]), "args: ab cd") with tc.assertRaises(BadGtpResponse) as ar: proxy.pass_command("error", []) tc.assertEqual(ar.exception.gtp_error_message, "normal error") tc.assertEqual(str(ar.exception), "failure response from 'er... |
proxy.pass_command("error", []) | fx.proxy.pass_command("error", []) | def test_pass_command(tc): proxy = _make_proxy() tc.assertEqual(proxy.pass_command("test", ["ab", "cd"]), "args: ab cd") with tc.assertRaises(BadGtpResponse) as ar: proxy.pass_command("error", []) tc.assertEqual(ar.exception.gtp_error_message, "normal error") tc.assertEqual(str(ar.exception), "failure response from 'er... |
proxy = _make_proxy() proxy.controller.channel.fail_next_command = True with tc.assertRaises(BackEndError) as ar: proxy.pass_command("test", []) | fx = Proxy_fixture(tc) fx.channel.fail_next_command = True with tc.assertRaises(BackEndError) as ar: fx.proxy.pass_command("test", []) | def test_pass_command_with_channel_error(tc): proxy = _make_proxy() proxy.controller.channel.fail_next_command = True with tc.assertRaises(BackEndError) as ar: proxy.pass_command("test", []) tc.assertEqual(str(ar.exception), "transport error sending 'test' to testbackend:\n" "forced failure for send_command_line") tc.a... |
proxy.close() tc.assertEqual(proxy._commands_handled, [('list_commands', [])]) | fx.proxy.close() tc.assertEqual(fx.commands_handled, [('list_commands', [])]) | def test_pass_command_with_channel_error(tc): proxy = _make_proxy() proxy.controller.channel.fail_next_command = True with tc.assertRaises(BackEndError) as ar: proxy.pass_command("test", []) tc.assertEqual(str(ar.exception), "transport error sending 'test' to testbackend:\n" "forced failure for send_command_line") tc.a... |
return proxy.handle_command("error", []) | return fx.proxy.handle_command("error", []) | def handle_xyzzy(args): if args and args[0] == "error": return proxy.handle_command("error", []) else: return proxy.handle_command("test", ["nothing", "happens"]) |
return proxy.handle_command("test", ["nothing", "happens"]) proxy = _make_proxy() proxy.engine.add_command("xyzzy", handle_xyzzy) check_engine(tc, proxy.engine, 'xyzzy', [], "args: nothing happens") check_engine(tc, proxy.engine, 'xyzzy', ['error'], "normal error", expect_failure=True) | return fx.proxy.handle_command("test", ["nothing", "happens"]) fx = Proxy_fixture(tc) fx.engine.add_command("xyzzy", handle_xyzzy) fx.check_command('xyzzy', [], "args: nothing happens") fx.check_command('xyzzy', ['error'], "normal error", expect_failure=True) | def handle_xyzzy(args): if args and args[0] == "error": return proxy.handle_command("error", []) else: return proxy.handle_command("test", ["nothing", "happens"]) |
return proxy.handle_command("test", []) proxy = _make_proxy() proxy.engine.add_command("xyzzy", handle_xyzzy) proxy.controller.channel.fail_next_command = True check_engine(tc, proxy.engine, 'xyzzy', [], "transport error sending 'test' to testbackend:\n" "forced failure for send_command_line", expect_failure=True, expe... | return fx.proxy.handle_command("test", []) fx = Proxy_fixture(tc) fx.engine.add_command("xyzzy", handle_xyzzy) fx.channel.fail_next_command = True fx.check_command('xyzzy', [], "transport error sending 'test' to testbackend:\n" "forced failure for send_command_line", expect_failure=True, expect_end=True) fx.proxy.close... | def handle_xyzzy(args): return proxy.handle_command("test", []) |
proxy = _make_proxy() tc.assertEqual(proxy.pass_command("quit", []), "") check_engine(tc, proxy.engine, 'test', ['ab', 'cd'], "error sending 'test ab cd' to testbackend:\n" "engine has closed the command channel", expect_failure=True, expect_end=True) | fx = Proxy_fixture(tc) tc.assertEqual(fx.proxy.pass_command("quit", []), "") fx.check_command('test', ['ab', 'cd'], "error sending 'test ab cd' to testbackend:\n" "engine has closed the command channel", expect_failure=True, expect_end=True) | def test_back_end_goes_away(tc): proxy = _make_proxy() tc.assertEqual(proxy.pass_command("quit", []), "") check_engine(tc, proxy.engine, 'test', ['ab', 'cd'], "error sending 'test ab cd' to testbackend:\n" "engine has closed the command channel", expect_failure=True, expect_end=True) |
proxy = _make_proxy() proxy.controller.channel.fail_next_command = True with tc.assertRaises(BackEndError) as ar: proxy.close() | fx = Proxy_fixture(tc) fx.channel.fail_next_command = True with tc.assertRaises(BackEndError) as ar: fx.proxy.close() | def test_close_with_errors(tc): proxy = _make_proxy() proxy.controller.channel.fail_next_command = True with tc.assertRaises(BackEndError) as ar: proxy.close() tc.assertEqual(str(ar.exception), "transport error sending 'quit' to testbackend:\n" "forced failure for send_command_line") tc.assertTrue(proxy.controller.chan... |
tc.assertTrue(proxy.controller.channel.is_closed) | tc.assertTrue(fx.channel.is_closed) | def test_close_with_errors(tc): proxy = _make_proxy() proxy.controller.channel.fail_next_command = True with tc.assertRaises(BackEndError) as ar: proxy.close() tc.assertEqual(str(ar.exception), "transport error sending 'quit' to testbackend:\n" "forced failure for send_command_line") tc.assertTrue(proxy.controller.chan... |
proxy = _make_proxy() tc.assertEqual(proxy.pass_command("quit", []), "") check_engine(tc, proxy.engine, 'quit', [], "", expect_end=True) proxy.close() tc.assertEqual(proxy._commands_handled, | fx = Proxy_fixture(tc) tc.assertEqual(fx.proxy.pass_command("quit", []), "") fx.check_command('quit', [], "", expect_end=True) fx.proxy.close() tc.assertEqual(fx.commands_handled, | def test_quit_ignores_already_closed(tc): proxy = _make_proxy() tc.assertEqual(proxy.pass_command("quit", []), "") check_engine(tc, proxy.engine, 'quit', [], "", expect_end=True) proxy.close() tc.assertEqual(proxy._commands_handled, [('list_commands', []), ('quit', [])]) |
proxy = _make_proxy() proxy.controller.channel.engine.add_command("quit", force_error) check_engine(tc, proxy.engine, 'quit', [], None, | fx = Proxy_fixture(tc) fx.underlying_engine.add_command("quit", force_error) fx.check_command('quit', [], None, | def force_error(args): 1 / 0 |
proxy.close() tc.assertEqual(proxy._commands_handled, | fx.proxy.close() tc.assertEqual(fx.commands_handled, | def force_error(args): 1 / 0 |
proxy = _make_proxy() proxy.controller.channel.fail_next_command = True check_engine(tc, proxy.engine, 'quit', [], "transport error sending 'quit' to testbackend:\n" "forced failure for send_command_line", expect_failure=True, expect_end=True) proxy.close() tc.assertEqual(proxy._commands_handled, [('list_commands', [])... | fx = Proxy_fixture(tc) fx.channel.fail_next_command = True fx.check_command('quit', [], "transport error sending 'quit' to testbackend:\n" "forced failure for send_command_line", expect_failure=True, expect_end=True) fx.proxy.close() tc.assertEqual(fx.commands_handled, [('list_commands', [])]) | def test_quit_with_channel_error(tc): proxy = _make_proxy() proxy.controller.channel.fail_next_command = True check_engine(tc, proxy.engine, 'quit', [], "transport error sending 'quit' to testbackend:\n" "forced failure for send_command_line", expect_failure=True, expect_end=True) proxy.close() tc.assertEqual(proxy._co... |
Raises ValueError with an appropriate message if 'arg' isn't a valid GTP | Raises ValueError with an appropriate message if 'vertex' isn't a valid GTP | def coords_from_vertex(vertex, board_size): """Interpret a string representing a vertex, as specified by GTP. Returns a pair of coordinates (row, col) in range(0, board_size) Raises ValueError with an appropriate message if 'arg' isn't a valid GTP vertex specification for a board of size 'board_size'. """ if not 0 <... |
if isinstance(b_score, Exception): | if b_score is Exception: | def handle_final_score_b(args): if isinstance(b_score, Exception): raise b_score return b_score |
if isinstance(w_score, Exception): | if w_score is Exception: | def handle_final_score_w(args): if isinstance(w_score, Exception): raise w_score return w_score |
fx.run_score_test("black wins", "W+4") tc.assertEqual(fx.game.result.sgf_result, "W+4") tc.assertIsNone(fx.game.result.detail) tc.assertEqual(fx.game.result.winning_colour, 'w') | fx.run_score_test("black wins", "W+4.5") tc.assertEqual(fx.game.result.sgf_result, "W+4.5") tc.assertIsNone(fx.game.result.detail) tc.assertEqual(fx.game.result.winning_colour, 'w') tc.assertEqual(fx.game.describe_scoring(), "two beat one W+4.5\n" "one final_score: black wins\n" "two final_score: W+4.5") | def test_players_score_one_illformed(tc): fx = Game_fixture(tc) fx.run_score_test("black wins", "W+4") tc.assertEqual(fx.game.result.sgf_result, "W+4") tc.assertIsNone(fx.game.result.detail) tc.assertEqual(fx.game.result.winning_colour, 'w') |
fx.run_score_test("b+3", "B+4") | fx.run_score_test("b+3", "B+4.0") | def test_players_score_agree_except_margin(tc): fx = Game_fixture(tc) fx.run_score_test("b+3", "B+4") tc.assertEqual(fx.game.result.sgf_result, "B+") tc.assertEqual(fx.game.result.detail, "unknown margin") tc.assertEqual(fx.game.result.winning_colour, 'b') |
unittest2.TestCase.__init__(self) | FrameworkTestCase.__init__(self) | def __init__(self, fn): unittest2.TestCase.__init__(self) self.fn = fn try: self.name = fn.__module__.split(".", 1)[-1] + "." + fn.__name__ except AttributeError: self.name = str(fn) |
"""Render tablular output. | """Render tabular output. | def render(self, s, width): if self.align == 'left': s = s.ljust(width) elif self.align == 'right': s = s.rjust(width) return s + " " * self.right_padding |
s = controller.safe_do_command(colour, 'gomill-cpu_time') | s = controller.safe_do_command('gomill-cpu_time') | def calculate_cpu_times(self): """Set CPU times in self.result. |
import logging LOG_FILENAME = '/tmp/openid.log' logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG) logging.debug("%s %s" % (identity_url, openid.openid)) | def openid_is_authorized(req, identity_url, trust_root): """ Check that they own the given identity URL, and that the trust_root is in their whitelist of trusted sites. """ if not req.user.is_authenticated(): return None openid = openid_get_identity(req, identity_url) if openid is None: return None import logging LOG... | |
url = '%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, path) | url = '%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, urlquote(path)) | def landing_page(request, orequest): """ The page shown when the user attempts to sign in somewhere using OpenID but is not authenticated with the site. For idproxy.net, a message telling them to log in manually is displayed. """ request.session['OPENID_REQUEST'] = orequest login_url = settings.LOGIN_URL path = request... |
from megrok.layout import Page | from megrok.layout.components import UtilityView | def nextURL(self): url = self.url(self.context) return url |
class Index(PageDisplayForm, Page, ContextualMenuEntry): | class Index(PageDisplayForm, ContextualMenuEntry): | def nextURL(self): url = self.url(self.context) return url |
class Edit(PageEditForm, grok.View): | class Edit(PageEditForm, ContextualMenuEntry): grok.implements(IDisplayView) | def nextURL(self): url = self.url(self.context) return url |
return item.geburtsdatum.strftime('%d.%m.%Y') | if item.geburtsdatum != None: return item.geburtsdatum.strftime('%d.%m.%Y') | def renderCell(self, item): return item.geburtsdatum.strftime('%d.%m.%Y') |
for base, dirs, files in os.walk(STARTDIR): | for base, dirs, files in os.walk(STARTDIR, topdown=True): | def findOn(self,path): |
skipDir = False | def findOn(self,path): | |
pprint(l) skipDir = True if skipDir: dirs.remove(dir_) | pprint(('DG',l)) culls.add(dir_) | def findOn(self,path): |
pprint(l) | pprint(('DO',l)) for cull in culls: dirs.remove(cull) | def findOn(self,path): |
pprint(l) | pprint(('FG', base, path, f, l)) | def findOn(self,path): |
class ReplicatedDiskException(Exception): pass | def commit(self): 'called when backup has acknowledged checkpoint reception' pass | |
class BufferedNICException(Exception): pass | _rth = None def getrth(): global _rth if not _rth: _rth = netlink.rtnl() return _rth class Netbuf(object): "Proxy for netdev with a queueing discipline" @staticmethod def devclass(): "returns the name of this device class" return 'unknown' @classmethod def available(cls): "returns True if this module can proxy the ... | def commit(self): msg = os.read(self.msgfd.fileno(), 4) if msg != 'done': print 'Unknown message: %s' % msg |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.