def test_version(mocked_exit): mocked_stdout = io.StringIO() with mock.patch.object(sys, "stdout", new=mocked_stdout): cli.parse_args(["-v"]) assert mocked_stdout.getvalue().strip() == f"m2cgen {__version__}"
def test_language_is_required(mocked_exit): mocked_stderr = io.StringIO() with mock.patch.object(sys, "stderr", new=mocked_stderr): cli.parse_args([]) assert ("the following arguments are required: --language" in mocked_stderr.getvalue()) mocked_exit.assert_called_with(2)
def test_file_as_input(tmp_path): f = tmp_path / "hello.txt" f.write_text("123") input_args = ["-l", "python", str(f)] args = cli.parse_args(input_args) assert args.language == "python" assert isinstance(args.infile, io.BufferedReader) assert args.infile.name == str(f)
def test_stdin_as_input(request): input_args = ["--language", "python"] args = cli.parse_args(input_args) assert args.language == "python" # Since pytest by default captures stdin, but sometimes we need to disable # it (primarily for using (i)pdb), we have 2 different strategies to verify # that stdin was returned as infile. capturemanager = request.config.pluginmanager.getplugin("capturemanager") if capturemanager.is_globally_capturing(): assert isinstance(args.infile, capture.DontReadFromInput) else: assert args.infile.name == "<stdin>"