Esempio n. 1
0
def test_info__using_pkg_info(reset_sys_argv, capfd):
    """Verify the metadata when using older-style lookups."""

    def metadata_generator():
        """Mock metadata generator."""
        for line in [
            "Metadata-Version: 1.0",
            "Version: 1.0.0",
            "Source-label: somewords",
            "Source-url: http://yourcompany.com",
        ]:
            yield line
        raise StopIteration

    mock_pkg = mock.Mock()
    mock_pkg.PKG_INFO = "PKG-INFO"
    mock_pkg._get_metadata = mock.Mock(return_value=metadata_generator())

    mockenv = mock.Mock()
    mockenv.__getitem__ = mock.Mock(return_value=[mock_pkg])

    environment_patch = mock.patch.object(
        commands.pkg_resources,
        "Environment",
        return_value=mockenv,
    )

    sys.argv = ["py-info", "foo-bar"]
    with environment_patch:
        commands.info()

    out, err = capfd.readouterr()
    assert not err
    for line in metadata_generator():
        assert line in out
Esempio n. 2
0
def test_info__using_pkg_info(reset_sys_argv, capfd):
    """Verify the metadata when using older-style lookups."""
    def metadata_generator():
        """Mock metadata generator."""
        for line in [
                "Metadata-Version: 1.0",
                "Version: 1.0.0",
                "Source-label: somewords",
                "Source-url: http://yourcompany.com",
        ]:
            yield line
        raise StopIteration

    mock_pkg = mock.Mock()
    mock_pkg.PKG_INFO = "PKG-INFO"
    mock_pkg._get_metadata = mock.Mock(return_value=metadata_generator())

    mockenv = mock.Mock()
    mockenv.__getitem__ = mock.Mock(return_value=[mock_pkg])

    environment_patch = mock.patch.object(
        commands.pkg_resources,
        "Environment",
        return_value=mockenv,
    )

    sys.argv = ["py-info", "foo-bar"]
    with environment_patch:
        commands.info()

    out, err = capfd.readouterr()
    assert not err
    for line in metadata_generator():
        assert line in out
Esempio n. 3
0
def test_info__pkg_not_found(reset_sys_argv, capfd):
    """Ensure the error message when a package is not found."""

    sys.argv = ["py-info", "some-random-non-existant-package"]
    commands.info()
    out, err = capfd.readouterr()

    assert not out
    assert "The package some-random-non-existant-package was not found." in err
Esempio n. 4
0
def test_info__pkg_not_found(reset_sys_argv, capfd):
    """Ensure the error message when a package is not found."""

    sys.argv = ["py-info", "some-random-non-existant-package"]
    commands.info()
    out, err = capfd.readouterr()

    assert not out
    assert "The package some-random-non-existant-package was not found." in err
Esempio n. 5
0
def test_info(reset_sys_argv, capfd):
    """Ensure we're looking up and dumping package metadata to stdout."""

    sys.argv = ["py-info", "pytest"]
    commands.info()
    stdout, stderr = capfd.readouterr()

    assert not stderr
    assert "Name: pytest" in stdout
    assert "License: MIT license" in stdout
Esempio n. 6
0
def test_info(reset_sys_argv, capfd):
    """Ensure we're looking up and dumping package metadata to stdout."""

    sys.argv = ["py-info", "pytest"]
    commands.info()
    stdout, stderr = capfd.readouterr()

    assert not stderr
    assert "Name: pytest" in stdout
    assert "License: MIT license" in stdout