Exemplo n.º 1
0
 def test_raises_when_file_does_not_exist(self):
     # temp file is deleted when closed
     with tempfile.NamedTemporaryFile() as file:
         filepath = file.name
     with pytest.raises(ValueError) as exc_info:
         fileutil.read_issue_from_file(filepath)
     assert "is not a file" in str(exc_info.value)
Exemplo n.º 2
0
 def test_only_title(self):
     """Title should be as specified and body should be empty."""
     expected_title = "This is the title"
     with written_tmpfile(expected_title) as file:
         issue = fileutil.read_issue_from_file(file.name)
     assert issue.title == expected_title
     assert issue.body == ""
Exemplo n.º 3
0
 def test_empty_title_and_body_if_file_is_empty(self):
     """It's not an error to specify an empty file, should result in empty
     title and empty body.
     """
     with written_tmpfile("") as file:
         issue = fileutil.read_issue_from_file(file.name)
     assert issue.title == ""
     assert issue.body == ""
Exemplo n.º 4
0
    def test_title_and_body(self):
        """If there is a line separator in the file, there should be both title
        and body.
        """
        expected_title = "This is the title again"
        expected_body = "Body **with formatting** and\nmultiple\nlines"
        text = "\n".join([expected_title, expected_body])

        with written_tmpfile(text) as file:
            issue = fileutil.read_issue_from_file(file.name)

        assert issue.title == expected_title
        assert issue.body == expected_body
Exemplo n.º 5
0
def _parse_args(
        sys_args: Iterable[str],
        config: plug.Config) -> Tuple[argparse.Namespace, _ArgsProcessing]:
    """Parse the command line arguments with some light processing. Any
    processing that requires external resources (such as a network connection)
    must be performed by the :py:func:`_process_args` function.

    Args:
        sys_args: A list of command line arguments.
        config: RepoBee's configuration.
    Returns:
        A namespace of parsed arpuments and a boolean that specifies whether or
        not further processing is required.
    """
    parser = cli.mainparser.create_parser(config)
    argcomplete.autocomplete(parser)

    args = parser.parse_args(_handle_deprecation(sys_args))
    cli.preparser.clean_arguments(args)

    if "_extension_command" in args and not getattr(args._extension_command,
                                                    "_is_core_command", False):
        return args, _ArgsProcessing.EXT

    if "base_url" in args:
        _validate_tls_url(args.base_url)

    args_dict = vars(args)
    args_dict["students"] = _extract_groups(args)
    args_dict["issue"] = (fileutil.read_issue_from_file(args.issue)
                          if "issue" in args and args.issue else None)
    args_dict.setdefault("template_org_name", None)
    args_dict.setdefault("title_regex", None)
    args_dict.setdefault("state", None)
    args_dict.setdefault("show_body", None)
    args_dict.setdefault("author", None)
    args_dict.setdefault("num_reviews", None)
    args_dict.setdefault("user", None)
    args_dict["action"] = (args.action if isinstance(
        args.action, categorization.Action) else plug.cli.CoreCommand(
            args.category)[args.action])
    args_dict["category"] = (args.category if isinstance(
        args.category, categorization.Category) else plug.cli.CoreCommand(
            args.category))

    requires_processing = _resolve_requires_processing(args)
    return argparse.Namespace(**args_dict), requires_processing
Exemplo n.º 6
0
 def test_raises_when_path_points_to_dir(self):
     """Should raise if the path points to a directory."""
     with tempfile.TemporaryDirectory() as tmpdir:
         with pytest.raises(ValueError) as exc_info:
             fileutil.read_issue_from_file(tmpdir)
         assert "is not a file" in str(exc_info.value)