def test_perform_guesswork__ignore(capfd, reset_sys_argv, move_home_pypackage): """If the user responds with 'all', ignore all guesses.""" conf = Config() conf.name = "previously existing" sys.argv = ["py-build", "-i"] guesses = OrderedDict([ ("name", "some name"), ("py_modules", "some_thing"), ("scripts", ["bin/something"]), ("package_data", {"some name": ["thing/data/file_1"]}), ]) with mock.patch.object(guessing, "_guess_at_things", return_value=guesses): with mock.patch.object(guessing, "INPUT", return_value="all"): guessing.perform_guesswork(conf, get_options()) assert conf.name == "previously existing" assert not hasattr(conf, "py_modules") assert not hasattr(conf, "package_data") assert not hasattr(conf, "scripts") out, err = capfd.readouterr() assert "ignoring all guesses" in out assert not err
def test_perform_guesswork(capfd, reset_sys_argv, move_home_pypackage): """Ensure the user can deselect guesses when using interactive.""" conf = Config() conf.name = "previously existing" sys.argv = ["py-build", "-i"] guesses = OrderedDict([ ("name", "some name"), ("py_modules", "some_thing"), ("scripts", ["bin/something"]), ("package_data", ["thing/data/file_1"]), ]) with mock.patch.object(guessing, "_guess_at_things", return_value=guesses): with mock.patch.object(guessing, "INPUT", side_effect=iter(["1", "-3", "2", ""])): guessing.perform_guesswork(conf, get_options()) assert conf.name == "previously existing" assert not hasattr(conf, "py_modules") assert conf.package_data == {"previously existing": ["thing/data/file_1"]} assert conf.scripts == ["bin/something"] out, err = capfd.readouterr() assert "name will not be guessed" in out assert "py_modules will not be guessed" in out assert not err
def test_perform_guesswork__ignore(capfd, reset_sys_argv, move_home_pypackage): """If the user responds with 'all', ignore all guesses.""" conf = Config() conf.name = "previously existing" sys.argv = ["py-build", "-i"] guesses = OrderedDict([ ("name", "some name"), ("py_modules", "some_thing"), ("scripts", ["bin/something"]), ("package_data", { "some name": ["thing/data/file_1"] }), ]) with mock.patch.object(guessing, "_guess_at_things", return_value=guesses): with mock.patch.object(guessing, "INPUT", return_value="all"): guessing.perform_guesswork(conf, get_options()) assert conf.name == "previously existing" assert not hasattr(conf, "py_modules") assert not hasattr(conf, "package_data") assert not hasattr(conf, "scripts") out, err = capfd.readouterr() assert "ignoring all guesses" in out assert not err
def test_perform_guesswork__interrupts(reset_sys_argv, side_effect): """Ensure the user can cleanly exit the interactive session.""" sys.argv = ["py-build", "-siR"] guesses = {"fake": True} with mock.patch.object(guessing, "_guess_at_things", return_value=guesses): with mock.patch.object(guessing, "INPUT", side_effect=side_effect): with pytest.raises(SystemExit) as error: guessing.perform_guesswork(Config(), get_options()) assert error.value.args[0] == "\nInterrupted"