Example #1
0
def pytest_run(config, opts):
    """
    activate venv and run pytest
    """
    suite_conf = config.test_suite(opts.suite)
    test_opts = suite_conf.get('test_options')
    where = suite_conf.get('where', 'tests/unit')
    if opts.options:
        # command line overrides
        test_opts = opts.options
    command = "pytest {}".format(where)
    if test_opts:
        command += " {}".format(test_opts)

    if opts.builder is None:
        opts.builder = get_builder_plugin()

    builder = FACTORY(opts.builder)
    activate = builder.activate()
    local(
        '{0} && {1}'.format(
            activate,
            command
        )
    )
Example #2
0
def nose_run(config, opts):
    """
    _nose_test_

    Locally activate vitrualenv and run tests via nose
    """
    where = config.test_where(opts.suite)
    suite_conf = config.test_suite(opts.suite)
    test_opts = suite_conf.get('test_options')
    if opts.options:
        # command line overrides
        test_opts = opts.options

    if opts.builder is None:
        opts.builder = get_builder_plugin()

    builder = FACTORY(opts.builder)
    activate = builder.activate()

    local(
        '{0} && nosetests -w {1} {2}'.format(
            activate,
            where,
            test_opts if test_opts else ""
        )
    )
Example #3
0
def tox_run(config, opts):
    """
    tox test

    activate venv and run tox test suite

    """
    suite_conf = config.test_suite(opts.suite)
    tox_ini = suite_conf.get('tox_ini')
    test_opts = suite_conf.get('test_options')
    if opts.options:
        # command line overrides
        test_opts = opts.options
    tox_command = "tox"
    if tox_ini:
        tox_command += " -c {}".format(tox_ini)
    if test_opts:
        tox_command += " {}".format(test_opts)

    if opts.builder is None:
        opts.builder = get_builder_plugin()

    builder = FACTORY(opts.builder)
    activate = builder.activate()
    local(
        '{0} && {1}'.format(
            activate,
            tox_command
        )
    )
Example #4
0
    def test_builder_extra_conda(self, mock_ospe, mock_base_local, mock_local, mock_repo_dir, mock_load_conf):
        mock_repo_dir.return_value = "REPO"
        mock_ospe.return_value = True
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(return_value={
            'build': {'builder': 'conf'},
            'extra_conda_requirements': 'extra-conda-requirements.txt',
            'extra_requirements': ['test-requirements.txt', 'more-reqs.txt']
        })
        mock_conf.pip_options = mock.Mock(return_value="PIP_OPTIONS")
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('CondaEnv')
        plugin.create(clean=True, upgrade=True, python='3.5', environment='env.yaml')
        plugin.activate()
        mock_base_local.assert_has_calls([
            mock.call('source REPO/venv/bin/activate REPO/venv && python setup.py develop')
        ])

        mock_local.assert_has_calls([
            mock.call('conda remove --all -y -p REPO/venv'),
            mock.call('source REPO/venv/bin/activate REPO/venv && conda env update REPO/venv -f env.yaml'),
            mock.call('source REPO/venv/bin/activate REPO/venv && conda install REPO/venv -f extra-conda-requirements.txt')
        ])
        mock_base_local.reset_mock()
        plugin.create(clean=True, nosetupdevelop=True, environment='env.yaml')
        self.failUnless(not mock_base_local.called)
Example #5
0
    def test_builder_channels(self, mock_ospe, mock_base_local, mock_local, mock_repo_dir, mock_load_conf):
        mock_repo_dir.return_value = "REPO"
        mock_ospe.return_value = True
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(return_value={
            'build': {'builder': 'conf'},
            "conda_channels": ['conda-forge', 'ioam'],
            'extra_requirements': ['test-requirements.txt', 'more-reqs.txt']
        })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('Conda')
        plugin.create(clean=True, python='3.5')
        plugin.activate()
        mock_base_local.assert_has_calls([
            mock.call('source REPO/venv/bin/activate REPO/venv && python setup.py develop')
        ])
        mock_local.assert_has_calls([
            mock.call('conda remove --all -y -p REPO/venv'),
            mock.call('conda install --no-update-dependencies  -c conda-forge -c ioam --yes --file requirements.txt'),
            mock.call('conda install   -c conda-forge -c ioam --yes --file test-requirements.txt'),
            mock.call('conda install   -c conda-forge -c ioam --yes --file more-reqs.txt')

        ])
        mock_base_local.reset_mock()
        plugin.create(clean=True, nosetupdevelop=True)
        self.failUnless(not mock_base_local.called)
Example #6
0
 def test_builder_clean(self, mock_exists, mock_local, mock_repo, mock_load_conf):
     mock_exists.return_value = True
     mock_repo.return_value = "REPO"
     mock_conf = mock.Mock(name="load_configuration")
     mock_conf.get = mock.Mock(return_value={
         'build': {'builder': 'conf'},
         'extra_requirements': ['test-requirements.txt', 'more-reqs.txt'],
         'python': 'python6.7',
         'virtualenv_name': 'venv'
     })
     mock_load_conf.return_value = mock_conf
     plugin = FACTORY('VirtualenvPip')
     plugin.clean()
     self.assertTrue(mock_local.called)
Example #7
0
    def test_builder(self, mock_ospe, mock_pip, mock_base_local, mock_local, mock_repo_dir, mock_load_conf):
        mock_pip.return_value = "PIP_COMMAND"
        mock_repo_dir.return_value = "REPO"
        mock_ospe.return_value = True
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(return_value={
            'build': {'builder': 'conf'},
            'extra_requirements': ['test-requirements.txt', 'more-reqs.txt']
        })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('CondaPip')
        plugin.create(clean=True, python='3.5')
        plugin.activate()
        mock_base_local.assert_has_calls([
            mock.call('source REPO/venv/bin/activate REPO/venv && python setup.py develop')
        ])

        mock_local.assert_has_calls([
            mock.call('conda remove --all -y -p REPO/venv'),
            mock.call('PIP_COMMAND'),
            mock.call('PIP_COMMAND'),
            mock.call('PIP_COMMAND')
        ])
        mock_base_local.reset_mock()
        plugin.create(clean=True, nosetupdevelop=True)
        self.failUnless(not mock_base_local.called)
Example #8
0
    def test_builder_new_conda(self, mock_ospe, mock_base_local, mock_local, mock_repo_dir, mock_load_conf):
        mock_repo_dir.return_value = "REPO"
        pe_results  = [True for x in range(17)]
        pe_results.extend([False, False])
        mock_ospe.side_effect = pe_results
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(return_value={
            'build': {'builder': 'conf'},
            'extra_requirements': ['test-requirements.txt', 'more-reqs.txt']
        })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('CondaEnv')
        plugin.create(clean=True, upgrade=True, python='3.5', environment='env.yaml')
        plugin.activate()
        mock_base_local.assert_has_calls([
            mock.call('source REPO/venv/bin/activate REPO/venv && python setup.py develop')
        ])

        mock_local.assert_has_calls([
            mock.call('conda remove --all -y -p REPO/venv'),
            mock.call('source REPO/venv/bin/activate REPO/venv && conda env update REPO/venv -f env.yaml')
        ])

        mock_base_local.reset_mock()
        plugin.create(clean=True, nosetupdevelop=True, environment='env.yaml')
        self.failUnless(not mock_base_local.called)
Example #9
0
    def test_builder_python_bin(self, mock_ospe, mock_pip, mock_base_local, mock_local, mock_repo_dir, mock_load_conf):
        mock_pip.return_value = "PIP_COMMAND"
        mock_repo_dir.return_value = "REPO"
        mock_ospe.return_value = False
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(return_value={
            'build': {'builder': 'conf'},
            'extra_requirements': ['test-requirements.txt', 'more-reqs.txt'],
            'python': '6.7'
        })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('CondaPip')
        self.assertEqual(plugin.python_bin, '6.7')
        self.assertEqual(plugin.python_bin_for_conda, '6.7')
        plugin.create()
        mock_local.assert_has_calls([
            mock.call('conda create -y -m -p REPO/venv pip virtualenv python=6.7')
        ])

        # verify that pythonX.Y format also works
        mock_local.reset_mock()
        mock_conf.get = mock.Mock(return_value={
            'build': {'builder': 'conf'},
            'extra_requirements': ['test-requirements.txt', 'more-reqs.txt'],
            'python': 'python6.7'
        })
        mock_load_conf.return_value = mock_conf
        plugin2 = FACTORY('CondaPip')
        self.assertEqual(plugin2.python_bin, 'python6.7')
        self.assertEqual(plugin2.python_bin_for_conda, '6.7')
        plugin2.create()
        mock_local.assert_has_calls([
            mock.call('conda create -y -m -p REPO/venv pip virtualenv python=6.7')
        ])
Example #10
0
    def test_builder(self, mock_pip, mock_base_local, mock_local,
                     mock_venv_cls, mock_repo_dir, mock_load_conf):
        mock_pip.return_value = "PIP_COMMAND"
        mock_repo_dir.return_value = "REPO"

        mock_venv = mock.Mock()
        mock_venv.open_or_create = mock.Mock()
        mock_venv_cls.return_value = mock_venv
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(
            return_value={
                'build': {
                    'builder': 'conf'
                },
                'extra_requirements':
                ['test-requirements.txt', 'more-reqs.txt']
            })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('VirtualenvPip')
        plugin.create(clean=True)
        plugin.activate()
        mock_base_local.assert_has_calls(
            [mock.call('. REPO/venv/bin/activate && python setup.py develop')])
        mock_local.assert_has_calls([
            mock.call('PIP_COMMAND'),
            mock.call('PIP_COMMAND'),
            mock.call('PIP_COMMAND')
        ])
        mock_base_local.reset_mock()
        plugin.create(clean=True, nosetupdevelop=True)
        self.failUnless(not mock_base_local.called)
Example #11
0
    def test_builder_errors(self, mock_base_local, mock_local, mock_repo_dir,
                            mock_load_conf):
        mock_repo_dir.return_value = "REPO"

        mock_local.side_effect = OSError("BOOM")

        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(
            return_value={
                'build': {
                    'builder': 'conf'
                },
                'extra_requirements':
                ['test-requirements.txt', 'more-reqs.txt']
            })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('CondaEnv')
        self.assertRaises(OSError,
                          plugin.create,
                          upgrade=True,
                          clean=True,
                          environment='env.yaml')

        mock_local.side_effect = [None, OSError("BOOM")]
        self.assertRaises(OSError,
                          plugin.create,
                          clean=True,
                          upgrade=True,
                          environment='env.yaml')
Example #12
0
    def test_builder(self, mock_pip, mock_base_local, mock_local, mock_venv_cls, mock_repo_dir, mock_load_conf):
        mock_pip.return_value = "PIP_COMMAND"
        mock_repo_dir.return_value = "REPO"

        mock_venv = mock.Mock()
        mock_venv.open_or_create = mock.Mock()
        mock_venv_cls.return_value = mock_venv
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(return_value={
            'build': {'builder': 'conf'},
            'extra_requirements': ['test-requirements.txt', 'more-reqs.txt']
        })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('VirtualenvPip')
        plugin.create(clean=True)
        plugin.activate()
        mock_base_local.assert_has_calls([
            mock.call('. REPO/venv/bin/activate && python setup.py develop')
        ])
        mock_local.assert_has_calls([
            mock.call('PIP_COMMAND'),
            mock.call('PIP_COMMAND'),
            mock.call('PIP_COMMAND')
        ])
        mock_base_local.reset_mock()
        plugin.create(clean=True, nosetupdevelop=True)
        self.failUnless(not mock_base_local.called)
Example #13
0
    def test_activate(self, mock_ospe, mock_pip, mock_base_local, mock_local, mock_repo_dir, mock_load_conf):
        mock_pip.return_value = "PIP_COMMAND"
        mock_repo_dir.return_value = "REPO"
        mock_ospe.return_value = True
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(return_value={
            'build': {'builder': 'conf'},
            'extra_requirements': ['test-requirements.txt', 'more-reqs.txt']
        })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('Conda')

        self.assertEqual(
            plugin.activate(),
            "source REPO/venv/bin/activate REPO/venv"
        )
        mock_ospe.return_value = False
        self.assertEqual(plugin.activate(), "source activate REPO/venv")
Example #14
0
 def test_builder_clean(self, mock_exists, mock_local, mock_repo,
                        mock_load_conf):
     mock_exists.return_value = True
     mock_repo.return_value = "REPO"
     mock_conf = mock.Mock(name="load_configuration")
     mock_conf.get = mock.Mock(
         return_value={
             'build': {
                 'builder': 'conf'
             },
             'extra_requirements':
             ['test-requirements.txt', 'more-reqs.txt'],
             'python': 'python6.7',
             'virtualenv_name': 'venv'
         })
     mock_load_conf.return_value = mock_conf
     plugin = FACTORY('VirtualenvPip')
     plugin.clean()
     self.assertTrue(mock_local.called)
Example #15
0
    def test_builder_python_bin(self, mock_pip, mock_base_local, mock_local,
                                mock_venv_cls, mock_repo_dir, mock_load_conf):
        mock_pip.return_value = "PIP_COMMAND"
        mock_repo_dir.return_value = "REPO"

        mock_venv = mock.Mock()
        mock_venv.open_or_create = mock.Mock()
        mock_venv_cls.return_value = mock_venv
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(
            return_value={
                'build': {
                    'builder': 'conf'
                },
                'extra_requirements':
                ['test-requirements.txt', 'more-reqs.txt'],
                'python': 'python6.7'
            })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('VirtualenvPip')
        plugin.create(clean=True)

        mock_venv_cls.assert_has_calls([
            mock.call('REPO/venv',
                      python='python6.7',
                      system_site_packages=False)
        ])

        # verify conda style python version works too
        mock_venv_cls.reset_mock()
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(
            return_value={
                'build': {
                    'builder': 'conf'
                },
                'extra_requirements':
                ['test-requirements.txt', 'more-reqs.txt'],
                'python': '6.7'
            })
        mock_load_conf.return_value = mock_conf
        plugin2 = FACTORY('VirtualenvPip')
        plugin2.create(clean=True)

        mock_venv_cls.assert_has_calls([
            mock.call('REPO/venv',
                      python='python6.7',
                      system_site_packages=False)
        ])
Example #16
0
    def test_builder_errors(self, mock_pip, mock_base_local, mock_local,
                            mock_venv_cls, mock_repo_dir, mock_load_conf):
        mock_pip.return_value = "PIP_COMMAND"
        mock_repo_dir.return_value = "REPO"

        mock_venv = mock.Mock()
        mock_local.side_effect = OSError("BOOM")
        mock_venv.open_or_create = mock.Mock()
        mock_venv_cls.return_value = mock_venv
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(
            return_value={
                'build': {
                    'builder': 'conf'
                },
                'extra_requirements':
                ['test-requirements.txt', 'more-reqs.txt']
            })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('VirtualenvPip')
        self.assertRaises(OSError, plugin.create, clean=True)

        mock_local.side_effect = [None, OSError("BOOM")]
        self.assertRaises(OSError, plugin.create, clean=True)
Example #17
0
    def test_builder_python_bin(self, mock_pip, mock_base_local, mock_local, mock_venv_cls, mock_repo_dir, mock_load_conf):
        mock_pip.return_value = "PIP_COMMAND"
        mock_repo_dir.return_value = "REPO"

        mock_venv = mock.Mock()
        mock_venv.open_or_create = mock.Mock()
        mock_venv_cls.return_value = mock_venv
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(return_value={
            'build': {'builder': 'conf'},
            'extra_requirements': ['test-requirements.txt', 'more-reqs.txt'],
            'python': 'python6.7'
        })
        mock_load_conf.return_value = mock_conf
        plugin = FACTORY('VirtualenvPip')
        plugin.create(clean=True)

        mock_venv_cls.assert_has_calls([
            mock.call('REPO/venv', python='python6.7', system_site_packages=False)
        ])

        # verify conda style python version works too
        mock_venv_cls.reset_mock()
        mock_conf = mock.Mock(name="load_configuration")
        mock_conf.get = mock.Mock(return_value={
            'build': {'builder': 'conf'},
            'extra_requirements': ['test-requirements.txt', 'more-reqs.txt'],
            'python': '6.7'
        })
        mock_load_conf.return_value = mock_conf
        plugin2 = FACTORY('VirtualenvPip')
        plugin2.create(clean=True)

        mock_venv_cls.assert_has_calls([
            mock.call('REPO/venv', python='python6.7', system_site_packages=False)
        ])
Example #18
0
 def test_builder_clean(self, mock_exists, mock_local, mock_repo,
                        mock_conf):
     mock_exists.return_value = True
     plugin = FACTORY('VirtualenvPip')
     plugin.clean()
     self.assertTrue(mock_local.called)