Exemple #1
0
    def test_basic(self):
        pkg = self.make_package('foo', remote='foo/1.2.3@conan/stable')
        self.assertEqual(pkg.remote, 'foo/1.2.3@conan/stable')
        self.assertEqual(pkg.build, False)
        self.assertEqual(pkg.options, {})
        self.assertEqual(pkg.needs_dependencies, False)
        self.assertEqual(pkg.should_deploy, True)

        with mock_open_log(mock_open_write()) as mopen, \
             mock.patch('subprocess.run') as mcall:  # noqa
            ConanPackage.resolve_all(self.pkgdir, [pkg])

            self.assertEqual(
                mopen.mock_file.getvalue(),
                dedent("""\
                [requires]
                foo/1.2.3@conan/stable

                [options]

                [generators]
                pkg_config
            """))
            mcall.assert_called_with([
                'conan', 'install', '-if',
                os.path.join(self.pkgdir, 'conan'), '--', self.pkgdir
            ],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     universal_newlines=True,
                                     check=True)

        self.check_usage(pkg)
Exemple #2
0
 def test_rehydrate(self):
     opts = self.make_options()
     pkg = ConanPackage('foo',
                        remote='foo/1.2.3@conan/stable',
                        options={'shared': True},
                        _options=opts,
                        config_file=self.config_file)
     data = through_json(pkg.dehydrate())
     self.assertEqual(pkg, Package.rehydrate(data, _options=opts))
Exemple #3
0
    def test_deploy(self):
        pkg = self.make_package('foo', remote='foo/1.2.3@conan/stable')
        self.assertEqual(pkg.should_deploy, True)
        with mock.patch('warnings.warn') as mwarn:
            ConanPackage.deploy_all(self.pkgdir, [pkg])
            mwarn.assert_called_once()

        pkg = self.make_package('foo',
                                remote='foo/1.2.3@conan/stable',
                                deploy=False)
        self.assertEqual(pkg.should_deploy, False)
        with mock.patch('warnings.warn') as mwarn:
            ConanPackage.deploy_all(self.pkgdir, [pkg])
            mwarn.assert_not_called()
Exemple #4
0
    def test_extra_args(self):
        opts = ConanPackage.Options()
        opts(extra_args='--foo',
             config_file=self.config_file,
             _symbols=self.symbols)
        self.assertEqual(opts.extra_args, ShellArguments(['--foo']))

        opts(extra_args='--bar --baz',
             config_file=self.config_file,
             _symbols=self.symbols)
        self.assertEqual(opts.extra_args,
                         ShellArguments(['--foo', '--bar', '--baz']))

        opts(extra_args=['--goat', '--panda'],
             config_file=self.config_file,
             _symbols=self.symbols)
        self.assertEqual(
            opts.extra_args,
            ShellArguments(['--foo', '--bar', '--baz', '--goat', '--panda']))

        opts(extra_args='$variable',
             config_file=self.config_file,
             _symbols=self.symbols)
        self.assertEqual(
            opts.extra_args,
            ShellArguments(
                ['--foo', '--bar', '--baz', '--goat', '--panda', 'value']))
Exemple #5
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 #6
0
 def test_rehydrate(self):
     opts = ConanPackage.Options()
     opts(build='foo',
          extra_args='--arg',
          config_file=self.config_file,
          _symbols=self.symbols)
     data = through_json(opts.dehydrate())
     self.assertEqual(opts, PackageOptions.rehydrate(data))
Exemple #7
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 #8
0
    def test_build(self):
        opts = ConanPackage.Options()
        opts(build='foo', config_file=self.config_file, _symbols=self.symbols)
        self.assertEqual(opts.build, ['foo'])

        opts(build=['bar', 'foo', 'baz'],
             config_file=self.config_file,
             _symbols=self.symbols)
        self.assertEqual(opts.build, ['foo', 'bar', 'baz'])

        opts(build='$variable',
             config_file=self.config_file,
             _symbols=self.symbols)
        self.assertEqual(opts.build, ['foo', 'bar', 'baz', 'value'])
Exemple #9
0
    def test_this_options_build_all(self):
        pkg = self.make_package('foo',
                                remote='foo/1.2.3@conan/stable',
                                this_options={'build': 'all'})
        self.assertEqual(pkg.remote, 'foo/1.2.3@conan/stable')
        self.assertEqual(pkg.build, False)
        self.assertEqual(pkg.options, {})
        self.assertEqual(pkg.should_deploy, True)

        with mock_open_log(mock_open_write()) as mopen, \
             mock.patch('subprocess.run') as mcall:  # noqa
            ConanPackage.resolve_all(self.pkgdir, [pkg])
            mcall.assert_called_with([
                'conan', 'install', '-if',
                os.path.join(self.pkgdir, 'conan'), '--build', '--',
                self.pkgdir
            ],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     universal_newlines=True,
                                     check=True)

        self.check_usage(pkg)
Exemple #10
0
    def test_multiple(self):
        pkgs = [
            self.make_package('foo', remote='foo/1.2.3@conan/stable'),
            self.make_package('bar',
                              remote='bar/2.3.4@conan/stable',
                              options={'shared': True}),
        ]

        with mock_open_log(mock_open_write()) as mopen, \
             mock.patch('subprocess.run') as mcall:  # noqa
            ConanPackage.resolve_all(self.pkgdir, pkgs)

            self.assertEqual(
                mopen.mock_file.getvalue(),
                dedent("""\
                [requires]
                foo/1.2.3@conan/stable
                bar/2.3.4@conan/stable

                [options]
                bar:shared=True

                [generators]
                pkg_config
            """))
            mcall.assert_called_with([
                'conan', 'install', '-if',
                os.path.join(self.pkgdir, 'conan'), '--', self.pkgdir
            ],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     universal_newlines=True,
                                     check=True)

        for pkg in pkgs:
            self.check_usage(pkg)
Exemple #11
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 #12
0
    def test_conditional_packages(self):
        data = dedent("""
          packages:
            foo:
              - if: false
                source: apt
              - source: conan
                remote: foo/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')
        self.assertEqual(cfg.options, opts)

        pkg = ConanPackage('foo',
                           remote='foo/1.2.3',
                           _options=opts,
                           config_file='mopack.yml')
        self.assertEqual(list(cfg.packages.items()), [('foo', pkg)])
Exemple #13
0
 def test_default(self):
     opts = ConanPackage.Options()
     self.assertEqual(opts.build, [])
     self.assertEqual(opts.extra_args, ShellArguments())