Skip to content

Commit

Permalink
Add tests for package field generation
Browse files Browse the repository at this point in the history
  • Loading branch information
matteodelabre committed Sep 1, 2021
1 parent 46d2355 commit b286730
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 3 deletions.
5 changes: 5 additions & 0 deletions tests/recipe_parsers/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def tearDown(self) -> None:
self.dir_handle.cleanup()

def test_basic_recipe(self) -> None:
"""Check that basic fields are parsed."""
rec_path = path.join(self.dir, "basic-recipe")
os.makedirs(rec_path)

Expand Down Expand Up @@ -180,6 +181,7 @@ def test_basic_recipe(self) -> None:
)

def test_dependencies(self):
"""Check that dependency fields are parsed (depends, recommends, ...)"""
rec_path = path.join(self.dir, "dependencies")
os.makedirs(rec_path)

Expand Down Expand Up @@ -313,6 +315,7 @@ def test_dependencies(self):
)

def test_split_packages(self):
"""Check that recipes defining several packages are parsed."""
rec_path = path.join(self.dir, "split-packages")
os.makedirs(rec_path)

Expand Down Expand Up @@ -574,6 +577,7 @@ def test_split_packages(self):
)

def test_split_archs(self):
"""Check that recipes supporting multiple architectures are parsed."""
rec_path = path.join(self.dir, "split-archs")
os.makedirs(rec_path)

Expand Down Expand Up @@ -1112,6 +1116,7 @@ def test_split_archs(self):
self.assertEqual(part2.postremove, "")

def test_errors(self) -> None:
"""Check error messages raised when invalid recipes are parsed."""
rec_path = path.join(self.dir, "errors")
os.makedirs(rec_path)

Expand Down
92 changes: 92 additions & 0 deletions tests/test_recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright (c) 2021 The Toltec Contributors
# SPDX-License-Identifier: MIT

import unittest
import textwrap
from datetime import datetime
from toltec.recipe import Package, Recipe
from toltec.version import (
Version,
Dependency,
DependencyKind,
VersionComparator,
)


class TestRecipe(unittest.TestCase):
def test_derived_fields(self) -> None:
rec = Recipe(
path="test",
timestamp=datetime.now(),
sources=set(),
makedepends=set(),
maintainer="Test <[email protected]>",
image="",
arch="armv7-3.2",
flags=[],
prepare="",
build="",
packages={},
)

pkg = Package(
name="test",
parent=rec,
version=Version(42, "12.1", "8"),
desc="Test package",
url="https://example.com/toltec/test",
section="misc",
license="MIT",
installdepends={
Dependency(
DependencyKind.HOST,
"test-dep",
VersionComparator.EQUAL,
Version(42, "1.0.0", "8"),
),
Dependency(
DependencyKind.HOST,
"aaaaaaaa",
VersionComparator.GREATER_THAN_OR_EQUAL,
Version(0, "1.0.0", "1"),
),
},
recommends={Dependency(DependencyKind.HOST, "recommended")},
optdepends={Dependency(DependencyKind.HOST, "optdep")},
conflicts={Dependency(DependencyKind.HOST, "conflict")},
replaces={Dependency(DependencyKind.HOST, "replaced")},
provides={Dependency(DependencyKind.HOST, "provided")},
package="",
preinstall="",
configure="",
preupgrade="",
postupgrade="",
preremove="",
postremove="",
)

self.assertEqual(pkg.pkgid(), "test_42_12.1-8_armv7-3.2")
self.assertEqual(
pkg.filename(), "armv7-3.2/test_42_12.1-8_armv7-3.2.ipk"
)
self.assertEqual(
pkg.control_fields(),
textwrap.dedent(
"""\
Package: test
Description: Test package
Homepage: https://example.com/toltec/test
Version: 42:12.1-8
Section: misc
Maintainer: Test <[email protected]>
License: MIT
Architecture: armv7-3.2
Depends: aaaaaaaa (>= 1.0.0-1), test-dep (= 42:1.0.0-8)
Recommends: recommended
Suggests: optdep
Conflicts: conflict
Replaces: replaced
Provides: provided
"""
),
)
File renamed without changes.
11 changes: 8 additions & 3 deletions toltec/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from toltec import util


def main():
def main() -> int:
"""Execute requested commands and return appropriate exit code."""
parser = argparse.ArgumentParser(description=__doc__)

parser.add_argument(
Expand Down Expand Up @@ -92,7 +93,9 @@ def main():
spec.loader.exec_module(module) # type: ignore
module.register(builder) # type: ignore
else:
raise RuntimeError(f"Hook module '{ident}' couldn’t be loaded")
raise RuntimeError(
f"Hook module '{ident}' couldn’t be loaded"
)

build_matrix: Optional[Dict[str, Optional[List[Package]]]] = None

Expand All @@ -102,7 +105,8 @@ def main():
for arch, recipes in recipe_bundle.items():
if args.package_name:
build_matrix[arch] = [
recipes.packages[pkg_name] for pkg_name in args.package_name
recipes.packages[pkg_name]
for pkg_name in args.package_name
]
else:
build_matrix[arch] = None
Expand All @@ -111,6 +115,7 @@ def main():
return 1

make_index(args.dist_dir)
return 0


if __name__ == "__main__":
Expand Down

0 comments on commit b286730

Please sign in to comment.