def test_build_dependencies(n_jobs, monkeypatch): build_list = [] class MockPackage(buildall.Package): def build(self, outputdir: Path, args) -> None: build_list.append(self.name) monkeypatch.setattr(buildall, "Package", MockPackage) pkg_map = buildall.generate_dependency_graph(PACKAGES_DIR, "lxml") Args = namedtuple("args", ["n_jobs"]) buildall.build_from_graph(pkg_map, Path("."), Args(n_jobs=n_jobs)) assert set(build_list) == { "distlib", "soupsieve", "beautifulsoup4", "micropip", "webencodings", "html5lib", "cssselect", "lxml", "libxslt", "libxml", "zlib", "libiconv", "six", } assert build_list.index("distlib") < build_list.index("micropip") assert build_list.index("soupsieve") < build_list.index("beautifulsoup4")
def test_build_dependencies(n_jobs, monkeypatch): build_list = [] class MockPackage(buildall.Package): def build(self, outputdir: Path, args: Any) -> None: build_list.append(self.name) monkeypatch.setattr(buildall, "Package", MockPackage) pkg_map = buildall.generate_dependency_graph(PACKAGES_DIR, {"pkg_1", "pkg_2"}) buildall.build_from_graph( pkg_map, Path("."), argparse.Namespace(n_jobs=n_jobs, force_rebuild=True)) assert set(build_list) == { "pkg_1", "pkg_1_1", "pkg_2", "pkg_3", "pkg_3_1", } assert build_list.index("pkg_1_1") < build_list.index("pkg_1") assert build_list.index("pkg_3") < build_list.index("pkg_1") assert build_list.index("pkg_3_1") < build_list.index("pkg_3")
def test_build_error(n_jobs, monkeypatch): """Try building all the dependency graph, without the actual build operations""" class MockPackage(buildall.Package): def build(self, outputdir: Path, args) -> None: raise ValueError("Failed build") monkeypatch.setattr(buildall, "Package", MockPackage) pkg_map = buildall.generate_dependency_graph(PACKAGES_DIR, "lxml") with pytest.raises(ValueError, match="Failed build"): Args = namedtuple("args", ["n_jobs"]) buildall.build_from_graph(pkg_map, Path("."), Args(n_jobs=n_jobs))
def test_build_error(n_jobs, monkeypatch): """Try building all the dependency graph, without the actual build operations""" class MockPackage(buildall.Package): def build(self, outputdir: Path, args: Any) -> None: raise ValueError("Failed build") monkeypatch.setattr(buildall, "Package", MockPackage) pkg_map = buildall.generate_dependency_graph(PACKAGES_DIR, {"pkg_1"}) with pytest.raises(ValueError, match="Failed build"): buildall.build_from_graph( pkg_map, Path("."), argparse.Namespace(n_jobs=n_jobs, force_rebuild=True))
def test_build_all_dependencies(n_jobs, monkeypatch): """Try building all the dependency graph, without the actual build operations""" class MockPackage(buildall.Package): n_builds = 0 def build(self, outputdir: Path, args) -> None: sleep(0.005) self.n_builds += 1 # check that each build is only run once assert self.n_builds == 1 monkeypatch.setattr(buildall, "Package", MockPackage) pkg_map = buildall.generate_dependency_graph(PACKAGES_DIR, package_list=None) Args = namedtuple("args", ["n_jobs"]) buildall.build_from_graph(pkg_map, Path("."), Args(n_jobs=n_jobs))
def test_build_all_dependencies(n_jobs, monkeypatch): """Try building all the dependency graph, without the actual build operations""" class MockPackage(buildall.Package): n_builds = 0 def build(self, outputdir: Path, args: Any) -> None: sleep(0.005) self.n_builds += 1 # check that each build is only run once assert self.n_builds == 1 monkeypatch.setattr(buildall, "Package", MockPackage) pkg_map = buildall.generate_dependency_graph(PACKAGES_DIR, packages={"*"}) buildall.build_from_graph( pkg_map, Path("."), argparse.Namespace(n_jobs=n_jobs, force_rebuild=False))