Exemple #1
0
def test_get_egg_cache_paths():
    with patch('pkglib.egg_cache.CONFIG',
               org.OrganisationConfig(installer_search_path=['/usr'])):
        assert get_egg_cache_paths() == ['/usr']

    with patch('pkglib.egg_cache.CONFIG',
               org.OrganisationConfig(installer_search_path=['/usr', '/bin'])):
        assert get_egg_cache_paths() == ['/usr', '/bin']
Exemple #2
0
def test__submits_matrix_job():
    project_name = "acme.foo.bar"
    url = "http://some_fancytest_url/" + project_name
    env_python_versions = '2.6.2 5.4.3 9.4.5.5'
    expected_python_versions = ['2.6.2', '5.4.3', '9.4.5.5']
    expected_build_cmd = COMMAND_TEMPLATE % {
        'project_name': project_name,
        'egg_name': project_name
    }
    TEST_CONFIG = org.OrganisationConfig(
        jenkins_matrix_job_pyversions=env_python_versions.split(),
        jenkins_url='http://acmejenkins.example.com',
        jenkins_matrix_job_xml=None,
        jenkins_job_xml=None,
        virtualenv_executable='virtualenv')

    jenkins_mock = Mock(side_effect=lambda *_args, **_kwargs: jenkins_mock)
    jenkins_mock.job_exists = Mock(return_value=False)

    with ExitStack() as stack:
        stack.enter_context(patch.object(jenkins_, 'CONFIG', TEST_CONFIG))
        stack.enter_context(
            patch('pkglib.setuptools.command.base.fetch_build_eggs'))
        stack.enter_context(patch_oss_jenkins(Jenkins=jenkins_mock))
        cmd = get_cmd(name=project_name, url=url, description='')
        cmd.matrix = True
        cmd.run()

    job_xml = xml_to_tree(jenkins_mock.create_job.call_args[0][1])

    jenkins_mock.create_job.assert_called_once_with(project_name, ANY)
    assert job_scm_location_remote(job_xml) == "%s/trunk" % url
    assert job_scm_location_local(job_xml) == project_name
    assert job_python_versions(job_xml) == expected_python_versions
    assert job_build_steps(job_xml)[2] == expected_build_cmd
Exemple #3
0
def test_get_active_python_versions__returns_system_python_by_default():
    cmd = get_cmd()
    with patch('pkglib.setuptools.command.jenkins_.CONFIG',
               org.OrganisationConfig(jenkins_matrix_job_pyversions=None)):
        actual = cmd._get_active_python_versions()
    expected = (".".join(str(s) for s in sys.version_info[0:3]), )
    assert list(actual) == list(expected)
Exemple #4
0
def test_get_active_python_versions__with_config():
    cmd = get_cmd()
    with patch(
            'pkglib.setuptools.command.jenkins_.CONFIG',
            org.OrganisationConfig(
                jenkins_matrix_job_pyversions=['1.2', '2.3'])):
        actual = cmd._get_active_python_versions()
    expected = ("1.2", "2.3")
    assert list(actual) == list(expected)
Exemple #5
0
def _prepare_test_cmd_mocks(
        cwd=_make_root_dir_from("<test_pylint_cwd>"), pylint_output="",
        mocks=None):
    if mocks is None:
        mocks = {}

    mocks['pkglib.setuptools.command.test.CONFIG'] = org.OrganisationConfig(
        test_linter=sentinel.linter,
        test_linter_package=sentinel.linter_pkg,
    )

    mocks["os.getcwd"] = Mock(return_value=cwd)
    mocks["os.path.isdir"] = Mock(return_value=True)
    mocks["pkglib.setuptools.command.test.test.get_test_roots"] = Mock(
        return_value=['tests'])

    # Mock output from checkstyle
    communicate_mock = Mock(return_value=(pylint_output, ""))
    mock_subprocess = Mock(
        return_value=Mock(returncode=0, communicate=communicate_mock))
    mocks["subprocess.Popen"] = mock_subprocess

    # Mock os.open() so that PyLint produce by test command is captured and
    # can be examined
    _unpatched_open = open
    output_files = defaultdict(SavedBytesIO)

    mock_open = Mock()
    mock_open.__output_files = output_files

    def pylint_open_mock_func(*a, **kw):
        return (output_files[a[0]] if a[0].endswith(test.HUDSON_XML_PYLINT)
                else _unpatched_open(*a, **kw))

    mock_open.side_effect = pylint_open_mock_func
    mocks[_open_func_path] = mock_open

    # Mock remaining supporting infrastructure
    _add_mock(mocks, "pytest.main", lambda: Mock(return_value=0))
    _add_mock(mocks, "pkglib.setuptools.buildout.install")

    return mocks
Exemple #6
0
def test_run__submits_matrix_job_with_correct_xml():
    project_name = "acme.foo"
    url = "http://some_fancytest_url"
    description = "This description is not very helpful\nBut OK for testing"
    username = "******"
    env_python_versions = '2.6.2 1.2.3 1.9.8.4'
    TEST_CONFIG = org.OrganisationConfig(
        jenkins_matrix_job_pyversions=env_python_versions.split(),
        jenkins_url='http://acmejenkins.example.com',
        jenkins_matrix_job_xml=None,
        virtualenv_executable='virtualenv')

    expected_python_versions = ['2.6.2', '1.2.3', '1.9.8.4']
    expected_build_cmd = COMMAND_TEMPLATE % {
        'project_name': project_name,
        'egg_name': project_name
    }

    jenkins_mock = Mock(side_effect=lambda *_args, **_kwargs: jenkins_mock)
    jenkins_mock.job_exists = Mock(return_value=False)

    with ExitStack() as stack:
        stack.enter_context(patch.object(jenkins_, 'CONFIG', TEST_CONFIG))
        stack.enter_context(patch('getpass.getuser', return_value=username))
        stack.enter_context(
            patch('pkglib.setuptools.command.base.fetch_build_eggs'))
        stack.enter_context(patch_oss_jenkins(Jenkins=jenkins_mock))
        cmd = get_cmd(name=project_name, url=url, description=description)
        cmd.matrix = True
        cmd.run()

    job_xml = xml_to_tree(jenkins_mock.create_job.call_args[0][1])

    jenkins_mock.create_job.assert_called_once_with(project_name, ANY)
    assert job_description(job_xml) == description
    assert job_display_name(job_xml) == "%s (%s)" % (project_name, username)
    assert job_scm_location_remote(job_xml) == "%s/trunk" % url
    assert job_scm_location_local(job_xml) == project_name
    assert job_python_versions(job_xml) == expected_python_versions
    assert job_build_steps(job_xml)[2] == expected_build_cmd
Exemple #7
0
def test__submits_core_job_hyphened_or_underscored_name(project_name):
    egg_name = project_name.replace('_', '?').replace('-', '?')
    url = "http://some_fancytest_url/" + project_name
    description = "This description is not very helpful\nFine for testing"
    username = "******"
    expected_build_cmd = COMMAND_TEMPLATE % {
        'project_name': project_name,
        'egg_name': egg_name
    }

    jenkins_mock = Mock(side_effect=lambda *_args, **_kwargs: jenkins_mock)
    jenkins_mock.job_exists = Mock(return_value=False)

    TEST_CONFIG = org.OrganisationConfig(
        jenkins_url='http://acmejenkins.example.com',
        jenkins_matrix_job_xml=None,
        jenkins_matrix_job_pyversions=None,
        jenkins_job_xml=None,
        virtualenv_executable='virtualenv')

    with ExitStack() as stack:
        stack.enter_context(patch.object(jenkins_, 'CONFIG', TEST_CONFIG))
        stack.enter_context(patch('getpass.getuser', return_value=username))
        stack.enter_context(
            patch('pkglib.setuptools.command.base.fetch_build_eggs'))
        stack.enter_context(patch_oss_jenkins(Jenkins=jenkins_mock))
        cmd = get_cmd(name=project_name, url=url, description=description)
        cmd.run()

    job_xml = xml_to_tree(jenkins_mock.create_job.call_args[0][1])

    jenkins_mock.create_job.assert_called_once_with(project_name, ANY)
    assert job_description(job_xml) == description
    assert job_display_name(job_xml) == "%s (%s)" % (project_name, username)
    assert job_scm_location_remote(job_xml) == "%s/trunk" % url
    assert job_scm_location_local(job_xml) == project_name
    assert job_build_steps(job_xml)[2] == expected_build_cmd
Exemple #8
0
import pkglib.setuptools  # monkeypatch; @UnusedImport # NOQA

from pkg_resources import parse_version
from zc.buildout import easy_install
from mock import patch

from pkglib.config import org

TEST_CONFIG = org.OrganisationConfig(third_party_build_prefix='acme')


def test_inhouse_version_is_between_upstream_versions():
    with patch('pkglib.setuptools.patches.inhouse_build_version.CONFIG',
               TEST_CONFIG):
        assert parse_version('1.0') < parse_version(
            '1.0-acme1') < parse_version('1.0-final1')


def test_inhouse_version_is_final():
    with patch('pkglib.setuptools.patches.inhouse_build_version.CONFIG',
               TEST_CONFIG):
        assert easy_install._final_version(parse_version('1.0-acme1'))
""" Unit tests for pkglib.manage
"""
import os

import mock

from pkglib import manage
from pkglib.config import org

pytest_plugins = ['pkglib_testing.fixtures.workspace']

TEST_CONFIG = org.OrganisationConfig(namespaces=['acme'],
                                     namespace_separator='.')


def test_get_inhouse_dependencies(workspace):
    with mock.patch.object(manage, 'CONFIG', TEST_CONFIG):
        with open(os.path.join(workspace.workspace, 'setup.cfg'), 'wb') as fp:
            fp.write("""[metadata]
name = acme.foo
version = 2.3.5
install_requires =
    scipy
    numpy
    acme.a
    acme.b>=1.0.0
    acme.c<3.0
""")
        result = [
            i for i in manage.get_inhouse_dependencies(workspace.workspace)
        ]
Exemple #10
0
pkglib.CONFIG = org.OrganisationConfig(
    pypi_url='http://acmepypi.example.com',
    pypi_variant=None,
    pypi_default_username=None,
    pypi_default_password=None,
    namespaces=['acme'],
    namespace_separator='.',
    third_party_build_prefix='acme',
    email_suffix='acme.example',
    dev_build_number='0.0',
    platform_packages=[],
    installer_search_path=[],
    installer_dev_search_path=[],
    default_platform_package=None,
    deploy_path='/deploy/to/nowhere',
    deploy_bin='/run/from/nowhere',
    vcs='svn',
    virtualenv_executable='virtualenv',
    sphinx_theme='pkglib.sphinx.default_theme',
    sphinx_theme_package=None,
    graph_easy=None,
    test_egg_namespace="acmetests",
    test_linter="flake8",
    test_linter_package="flake8",
    test_dirname="tests",
    jenkins_url=None,
    jenkins_job_xml=None,
    jenkins_matrix_job_xml=None,
    jenkins_matrix_job_pyversions=None,
)