コード例 #1
0
    def test_build(self, mock_base_build, mock_run, mock_run_output):
        self.options.requirements = 'requirements.txt'
        self.options.constraints = 'constraints.txt'
        self.options.python_packages = ['test', 'packages']

        class TempDir(tempfile.TemporaryDirectory):
            def __enter__(self):
                project_whl_path = os.path.join(self.name, 'project.whl')
                open(project_whl_path, 'w').close()
                return super().__enter__()

        patcher = mock.patch('tempfile.TemporaryDirectory',
                             new=mock.Mock(wraps=TempDir))
        patcher.start()
        self.addCleanup(patcher.stop)

        mock_run_output.return_value = 'yaml (1.2)\bextras (1.0)'

        os.environ = {}
        plugin = python.PythonPlugin('test-part', self.options,
                                     self.project_options)
        setup_directories(plugin, self.options.python_version)

        def build_side_effect():
            open(os.path.join(plugin.builddir, 'setup.py'), 'w').close()

        mock_base_build.side_effect = build_side_effect

        requirements_path = os.path.join(plugin.sourcedir, 'requirements.txt')
        constraints_path = os.path.join(plugin.sourcedir, 'constraints.txt')

        pip_wheel = [
            'pip', 'wheel', '--disable-pip-version-check', '--no-index',
            '--find-links', plugin._python_package_dir, '--constraint',
            constraints_path, '--wheel-dir', mock.ANY
        ]

        pip_install = [
            'pip', 'install', '--user', '--no-compile',
            '--disable-pip-version-check', '--no-index', '--find-links',
            plugin._python_package_dir, '--constraint', constraints_path
        ]

        calls = [
            mock.call(pip_wheel + ['--requirement', requirements_path],
                      env=mock.ANY),
            mock.call(tests.ContainsList(pip_install + ['project.whl']),
                      env=mock.ANY),
            mock.call(pip_wheel + ['test', 'packages'], env=mock.ANY),
            mock.call(tests.ContainsList(pip_install + ['project.whl']),
                      env=mock.ANY),
            mock.call(pip_wheel + ['.'], cwd=plugin.builddir, env=mock.ANY),
            mock.call(tests.ContainsList(pip_install + ['project.whl']),
                      env=mock.ANY),
        ]
        plugin.build()
        mock_run.assert_has_calls(calls)
コード例 #2
0
    def test_build(self, mock_base_build, mock_run, mock_run_output):
        self.options.requirements = 'requirements.txt'
        self.options.constraints = 'constraints.txt'
        self.options.python_packages = ['test', 'packages']

        class TempDir(tempfile.TemporaryDirectory):
            def __enter__(self):
                project_whl_path = os.path.join(self.name, 'project.whl')
                open(project_whl_path, 'w').close()
                return super().__enter__()

        patcher = mock.patch('tempfile.TemporaryDirectory',
                             new=mock.Mock(wraps=TempDir))
        patcher.start()
        self.addCleanup(patcher.stop)

        mock_run_output.return_value = (
            '[{"name": "yaml", "version": "1.2"},'
            ' {"name": "extras", "version": "1.0"}]')

        self.useFixture(fixture_setup.CleanEnvironment())
        plugin = python.PythonPlugin('test-part', self.options,
                                     self.project_options)
        setup_directories(plugin, self.options.python_version)

        for file_name in (self.options.requirements, self.options.constraints):
            path = os.path.join(plugin.sourcedir, file_name)
            open(path, 'w').close()

        def build_side_effect():
            open(os.path.join(plugin.builddir, 'setup.py'), 'w').close()
            os.mkdir(os.path.join(plugin.builddir, 'dist'))
            open(os.path.join(plugin.builddir, 'dist', 'package.tar'),
                 'w').close()

        mock_base_build.side_effect = build_side_effect

        requirements_path = os.path.join(plugin.sourcedir, 'requirements.txt')
        constraints_path = os.path.join(plugin.sourcedir, 'constraints.txt')

        pip_command = [
            os.path.join(plugin.installdir, 'usr', 'bin', 'python3'), '-m',
            'pip'
        ]

        pip_wheel = [
            'wheel', '--disable-pip-version-check', '--no-index',
            '--find-links', plugin._python_package_dir, '--constraint',
            constraints_path, '--wheel-dir', mock.ANY
        ]

        pip_install = [
            'install', '--user', '--no-compile', '--disable-pip-version-check',
            '--no-index', '--find-links', plugin._python_package_dir,
            '--constraint', constraints_path
        ]

        calls = [
            mock.call(
                pip_command + pip_wheel +
                ['--requirement', requirements_path, '.', 'test', 'packages'],
                cwd=plugin.builddir,
                env=mock.ANY),
            mock.call(tests.ContainsList(pip_command + pip_install +
                                         ['project.whl']),
                      env=mock.ANY),
        ]
        plugin.build()
        mock_run.assert_has_calls(calls)