Exemplo n.º 1
0
    def test_multiple_common_options(self):
        data1 = dedent("""
          options:
            target_platform: linux
            env:
              FOO: foo
          packages:
            foo:
              source: apt
        """)
        data2 = dedent("""
          options:
            target_platform: windows
            env:
              FOO: bad
          packages:
            bar:
              source: apt
        """)

        files = {'mopack.yml': data1, 'mopack2.yml': data2}
        with mock.patch('builtins.open', mock_open_files(files)):
            cfg = Config(['mopack2.yml', 'mopack.yml'])
        cfg.finalize()

        opts = Options()
        opts.common.target_platform = 'linux'
        opts.common.env = {'FOO': 'foo'}
        opts.common.finalize()
        self.assertEqual(cfg.options, opts)

        pkg1 = AptPackage('foo', _options=opts, config_file='mopack.yml')
        pkg2 = AptPackage('bar', _options=opts, config_file='mopack.yml')
        self.assertEqual(list(cfg.packages.items()), [('foo', pkg1),
                                                      ('bar', pkg2)])
Exemplo n.º 2
0
    def test_directory(self):
        def exists(p):
            return os.path.basename(p) == 'dir'

        files = {
            'mopack.yml': foo_cfg,
            'mopack-local.yml': bar_cfg,
            'mopack-foobar.yml': foobar_cfg
        }
        with mock.patch('os.path.isdir', exists), \
             mock.patch('os.path.exists', return_value=True), \
             mock.patch('builtins.open', mock_open_files(files)):  # noqa
            # Filenames are in reversed order from file data, since Config
            # loads last-to-first.
            cfg = Config(['dir', 'mopack-foobar.yml'])
        self.assertEqual(list(cfg.packages.items()), [
            ('bar',
             AptPackage('bar',
                        remote='libbar1-dev',
                        _options=self.default_opts,
                        config_file='mopack2.yml')),
            ('foo',
             AptPackage(
                 'foo', _options=self.default_opts, config_file='mopack.yml')),
        ])
Exemplo n.º 3
0
    def test_child_mixed_in_parent(self):
        files = {'mopack.yml': foo_cfg, 'mopack-child.yml': foobar_cfg}
        with mock.patch('builtins.open', mock_open_files(files)):
            parent = Config(['mopack.yml'])
        with mock.patch('builtins.open', mock_open_files(files)):
            child = ChildConfig(['mopack-child.yml'], parent=parent)
        self.assertEqual(list(child.packages.items()), [
            ('foo', PlaceholderPackage),
            ('bar',
             AptPackage('bar',
                        _options=self.default_opts,
                        config_file='mopack-child.yml')),
        ])

        parent.add_children([child])
        self.assertEqual(list(parent.packages.items()), [
            ('foo',
             AptPackage('foo',
                        remote='libfoo1-dev',
                        _options=self.default_opts,
                        config_file='mopack.yml')),
            ('bar',
             AptPackage('bar',
                        _options=self.default_opts,
                        config_file='mopack-child.yml')),
        ])
Exemplo n.º 4
0
 def test_single_file(self):
     files = {'mopack.yml': foobar_cfg}
     with mock.patch('builtins.open', mock_open_files(files)):
         cfg = Config(['mopack.yml'])
     self.assertEqual(list(cfg.packages.items()), [
         ('foo',
          AptPackage(
              'foo', _options=self.default_opts, config_file='mopack.yml')),
         ('bar',
          AptPackage(
              'bar', _options=self.default_opts, config_file='mopack.yml')),
     ])
Exemplo n.º 5
0
    def test_builder_options(self):
        data = dedent("""
          options:
            builders:
              bfg9000:
                toolchain: toolchain.bfg
              goat:
                sound: baah
          packages:
            foo:
              source: apt
            bar:
              source: directory
              path: /path/to/src
              build: bfg9000
        """)
        files = {'mopack.yml': data}
        with mock.patch('builtins.open', mock_open_files(files)):
            cfg = Config(['mopack.yml'])
        cfg.finalize()

        opts = Options.default()
        opts.add('builders', 'bfg9000')
        opts.builders['bfg9000'].toolchain = os.path.abspath('toolchain.bfg')
        self.assertEqual(cfg.options, opts)

        pkg1 = AptPackage('foo', _options=opts, config_file='mopack.yml')
        pkg2 = DirectoryPackage('bar',
                                path=normpath('/path/to/src'),
                                build='bfg9000',
                                _options=opts,
                                config_file='mopack.yml')
        self.assertEqual(list(cfg.packages.items()), [('foo', pkg1),
                                                      ('bar', pkg2)])
Exemplo n.º 6
0
    def test_source_options(self):
        data = dedent("""
          options:
            sources:
              conan:
                extra_args: foo
              goat:
                sound: baah
          packages:
            foo:
              source: apt
            bar:
              source: conan
              remote: bar/1.2.3
        """)
        files = {'mopack.yml': data}
        with mock.patch('builtins.open', mock_open_files(files)):
            cfg = Config(['mopack.yml'])
        cfg.finalize()

        opts = Options.default()
        opts.add('sources', 'conan')
        opts.sources['conan'].extra_args.append('foo')
        self.assertEqual(cfg.options, opts)

        pkg1 = AptPackage('foo', _options=opts, config_file='mopack.yml')
        pkg2 = ConanPackage('bar',
                            remote='bar/1.2.3',
                            _options=opts,
                            config_file='mopack.yml')
        self.assertEqual(list(cfg.packages.items()), [('foo', pkg1),
                                                      ('bar', pkg2)])
Exemplo n.º 7
0
 def test_override(self):
     files = {'mopack-foo.yml': foo_cfg, 'mopack-foobar.yml': foobar_cfg}
     with mock.patch('builtins.open', mock_open_files(files)):
         # Filenames are in reversed order from file data, since Config
         # loads last-to-first.
         cfg = Config(['mopack-foobar.yml', 'mopack-foo.yml'])
     self.assertEqual(list(cfg.packages.items()), [
         ('foo',
          AptPackage('foo',
                     remote='libfoo1-dev',
                     _options=self.default_opts,
                     config_file='mopack2.yml')),
         ('bar',
          AptPackage(
              'bar', _options=self.default_opts, config_file='mopack.yml')),
     ])
Exemplo n.º 8
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)
Exemplo n.º 9
0
    def test_multiple_source_options(self):
        data1 = dedent("""
          options:
            sources:
              conan:
                extra_args: -B
        """)
        data2 = dedent("""
          options:
            sources:
              conan:
                extra_args: -C
                final: true
          packages:
            foo:
              source: apt
        """)
        data3 = dedent("""
          options:
            sources:
              conan:
                extra_args: -D
          packages:
            bar:
              source: conan
              remote: bar/1.2.3
        """)

        files = {
            'mopack.yml': data1,
            'mopack2.yml': data2,
            'mopack3.yml': data3
        }
        with mock.patch('builtins.open', mock_open_files(files)):
            cfg = Config(['mopack3.yml', 'mopack2.yml', 'mopack.yml'],
                         {'sources': {
                             'conan': {
                                 'extra_args': '-A'
                             }
                         }})
        cfg.finalize()

        opts = Options.default()
        opts.add('sources', 'conan')
        opts.sources['conan'].extra_args.extend(['-A', '-B', '-C'])
        self.assertEqual(cfg.options, opts)

        pkg1 = AptPackage('foo', _options=opts, config_file='mopack.yml')
        pkg2 = ConanPackage('bar',
                            remote='bar/1.2.3',
                            _options=opts,
                            config_file='mopack.yml')
        self.assertEqual(list(cfg.packages.items()), [('foo', pkg1),
                                                      ('bar', pkg2)])
Exemplo n.º 10
0
 def test_binary_package(self):
     cfg = self.make_apt_config()
     with mock.patch('os.path.exists', return_value=False), \
          mock.patch('builtins.open', side_effect=FileNotFoundError()), \
          mock.patch.object(AptPackage, 'fetch') as mfetch:  # noqa
         metadata = commands.fetch(cfg, self.pkgdir)
         self.assertEqual(metadata.files, [os.path.abspath('mopack.yml')])
         self.assertEqual(metadata.implicit_files, [])
         self.assertEqual(metadata.packages, {'foo': AptPackage(
             'foo', remote='libfoo1-dev', _options=cfg.options,
             config_file=os.path.abspath('mopack.yml'),
         )})
         mfetch.assert_called_once()
Exemplo n.º 11
0
    def test_changed_package(self):
        cfg = self.make_apt_config()

        old_metadata = commands.Metadata()
        old_metadata.add_package(AptPackage(
            'foo', _options=cfg.options,
            config_file=os.path.abspath('mopack.yml'),
        ))

        with mock.patch('os.path.exists', return_value=False), \
             mock.patch('mopack.commands.Metadata.try_load',
                        return_value=old_metadata), \
             mock.patch.object(AptPackage, 'fetch') as mfetch, \
             mock.patch.object(AptPackage, 'clean_post') as mclean:  # noqa
            metadata = commands.fetch(cfg, self.pkgdir)
            self.assertEqual(metadata.files, [os.path.abspath('mopack.yml')])
            self.assertEqual(metadata.implicit_files, [])
            self.assertEqual(metadata.packages, {'foo': AptPackage(
                'foo', remote='libfoo1-dev', _options=cfg.options,
                config_file=os.path.abspath('mopack.yml'),
            )})
            mfetch.assert_called_once()
            mclean.assert_called_once()
Exemplo n.º 12
0
    def test_batch_package(self):
        cfg = self.make_empty_config(['mopack.yml'])

        metadata = commands.Metadata()
        metadata.add_package(AptPackage(
            'foo', _options=cfg.options,
            config_file=os.path.abspath('mopack.yml'),
        ))

        with mock.patch('mopack.commands.fetch', return_value=metadata), \
             mock.patch.object(AptPackage, 'resolve_all') as mresolve, \
             mock.patch.object(commands.Metadata, 'save') as msave:  # noqa
            commands.resolve(cfg, self.pkgdir)
            mresolve.assert_called_once()
            msave.assert_called_once()
Exemplo n.º 13
0
    def test_child_duplicate(self):
        files = {'mopack-child1.yml': foo_cfg, 'mopack-child2.yml': foo_cfg}
        parent = Config([])
        with mock.patch('builtins.open', mock_open_files(files)):
            child1 = ChildConfig(['mopack-child1.yml'], parent=parent)
        with mock.patch('builtins.open', mock_open_files(files)):
            child2 = ChildConfig(['mopack-child2.yml'], parent=parent)

        parent.add_children([child1, child2])
        self.assertEqual(list(parent.packages.items()), [
            ('foo',
             AptPackage('foo',
                        remote='libfoo1-dev',
                        _options=self.default_opts,
                        config_file='mopack.yml')),
        ])
Exemplo n.º 14
0
    def test_packages(self):
        data = dedent("""
          packages:
            foo:
              source: apt
        """)
        files = {'mopack.yml': data}
        with mock.patch('builtins.open', mock_open_files(files)):
            cfg = Config(['mopack.yml'])
        cfg.finalize()

        opts = Options.default()
        self.assertEqual(cfg.options, opts)

        pkg = AptPackage('foo', _options=opts, config_file='mopack.yml')
        self.assertEqual(list(cfg.packages.items()), [('foo', pkg)])
Exemplo n.º 15
0
    def test_removed_package(self):
        cfg = self.make_empty_config()

        old_metadata = commands.Metadata()
        old_metadata.add_package(AptPackage(
            'foo', _options=cfg.options,
            config_file=os.path.abspath('mopack.yml'),
        ))

        with mock.patch('os.path.exists', return_value=False), \
             mock.patch('mopack.commands.Metadata.try_load',
                        return_value=old_metadata), \
             mock.patch.object(AptPackage, 'clean_all') as mclean:
            metadata = commands.fetch(cfg, self.pkgdir)
            self.assertEqual(metadata.files, [])
            self.assertEqual(metadata.implicit_files, [])
            self.assertEqual(metadata.packages, {})
            mclean.assert_called_once()
Exemplo n.º 16
0
    def test_source_options(self):
        data1 = dedent("""
          options:
            sources:
              conan:
                extra_args: foo
        """)
        data2 = dedent("""
          options:
            sources:
              conan:
                extra_args: bar
              goat:
                sound: baah
          packages:
            foo:
              source: apt
            bar:
              source: conan
              remote: bar/1.2.3
        """)

        files = {'mopack.yml': data1, 'mopack-child.yml': data2}

        with mock.patch('builtins.open', mock_open_files(files)):
            parent = Config(['mopack.yml'])
        with mock.patch('builtins.open', mock_open_files(files)):
            child = ChildConfig(['mopack-child.yml'], parent=parent)

        parent.add_children([child])
        parent.finalize()

        opts = Options.default()
        opts.add('sources', 'conan')
        opts.sources['conan'].extra_args.extend(['foo', 'bar'])
        self.assertEqual(parent.options, opts)

        pkg1 = AptPackage('foo', _options=opts, config_file='mopack.yml')
        pkg2 = ConanPackage('bar',
                            remote='bar/1.2.3',
                            _options=opts,
                            config_file='mopack.yml')
        self.assertEqual(list(parent.packages.items()), [('foo', pkg1),
                                                         ('bar', pkg2)])
Exemplo n.º 17
0
    def test_batch_package_failure(self):
        cfg = self.make_empty_config(['mopack.yml'])

        metadata = commands.Metadata()
        metadata.add_package(AptPackage(
            'foo', _options=cfg.options,
            config_file=os.path.abspath('mopack.yml'),
        ))

        with mock.patch('mopack.commands.fetch', return_value=metadata), \
             mock.patch.object(AptPackage, 'resolve_all',
                               side_effect=RuntimeError()) as mresolve, \
             mock.patch.object(AptPackage, 'clean_post') as mclean, \
             mock.patch.object(commands.Metadata, 'save') as msave:  # noqa
            with self.assertRaises(RuntimeError):
                commands.resolve(cfg, self.pkgdir)
            mresolve.assert_called_once()
            mclean.assert_called_once()
            msave.assert_called_once()
Exemplo n.º 18
0
    def test_builder_options(self):
        data = dedent("""
          options:
            builders:
              bfg9000:
                toolchain: toolchain.bfg
              goat:
                sound: baah
          packages:
            foo:
              source: apt
            bar:
              source: directory
              path: /path/to/src
              build: bfg9000
        """)
        files = {'mopack.yml': '', 'mopack-child.yml': data}

        with mock.patch('builtins.open', mock_open_files(files)):
            parent = Config(['mopack.yml'])
        with mock.patch('builtins.open', mock_open_files(files)):
            child = ChildConfig(['mopack-child.yml'], parent=parent)

        parent.add_children([child])
        parent.finalize()

        opts = Options.default()
        opts.add('builders', 'bfg9000')
        self.assertEqual(parent.options, opts)

        pkg1 = AptPackage('foo', _options=opts, config_file='mopack.yml')
        pkg2 = DirectoryPackage('bar',
                                path=normpath('/path/to/src'),
                                build='bfg9000',
                                _options=opts,
                                config_file='mopack.yml')
        self.assertEqual(list(parent.packages.items()), [('foo', pkg1),
                                                         ('bar', pkg2)])
Exemplo n.º 19
0
 def test_deploy(self):
     pkg = self.make_package('foo')
     # This is a no-op; just make sure it executes ok.
     AptPackage.deploy_all(self.pkgdir, [pkg])
Exemplo n.º 20
0
 def test_rehydrate(self):
     opts = self.make_options()
     pkg = AptPackage('foo', remote='libbar-dev', _options=opts,
                      config_file=self.config_file)
     data = through_json(pkg.dehydrate())
     self.assertEqual(pkg, Package.rehydrate(data, _options=opts))