Exemple #1
0
    def check_build(self,
                    builder,
                    extra_args=[],
                    *,
                    submodules=None,
                    usage=None):
        if usage is None:
            pcfiles = ['foo']
            pcfiles.extend('foo_{}'.format(i) for i in iterate(submodules))
            usage = {
                'type': 'pkg_config',
                'path': self.pkgconfdir('foo'),
                'pcfiles': pcfiles,
                'extra_args': []
            }

        with mock_open_log() as mopen, \
             mock.patch('mopack.builders.cmake.pushd'), \
             mock.patch('subprocess.run') as mcall:  # noqa
            builder.build(self.pkgdir, self.srcdir)
            mopen.assert_called_with(
                os.path.join(self.pkgdir, 'logs', 'foo.log'), 'a')
            mcall.assert_any_call(['cmake', self.srcdir, '-G', 'Ninja'] +
                                  extra_args,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.STDOUT,
                                  universal_newlines=True,
                                  check=True)
            mcall.assert_called_with(['ninja'],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     universal_newlines=True,
                                     check=True)
        self.assertEqual(
            builder.get_usage(self.pkgdir, submodules, self.srcdir), usage)
Exemple #2
0
 def check_usage(self, pkg, *, submodules=None, usage=None):
     if usage is None:
         pcfiles = ([] if pkg.submodules and pkg.submodules['required'] else
                    [pkg.name])
         pcfiles.extend('{}_{}'.format(pkg.name, i)
                        for i in iterate(submodules))
         usage = {
             'type': 'pkg_config',
             'path': self.pkgconfdir,
             'pcfiles': pcfiles,
             'extra_args': []
         }
     self.assertEqual(pkg.get_usage(self.pkgdir, submodules), usage)
Exemple #3
0
    def check_resolve(self, pkg, *, submodules=None, usage=None):
        if usage is None:
            pcfiles = ([] if pkg.submodules and pkg.submodules['required'] else
                       ['foo'])
            pcfiles.extend('foo_{}'.format(i) for i in iterate(submodules))
            usage = {
                'type': 'pkg_config',
                'path': self.pkgconfdir('foo'),
                'pcfiles': pcfiles,
                'extra_args': []
            }

        with mock_open_log() as mopen, \
             mock.patch('mopack.builders.bfg9000.pushd'), \
             mock.patch('subprocess.run'):  # noqa
            pkg.resolve(self.pkgdir)
            mopen.assert_called_with(
                os.path.join(self.pkgdir, 'logs', 'foo.log'), 'a')
        self.assertEqual(pkg.get_usage(self.pkgdir, submodules), usage)
Exemple #4
0
    def check_resolve_all(self, packages, remotes, *, submodules=None,
                          usages=None):
        with mock_open_log() as mopen, \
             mock.patch('subprocess.run') as mcall:  # noqa
            AptPackage.resolve_all(self.pkgdir, packages)

            mopen.assert_called_with(os.path.join(
                self.pkgdir, 'logs', 'apt.log'
            ), 'a')
            for i in packages:
                if i.repository:
                    mcall.assert_any_call(
                        ['sudo', 'add-apt-repository', '-y', i.repository],
                        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                        universal_newlines=True, check=True
                    )
            mcall.assert_any_call(
                ['sudo', 'apt-get', 'update'], stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT, universal_newlines=True, check=True
            )
            mcall.assert_any_call(
                ['sudo', 'apt-get', 'install', '-y'] + remotes,
                stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                universal_newlines=True, check=True
            )

        if usages is None:
            usages = []
            for pkg in packages:
                libs = ([] if pkg.submodules and pkg.submodules['required']
                        else [pkg.name])
                libs.extend('{}_{}'.format(pkg.name, i)
                            for i in iterate(submodules))
                usages.append({
                    'type': 'path', 'auto_link': False, 'include_path': [],
                    'library_path': [], 'headers': [], 'libraries': libs,
                    'compile_flags': [], 'link_flags': [],
                })

        for pkg, usage in zip(packages, usages):
            with mock.patch('subprocess.run', side_effect=OSError()):
                self.assertEqual(pkg.get_usage(self.pkgdir, submodules), usage)
Exemple #5
0
    def check_build(self,
                    builder,
                    extra_args=[],
                    *,
                    submodules=None,
                    usage=None):
        if usage is None:
            pcfiles = ['foo']
            pcfiles.extend('foo_{}'.format(i) for i in iterate(submodules))
            usage = {
                'type': 'pkg_config',
                'path': self.pkgconfdir('foo'),
                'pcfiles': pcfiles,
                'extra_args': []
            }

        with mock.patch('subprocess.run') as mcall:
            builder.build(self.pkgdir, self.srcdir)
            mcall.assert_not_called()
        self.assertEqual(
            builder.get_usage(self.pkgdir, submodules, self.srcdir), usage)
Exemple #6
0
    def check_build(self,
                    builder,
                    build_commands=None,
                    *,
                    submodules=None,
                    usage=None):
        if usage is None:
            pcfiles = ['foo']
            pcfiles.extend('foo_{}'.format(i) for i in iterate(submodules))
            usage = {
                'type': 'pkg_config',
                'path': self.pkgconfdir('foo'),
                'pcfiles': pcfiles,
                'extra_args': []
            }
        if build_commands is None:
            builddir = os.path.join(self.pkgdir, 'build', builder.name)
            build_commands = [
                i.fill(srcdir=self.srcdir, builddir=builddir)
                for i in builder.build_commands
            ]

        with mock_open_log() as mopen, \
             mock.patch('mopack.builders.custom.pushd'), \
             mock.patch('subprocess.run') as mcall:  # noqa
            builder.build(self.pkgdir, self.srcdir)
            mopen.assert_called_with(
                os.path.join(self.pkgdir, 'logs', 'foo.log'), 'a')
            for line in build_commands:
                mcall.assert_any_call(line,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.STDOUT,
                                      universal_newlines=True,
                                      check=True)
        self.assertEqual(
            builder.get_usage(self.pkgdir, submodules, self.srcdir), usage)
Exemple #7
0
 def test_many(self):
     self.assertEqual(list(iterutils.iterate(['foo', 'bar'])),
                      ['foo', 'bar'])
Exemple #8
0
 def test_one(self):
     self.assertEqual(list(iterutils.iterate('foo')), ['foo'])
Exemple #9
0
 def test_none(self):
     self.assertEqual(list(iterutils.iterate(None)), [])