예제 #1
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_example():
    with patch_sys_argv_helper(["ti", "example", "minimal"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.name == "minimal"

    with patch_sys_argv_helper(["ti", "example", "minimal.py"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.name == "minimal"

    with patch_sys_argv_helper(["ti", "example", "-s",
                                "minimal.py"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.name == "minimal" and args.save == True

    with patch_sys_argv_helper(["ti", "example", "-p",
                                "minimal.py"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.name == "minimal" and args.print == True

    with patch_sys_argv_helper(["ti", "example", "-P",
                                "minimal.py"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.name == "minimal" and args.pretty_print == True
예제 #2
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_video_scale():
    with patch_sys_argv_helper(
        ["ti", "video_scale", "-i", "video.mp4", "-w", "1.2"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.input_file == "video.mp4"
        assert args.ratio_width == 1.2
        assert args.ratio_height == 1.2
        assert args.output_file == "video-scaled.mp4"

    with patch_sys_argv_helper([
            "ti", "video_scale", "-i", "video.mp4", "-w", "1.2",
            "--ratio-height", "1.5"
    ]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.input_file == "video.mp4"
        assert args.ratio_width == 1.2
        assert args.ratio_height == 1.5
        assert args.output_file == "video-scaled.mp4"

    with patch_sys_argv_helper([
            "ti", "video_scale", "-i", "video.mp3", "-w", "1.2",
            "--ratio-height", "1.5"
    ]) as custom_argv:
        with pytest.raises(SystemExit) as pytest_wrapped_err:
            cli = TaichiMain(test_mode=True)
            args = cli()
            assert pytest_wrapped_err.__context__.type == argparse.ArgumentTypeError
예제 #3
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_video_speed():
    with patch_sys_argv_helper(
        ["ti", "video_speed", "-i", "video.mp4", "-s", "2.0"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.input_file == "video.mp4"
        assert args.speed == 2.0
        assert args.output_file == "video-sped.mp4"

    with patch_sys_argv_helper(
        ["ti", "video_speed", "-i", "video.mp3", "-s", "2.0"]) as custom_argv:
        with pytest.raises(SystemExit) as pytest_wrapped_err:
            cli = TaichiMain(test_mode=True)
            args = cli()
            assert pytest_wrapped_err.__context__.type == argparse.ArgumentTypeError
예제 #4
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_gif():
    with patch_sys_argv_helper(["ti", "gif", "-i", "video.mp4", "-f",
                                "30"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.input_file == "video.mp4"
        assert args.framerate == 30
        assert args.output_file == "video.gif"

    with patch_sys_argv_helper(["ti", "gif", "-i", "video.mp3", "-f",
                                "30"]) as custom_argv:
        with pytest.raises(SystemExit) as pytest_wrapped_err:
            cli = TaichiMain(test_mode=True)
            args = cli()
            assert pytest_wrapped_err.__context__.type == argparse.ArgumentTypeError
예제 #5
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_regression():
    with patch_sys_argv_helper(["ti", "regression", "a.py", "b.py",
                                "-g"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.files == ["a.py", "b.py"]
        assert args.gui == True
예제 #6
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_can_dispatch_commands_to_methods_correctly():
    with patch_sys_argv_helper(
        ["ti", "example", "bogus_example_name_for_test"]):
        with patch.object(TaichiMain, 'example',
                          return_value=None) as mock_method:
            cli = TaichiMain(test_mode=False)
            cli()
            mock_method.assert_called_once_with(
                ["bogus_example_name_for_test"])
예제 #7
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_video():
    with patch_sys_argv_helper(
        ["ti", "video", "image.gif", "-o", "video.mp4", "-f",
         "30"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.inputs == ["image.gif"]
        assert args.framerate == 30
        assert isinstance(args.output_file, Path)
        assert args.output_file.name == "video.mp4"

    with patch_sys_argv_helper(["ti", "video", "-o", "video.mp4", "-f",
                                "30"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert isinstance(args.inputs, list)
        assert args.framerate == 30
        assert isinstance(args.output_file, Path)
        assert args.output_file.name == "video.mp4"
예제 #8
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_benchmark():
    with patch_sys_argv_helper(
        ["ti", "benchmark", "a.py", "b.py", "-T", "-v", "-r2",
         "-t4"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.files == ["a.py", "b.py"]
        assert args.tprt == True
        assert args.verbose == True
        assert args.rerun == "2"
        assert args.threads == "4"
예제 #9
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_video_crop():
    with patch_sys_argv_helper([
            "ti", "video_crop", "-i", "video.mp4", "--x1", "10.0", "--x2",
            "20.0", "--y1", "10.0", "--y2", "20.0"
    ]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.input_file == "video.mp4"
        assert args.x_begin == 10.0
        assert args.x_end == 20.0
        assert args.y_begin == 10.0
        assert args.y_end == 20.0
        assert args.output_file == "video-cropped.mp4"

    with patch_sys_argv_helper([
            "ti", "video_crop", "-i", "video.mp3", "--x1", "10.0", "--x2",
            "20.0", "--y1", "10.0", "--y2", "20.0"
    ]) as custom_argv:
        with pytest.raises(SystemExit) as pytest_wrapped_err:
            cli = TaichiMain(test_mode=True)
            args = cli()
            assert pytest_wrapped_err.__context__.type == argparse.ArgumentTypeError
예제 #10
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_exit_one_with_bogus_command_provided():
    with patch_sys_argv_helper(["ti", "bogus-command-not-registered-yet"]):
        cli = TaichiMain(test_mode=True)
        assert cli() == 1
예제 #11
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_exit_one_with_no_command_provided():
    with patch_sys_argv_helper(["ti"]):
        cli = TaichiMain(test_mode=True)
        assert cli() == 1
예제 #12
0
파일: test_cli.py 프로젝트: varinic/taichi
def test_cli_run():
    with patch_sys_argv_helper(["ti", "run", "a.py"]) as custom_argv:
        cli = TaichiMain(test_mode=True)
        args = cli()
        assert args.filename == "a.py"