Esempio n. 1
0
def run_main(subcommand,
             lines,
             main_args=None,
             subcommand_args=None,
             to_stdout=False):
    in_fh, in_fn = tmp_file(lines=lines)
    in_fh.close()

    out_fh, out_fn = tempfile.mkstemp()

    if not main_args:
        main_args = []
    main_args.extend([subcommand, "--input", str(in_fn)])
    if not to_stdout:
        main_args.extend(["--output", str(out_fn)])
    if subcommand_args:
        main_args.extend(subcommand_args)

    with captured_output() as (stdout, stderr):
        main(args=main_args)

    fh = open(out_fn, "r")
    out_lines = [line.rstrip("\r\n") for line in fh]
    fh.close()

    stdout = stdout.getvalue().rstrip('\r\n').split("\n")
    stderr = stderr.getvalue().rstrip('\r\n').split("\n")

    os.remove(in_fn)
    os.remove(out_fn)

    return (out_lines, stdout, stderr)
Esempio n. 2
0
    def __sort(self, lines, extra_args, test_func, to_stdout=False):
        in_fh, in_fn = tmp_file(lines=lines)
        in_fh.close()

        out_fh, out_fn = tempfile.mkstemp()

        main_args = ["validate", "--input", str(in_fn)]
        if not to_stdout:
            main_args.extend(["--output", str(out_fn)])
        main_args.extend(extra_args)

        with captured_output() as (stdout, stderr):
            main(args=main_args)

        fh = open(out_fn, "r")
        out_lines = [line.rstrip("\r\n") for line in fh]
        fh.close()

        stdout = stdout.getvalue().rstrip('\r\n').split("\n")
        stderr = stderr.getvalue().rstrip('\r\n').split("\n")

        test_func(out_lines=out_lines, stdout=stdout, stderr=stderr)

        os.remove(in_fn)
        os.remove(out_fn)
Esempio n. 3
0
 def test_no_inputs(self):
     with captured_output() as (_, stderr):
         with self.assertRaises(SystemExit) as context:
             main(args=['sort'])