Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
def test_standard_attributes__re_classify(reset_sys_argv):
    """If reclassify is set, classifiers should be in the unconfigured set."""

    conf = Config()
    conf.classifiers = ["fake things"]
    sys.argv = ["py-build", "-R"]
    attrs = configure.standard_attributes(conf, get_options())
    assert "classifiers" in attrs
Example #6
0
def test_standard_attributes__re_classify(reset_sys_argv):
    """If reclassify is set, classifiers should be in the unconfigured set."""

    conf = Config()
    conf.classifiers = ["fake things"]
    sys.argv = ["py-build", "-R"]
    attrs = configure.standard_attributes(conf, get_options())
    assert "classifiers" in attrs
Example #7
0
def test_feature_attributes__re_config(reset_sys_argv):
    """When --rebuild is used, all features should appear unconfigured."""

    conf = Config()
    conf.test_runner = "pytest"
    sys.argv = ["py-build", "--rebuild"]
    attrs = configure.feature_attributes(conf, get_options())
    expected = list(conf._PYPACKAGE_KEYS.keys())
    assert attrs == expected
Example #8
0
def test_feature_attributes(reset_sys_argv, move_home_pypackage):
    """If we have default runner args they should appear unconfigured."""

    conf = Config()
    conf.runner_args = ["fake", "args"]
    conf._configured_runner_args = False
    attrs = configure.feature_attributes(conf, get_options())
    expected = list(conf._PYPACKAGE_KEYS.keys())
    assert attrs == expected
Example #9
0
def test_standard_attributes__re_config(reset_sys_argv):
    """If reconfig is set, all standard attributes should be unconfigured."""

    conf = Config()
    conf.name = "something"
    sys.argv = ["py-build", "-r"]
    attrs = configure.standard_attributes(conf, get_options())
    expected = list(conf._KEYS.keys())[:17]
    assert attrs == expected
Example #10
0
def test_standard_attributes__re_config(reset_sys_argv):
    """If reconfig is set, all standard attributes should be unconfigured."""

    conf = Config()
    conf.name = "something"
    sys.argv = ["py-build", "-r"]
    attrs = configure.standard_attributes(conf, get_options())
    expected = list(conf._KEYS.keys())[:conf._STD_TO_EXTD_INDEX]
    assert attrs == expected
Example #11
0
def test_feature_attributes(reset_sys_argv, move_home_pypackage):
    """If we have default runner args they should appear unconfigured."""

    conf = Config()
    conf.runner_args = ["fake", "args"]
    conf._configured_runner_args = False
    attrs = configure.feature_attributes(conf, get_options())
    expected = list(conf._PYPACKAGE_KEYS.keys())
    assert attrs == expected
Example #12
0
def test_extended_attributes__re_config(reset_sys_argv):
    """If --rebuild is used, all extended attributes should be unconfigured."""

    conf = Config()
    conf.use_2to3 = True
    sys.argv = ["py-build", "-r"]
    attrs = configure.extended_attributes(conf, get_options())
    expected = list(conf._KEYS.keys())[conf._STD_TO_EXTD_INDEX:]
    assert attrs == expected
Example #13
0
def test_extended_attributes(reset_sys_argv, move_home_pypackage):
    """Extended attributes should return unset keys past _STD_TO_EXTD_INDEX."""

    conf = Config()
    expected = list(conf._KEYS.keys())[conf._STD_TO_EXTD_INDEX:]
    conf.use_2to3 = True
    expected.remove("use_2to3")
    attrs = configure.extended_attributes(conf, get_options())
    assert attrs == expected
Example #14
0
def test_feature_attributes__re_config(reset_sys_argv):
    """When --rebuild is used, all features should appear unconfigured."""

    conf = Config()
    conf.test_runner = "pytest"
    sys.argv = ["py-build", "--rebuild"]
    attrs = configure.feature_attributes(conf, get_options())
    expected = list(conf._PYPACKAGE_KEYS.keys())
    assert attrs == expected
Example #15
0
def test_extended_attributes__re_config(reset_sys_argv):
    """If --rebuild is used, all extended attributes should be unconfigured."""

    conf = Config()
    conf.use_2to3 = True
    sys.argv = ["py-build", "-r"]
    attrs = configure.extended_attributes(conf, get_options())
    expected = list(conf._KEYS.keys())[17:]
    assert attrs == expected
Example #16
0
def test_extended_attributes(reset_sys_argv, move_home_pypackage):
    """Extended attributes should return any unset keys past 17."""

    conf = Config()
    expected = list(conf._KEYS.keys())[17:]
    conf.use_2to3 = True
    expected.remove("use_2to3")
    attrs = configure.extended_attributes(conf, get_options())
    assert attrs == expected
Example #17
0
def test_standard_attributes(reset_sys_argv, move_home_pypackage):
    """Ensure the standard attribute set."""

    conf = Config()
    expected_attrs = list(conf._KEYS.keys())[:conf._STD_TO_EXTD_INDEX]
    conf.name = "foobar"
    conf.classifiers = ["fake classifier"]
    expected_attrs.remove("name")
    expected_attrs.remove("classifiers")
    attrs = configure.standard_attributes(conf, get_options())
    assert attrs == expected_attrs
Example #18
0
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"
Example #19
0
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"
Example #20
0
def test_standard_attributes(reset_sys_argv, move_home_pypackage):
    """Ensure the standard attribute set."""

    conf = Config()
    expected_attrs = list(conf._KEYS.keys())[:17]
    conf.name = "foobar"
    conf.classifiers = ["fake classifier"]
    expected_attrs.remove("name")
    expected_attrs.remove("classifiers")
    attrs = configure.standard_attributes(conf, get_options())
    assert attrs == expected_attrs
Example #21
0
def test_interactive_setup(capfd, reset_sys_argv, move_home_pypackage,
                           flags, banner):
    """Ensure the calls made and feedback during the interactive setup."""

    conf = Config()
    sys.argv = ["py-build", flags]
    opts = get_options()

    standard_patch = mock.patch.object(
        configure,
        "standard_attributes",
        return_value=["standard"],
    )
    feature_patch = mock.patch.object(
        configure,
        "feature_attributes",
        return_value=["feature"],
    )
    extended_patch = mock.patch.object(
        configure,
        "extended_attributes",
        return_value=["extended"],
    )
    set_value_patch = mock.patch.object(configure, "set_value_in_config")

    with standard_patch:
        with feature_patch:
            with extended_patch:
                with set_value_patch as patched_set_value:
                    assert configure.run_interactive_setup(conf, opts) == conf

    expected_calls = [
        mock.call.Call("standard", conf, conf._KEYS),
        mock.call.Call("feature", conf, conf._PYPACKAGE_KEYS),
        mock.call.Call("extended", conf, conf._KEYS),
    ]
    assert patched_set_value.mock_calls == expected_calls

    out, err = capfd.readouterr()
    assert banner in out
    assert "~ Standard Attributes ~" in out
    assert "~ Pypackage Features ~" in out
    assert "~ Extended Attributes ~" in out
    assert not err
Example #22
0
def test_interactive_setup(capfd, reset_sys_argv, move_home_pypackage, flags,
                           banner):
    """Ensure the calls made and feedback during the interactive setup."""

    conf = Config()
    sys.argv = ["py-build", flags]
    opts = get_options()

    standard_patch = mock.patch.object(
        configure,
        "standard_attributes",
        return_value=["standard"],
    )
    feature_patch = mock.patch.object(
        configure,
        "feature_attributes",
        return_value=["feature"],
    )
    extended_patch = mock.patch.object(
        configure,
        "extended_attributes",
        return_value=["extended"],
    )
    set_value_patch = mock.patch.object(configure, "set_value_in_config")

    with standard_patch:
        with feature_patch:
            with extended_patch:
                with set_value_patch as patched_set_value:
                    assert configure.run_interactive_setup(conf, opts) == conf

    expected_calls = [
        mock.call.Call("standard", conf, conf._KEYS),
        mock.call.Call("feature", conf, conf._PYPACKAGE_KEYS),
        mock.call.Call("extended", conf, conf._KEYS),
    ]
    assert patched_set_value.mock_calls == expected_calls

    out, err = capfd.readouterr()
    assert banner in out
    assert "~ Standard Attributes ~" in out
    assert "~ Pypackage Features ~" in out
    assert "~ Extended Attributes ~" in out
    assert not err
Example #23
0
def test_get_options(reset_sys_argv):
    sys.argv = ["py-build", "-isR", "--extended"]
    options = get_options()
    for opt in ("interactive", "setup", "re_classify", "extended"):
        assert getattr(options, opt)
Example #24
0
def test_get_options(reset_sys_argv):
    sys.argv = ["py-build", "-isR", "--extended"]
    options = get_options()
    for opt in ("interactive", "setup", "re_classify", "extended"):
        assert getattr(options, opt)