Ejemplo n.º 1
0
def test_raises():
    package = spawn_package()

    with pytest.raises(RuntimeError):
        list(format_package_links(package, 'https://example.com/{unknown}'))

    assert list(format_package_links(package,
                                     'https://example.com/{?unknown}')) == []

    with pytest.raises(RuntimeError):
        list(
            format_package_links(package,
                                 'https://example.com/{name|unknownfilter}'))
Ejemplo n.º 2
0
    def test_raises(self) -> None:
        package = spawn_package()

        with self.assertRaises(RuntimeError):
            list(format_package_links(package,
                                      'https://example.com/{unknown}'))

        self.assertEqual(
            list(
                format_package_links(package,
                                     'https://example.com/{?unknown}')), [])

        with self.assertRaises(RuntimeError):
            list(
                format_package_links(
                    package, 'https://example.com/{name|unknownfilter}'))
Ejemplo n.º 3
0
def test_filter():
    assert list(
        format_package_links(spawn_package(
            name='FOO',
            version='1.1',
        ), 'https://example.com/{name|lowercase}')) == [
            'https://example.com/foo'
        ]
Ejemplo n.º 4
0
def test_basic():
    assert list(
        format_package_links(spawn_package(
            name='foo',
            version='1.1',
        ), 'https://example.com/{name}/{version}')) == [
            'https://example.com/foo/1.1'
        ]
Ejemplo n.º 5
0
 def test_filter(self) -> None:
     self.assertEqual(
         list(
             format_package_links(
                 spawn_package(
                     name='FOO',
                     version='1.1',
                 ), 'https://example.com/{name|lowercase}')),
         ['https://example.com/foo'])
Ejemplo n.º 6
0
 def test_basic(self) -> None:
     self.assertEqual(
         list(
             format_package_links(
                 spawn_package(
                     name='foo',
                     version='1.1',
                 ), 'https://example.com/{name}/{version}')),
         ['https://example.com/foo/1.1'])
Ejemplo n.º 7
0
        def postprocess_parsed_packages(
                packages_iter: Iterable[PackageMaker]) -> Iterator[Package]:
            for packagemaker in packages_iter:
                try:
                    package = packagemaker.spawn(
                        repo=repository['name'],
                        family=repository['family'],
                        subrepo=source.get('subrepo'),
                        shadow=repository.get('shadow', False),
                        default_maintainer=repository.get(
                            'default_maintainer'),
                    )
                except RuntimeError as e:
                    packagemaker.log(str(e), Logger.ERROR)
                    raise

                # transform
                if transformer:
                    transformer.process(package)

                # skip removed packages
                if package.has_flag(PackageFlags.REMOVE):
                    continue

                # postprocess flavors
                def strip_flavor(flavor: str) -> str:
                    flavor.removeprefix(package.effname + '-')
                    return flavor

                package.flavors = sorted(
                    set(map(strip_flavor, package.flavors)))

                # add packagelinks
                packagelinks: List[Tuple[int, str]] = []
                for pkglink in source.get('packagelinks', []) + repository.get(
                        'packagelinks', []):
                    if 'type' in pkglink:  # XXX: will become mandatory
                        link_type = LinkType.from_string(pkglink['type'])
                        try:
                            packagelinks.extend(
                                (link_type, url)
                                for url in format_package_links(
                                    package, pkglink['url']))
                        except Exception as e:
                            packagemaker.log(
                                f'cannot spawn package link from template "{pkglink["url"]}": {str(e)}',
                                Logger.ERROR)
                            raise

                if package.links is None:
                    package.links = packagelinks
                else:
                    seen = set(package.links)
                    package.links.extend(link for link in packagelinks
                                         if link not in seen)

                yield package
Ejemplo n.º 8
0
        def postprocess_parsed_packages(packages_iter: Iterable[PackageMaker]) -> Iterator[Package]:
            for packagemaker in packages_iter:
                try:
                    package = packagemaker.spawn(
                        repo=repository.name,
                        family=repository.family,
                        subrepo=source.subrepo,
                        shadow=repository.shadow,
                        default_maintainer=repository.default_maintainer,
                    )
                except RuntimeError as e:
                    packagemaker.log(str(e), Logger.ERROR)
                    raise

                # transform
                if transformer:
                    transformer.process(package)

                # skip removed packages
                if package.has_flag(PackageFlags.REMOVE):
                    continue

                # postprocess flavors
                def strip_flavor(flavor: str) -> str:
                    flavor.removeprefix(package.effname + '-')
                    return flavor

                package.flavors = sorted(set(map(strip_flavor, package.flavors)))

                # add packagelinks
                packagelinks: list[tuple[int, str]] = []
                for pkglink in source.packagelinks + repository.packagelinks:
                    link_type = pkglink.type
                    try:
                        packagelinks.extend(
                            (link_type, url)
                            for url in format_package_links(package, pkglink.url)
                        )
                    except Exception as e:
                        packagemaker.log(f'cannot spawn package link from template "{pkglink.url}": {str(e)}', Logger.ERROR)
                        raise

                if package.links is None:
                    package.links = packagelinks
                else:
                    seen = set(package.links)
                    package.links.extend(link for link in packagelinks if link not in seen)

                # postprocess maintainers
                if maintainermgr and package.maintainers:
                    package.maintainers = [maintainer for maintainer in package.maintainers if not maintainermgr.is_hidden(maintainer)]

                yield package
Ejemplo n.º 9
0
def test_list():
    package = spawn_package()
    package.extrafields = {
        'patch': ['foo', 'bar', 'baz'],
        'suffix': ['a', 'b']
    }

    assert list(
        format_package_links(package,
                             'https://example.com/{patch}{suffix}')) == [
                                 'https://example.com/fooa',
                                 'https://example.com/foob',
                                 'https://example.com/bara',
                                 'https://example.com/barb',
                                 'https://example.com/baza',
                                 'https://example.com/bazb',
                             ]
Ejemplo n.º 10
0
    def test_list(self) -> None:
        package = spawn_package()
        package.extrafields = {
            'patch': ['foo', 'bar', 'baz'],
            'suffix': ['a', 'b']
        }

        self.assertEqual(
            list(
                format_package_links(package,
                                     'https://example.com/{patch}{suffix}')), [
                                         'https://example.com/fooa',
                                         'https://example.com/foob',
                                         'https://example.com/bara',
                                         'https://example.com/barb',
                                         'https://example.com/baza',
                                         'https://example.com/bazb',
                                     ])