Пример #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:
         util.read_issue(filepath)
     assert "is not a file" in str(exc_info.value)
Пример #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 = util.read_issue(file.name)
     assert issue.title == expected_title
     assert issue.body == ""
Пример #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 = util.read_issue(file.name)
     assert issue.title == ""
     assert issue.body == ""
Пример #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{}multiple{}lines".format(
            os.linesep, os.linesep
        )
        text = os.linesep.join([expected_title, expected_body])

        with written_tmpfile(text) as file:
            issue = util.read_issue(file.name)

        assert issue.title == expected_title
        assert issue.body == expected_body
Пример #5
0
def _parse_args(
        sys_args: Iterable[str], config_file: pathlib.Path
) -> 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_file: Path to the config file.
    Returns:
        A namespace of parsed arpuments and a boolean that specifies whether or
        not further processing is required.
    """
    parser = cli.mainparser.create_parser(config_file)
    argcomplete.autocomplete(parser)

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

    if "_extension_command" in args:
        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"] = (util.read_issue(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
Пример #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:
             util.read_issue(tmpdir)
         assert "is not a file" in str(exc_info.value)