def add_handler_with_description_test(): runner = glint.Runner() runner['test'] = (default_handler, 'testing') assert_equal(2, len(runner._commands)) assert_equal(default_handler, runner._commands['test']._method) assert_equal('testing', runner._commands['test'].description)
def create_with_parameters_test(): runner = glint.Runner(description='test', show_usage=False, prefix='+') assert_equal('test', runner._description) assert_equal('+', runner._prefix) assert_false(runner._show_usage) assert_equal(0, len(runner))
def create_with_defaults_test(): runner = glint.Runner() assert_equal(None, runner._description) assert_equal('--', runner._prefix) assert_true(runner._show_usage) assert_equal(1, len(runner._commands)) assert_true('help' in runner._commands)
def length_test(): runner = glint.Runner() assert_equal(1, len(runner)) runner[None] = default_handler assert_equal(2, len(runner)) runner['test'] = test_handler assert_equal(3, len(runner))
def contains_test(): runner = glint.Runner() runner[None] = default_handler runner['test'] = test_handler assert_true('help' in runner) assert_true(None in runner) assert_true('test' in runner)
def run_correct_handler_test(): handler_run = None runner = glint.Runner() runner[None] = default_handler runner['test'] = test_handler runner.run(['test']) assert_true('test', handler_run)
def add_multiple_handlers_test(): runner = glint.Runner() runner[None] = default_handler runner['test'] = test_handler assert_equal(3, len(runner._commands)) assert_true(None in runner._commands) assert_equal(default_handler, runner._commands[None]._method) assert_true('test' in runner._commands) assert_equal(test_handler, runner._commands['test']._method)
def empty_project(name): projects = read_timings() if name in projects: projects[name].clear() write_timings(projects) else: print(f"{name} {sty.fg.red}not in timings DB: no change.{sty.fg.rs}") def default(): print(sty.fg.red, f"something in RED") # save_current_timings_file() pass if __name__ == '__main__': runner = glint.Runner() runner["add"] = (add_project, "add project 'name'") runner["del"] = (del_project, "delete project 'name'") runner["projects"] = (show_projects, "show projects") runner["continue"] = (continue_project, "start/continue working on project 'name'") runner["start"] = (continue_project, "start/continue working on project 'name'") runner["done"] = (stop, "stop working on project 'name'") runner["stop"] = (stop, "stop working on project 'name'") runner["empty"] = (empty_project, "remove all entries from project 'name'") runner[None] = default runner.run()
def add_multiple_handlers_with_same_name_test(): runner = glint.Runner() runner['test'] = default_handler runner['test'] = test_handler
def add_handler_with_different_prefix_test(): runner = glint.Runner(prefix='+') runner[None] = default_handler for c in runner._commands: assert_equal('+', runner._commands[c]._prefix)
def add_handler_with_description_that_is_not_a_method_test(): runner = glint.Runner() runner['test'] = ('foo', 'bar')
def add_handler_that_is_not_a_method_test(): runner = glint.Runner() runner['test'] = 'foo'
def add_handler_test(): runner = glint.Runner() runner['test'] = default_handler assert_equal(2, len(runner._commands)) assert_equal(default_handler, runner._commands['test']._method)
def return_none_when_show_usage_true_test(): runner = glint.Runner() assert_is_none(runner.help())
def exception_when_not_enough_parameters_passed_to_command_test(): runner = glint.Runner(show_usage=False) runner['test'] = argument_handler runner.run(['test'])
def exception_when_no_command_specified_and_no_default_handler_test(): runner = glint.Runner(show_usage=False) runner.run([])
def exception_when_unable_to_find_handler_and_show_usage_is_false_test(): runner = glint.Runner(show_usage=False) runner.run(['test'])
def return_usage_when_show_usage_is_false_test(): runner = glint.Runner(show_usage=False) help = runner.help() assert_is_not_none(help)