Exemplo n.º 1
0
def _dispatch_issues_command(
    args: argparse.Namespace, config: plug.Config, api: plug.PlatformAPI
) -> Optional[Mapping[str, List[plug.Result]]]:
    issues = plug.cli.CoreCommand.issues
    action = args.action
    if action == issues.open:
        if args.issue:
            command.open_issue(
                args.issue, args.assignments, args.students, api
            )
        else:
            command.open_issues_from_hook_results(
                plug.json_to_result_mapping(
                    args.hook_results_file.read_text(
                        encoding=sys.getdefaultencoding()
                    )
                ),
                args.repos,
                api,
            )
        return None
    elif action == issues.close:
        command.close_issue(args.title_regex, args.repos, api)
        return None
    elif action == issues.list:
        return command.list_issues(
            args.repos,
            api,
            state=args.state,
            title_regex=args.title_regex or "",
            show_body=args.show_body,
            author=args.author,
            double_blind_key=args.double_blind_key,
        )
    _raise_illegal_action_error(args)
Exemplo n.º 2
0
    def command(self) -> None:
        hook_results_file = pathlib.Path(self.hook_results_file).resolve()
        if not hook_results_file.exists():
            raise plug.PlugError(f"no such file: {str(hook_results_file)}")

        contents = hook_results_file.read_text(
            encoding=sys.getdefaultencoding())
        hook_results_mapping = plug.json_to_result_mapping(contents)
        selected_hook_results = _filter_hook_results(hook_results_mapping,
                                                     self.args.students,
                                                     self.args.assignments)
        plug.echo(formatters.format_hook_results_output(selected_hook_results))
Exemplo n.º 3
0
def test_lossless_serialization(hook_result_mapping):
    """Test that serializing and then deserializing results in all data being
    recovered.
    """
    expected = dict(hook_result_mapping)

    serialized = plug.result_mapping_to_json(hook_result_mapping)
    deserialized = plug.json_to_result_mapping(serialized)
    actual = {
        repo_name: sorted(results)
        for repo_name, results in deserialized.items()
    }

    assert actual == expected
Exemplo n.º 4
0
def read_results_file(results_file):
    if not results_file.is_file():
        raise plug.PlugError(f"no such file: {str(results_file)}")
    return plug.json_to_result_mapping(
        results_file.read_text(encoding=sys.getdefaultencoding())
    )
Exemplo n.º 5
0
def test_desezialize_empty_json():
    assert plug.json_to_result_mapping("{}") == {}