Exemple #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)])
Exemple #2
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')),
        ])
Exemple #3
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')),
        ])
Exemple #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')),
     ])
Exemple #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)])
Exemple #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)])
Exemple #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')),
     ])
Exemple #8
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)])
Exemple #9
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()
Exemple #10
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()
Exemple #11
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()
Exemple #12
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')),
        ])
Exemple #13
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)])
Exemple #14
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()
Exemple #15
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)])
Exemple #16
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()
Exemple #17
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)])
Exemple #18
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))