Skip to content

Commit

Permalink
amend test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed Nov 26, 2024
1 parent 06db6c5 commit 4f6b981
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 28 deletions.
6 changes: 5 additions & 1 deletion conda_build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,10 +1141,14 @@ def package_has_file(package_path, file_path, refresh_mode="modified"):
conda_package_handling.api.extract(
package_path, dest_dir=td, components="info"
)
else:
elif package_path.endswith(".tar.bz2"):
conda_package_handling.api.extract(
package_path, dest_dir=td, components=file_path
)
else:
conda_package_handling.api.extract(
package_path, dest_dir=td, components="pkg"
)
resolved_file_path = os.path.join(td, file_path)
if os.path.exists(resolved_file_path):
# TODO :: Remove this text-mode load. Files are binary.
Expand Down
16 changes: 9 additions & 7 deletions tests/cli/test_main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_build_output_build_path(
test_path = os.path.join(
testing_config.croot,
testing_config.host_subdir,
"test_build_output_build_path-1.0-1.tar.bz2",
"test_build_output_build_path-1.0-1.conda",
)
output, error = capfd.readouterr()
assert test_path == output.rstrip(), error
Expand All @@ -126,7 +126,7 @@ def test_build_output_build_path_multiple_recipes(
testing_config.croot, testing_config.host_subdir, pkg
)
test_paths = [
test_path("test_build_output_build_path_multiple_recipes-1.0-1.tar.bz2"),
test_path("test_build_output_build_path_multiple_recipes-1.0-1.conda"),
]

output, error = capfd.readouterr()
Expand All @@ -142,6 +142,7 @@ def test_slash_in_recipe_arg_keeps_build_id(
"--croot",
testing_config.croot,
"--no-anaconda-upload",
"--package-format=1"
]
main_build.execute(args)

Expand Down Expand Up @@ -177,6 +178,7 @@ def test_build_no_build_id(testing_workdir: str, testing_config: Config):
testing_config.croot,
"--no-activate",
"--no-anaconda-upload",
"--package-format=1",
]
main_build.execute(args)

Expand Down Expand Up @@ -420,17 +422,17 @@ def test_relative_path_croot(
]
main_build.execute(args)

assert len(list(croot.glob("**/*.tar.bz2"))) == 1
assert len(list(croot.glob("**/*.conda"))) == 1
assert (
croot / testing_config.subdir / "empty_with_build_script-0.0-0.tar.bz2"
croot / testing_config.subdir / "empty_with_build_script-0.0-0.conda"
).is_file()


def test_relative_path_test_artifact(
conda_build_test_recipe_envvar: str, testing_config: Config
):
# this test builds a package into (cwd)/relative/path and then calls:
# conda-build --test ./relative/path/{platform}/{artifact}.tar.bz2
# conda-build --test ./relative/path/{platform}/{artifact}.conda
empty_sections = Path(metadata_dir, "empty_with_build_script")
croot_rel = Path(".", "relative", "path")
croot_abs = croot_rel.resolve()
Expand All @@ -444,7 +446,7 @@ def test_relative_path_test_artifact(
]
main_build.execute(args)

assert len(list(croot_abs.glob("**/*.tar.bz2"))) == 1
assert len(list(croot_abs.glob("**/*.conda"))) == 1

# run the test stage with relative path
args = [
Expand All @@ -453,7 +455,7 @@ def test_relative_path_test_artifact(
os.path.join(
croot_rel,
testing_config.subdir,
"empty_with_build_script-0.0-0.tar.bz2",
"empty_with_build_script-0.0-0.conda",
),
]
main_build.execute(args)
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_main_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_inspect_prefix_length(testing_workdir, capfd):

# build our own known-length package here
test_base = os.path.expanduser("~/cbtmp")
config = api.Config(croot=test_base, anaconda_upload=False, verbose=True)
config = api.Config(croot=test_base, anaconda_upload=False, verbose=True, conda_pkg_format=1)
recipe_path = os.path.join(metadata_dir, "has_prefix_files")
config.prefix_length = 80
outputs = api.build(recipe_path, config=config, notest=True)
Expand Down
8 changes: 4 additions & 4 deletions tests/cli/test_main_metapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_metapackage(testing_config, testing_workdir):
os.path.join(
testing_config.croot,
testing_config.host_subdir,
"metapackage_test-1.0-0.tar.bz2",
"metapackage_test-1.0-0.conda",
)
)[0]
assert os.path.isfile(test_path)
Expand All @@ -38,7 +38,7 @@ def test_metapackage_build_number(testing_config, testing_workdir):
os.path.join(
testing_config.croot,
testing_config.host_subdir,
"metapackage_test_build_number-1.0-1.tar.bz2",
"metapackage_test_build_number-1.0-1.conda",
)
)[0]
assert os.path.isfile(test_path)
Expand All @@ -60,7 +60,7 @@ def test_metapackage_build_string(testing_config, testing_workdir):
os.path.join(
testing_config.croot,
testing_config.host_subdir,
"metapackage_test_build_string-1.0-frank*.tar.bz2",
"metapackage_test_build_string-1.0-frank*.conda",
)
)[0]
assert os.path.isfile(test_path)
Expand All @@ -86,7 +86,7 @@ def test_metapackage_metadata(testing_config, testing_workdir):
os.path.join(
testing_config.croot,
testing_config.host_subdir,
"metapackage_testing_metadata-1.0-0.tar.bz2",
"metapackage_testing_metadata-1.0-0.conda",
)
)[0]
assert os.path.isfile(test_path)
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/test_main_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_render_output_build_path(
test_path = os.path.join(
testing_config.croot,
testing_metadata.config.host_subdir,
"test_render_output_build_path-1.0-1.tar.bz2",
"test_render_output_build_path-1.0-1.conda",
)
output, error = capfd.readouterr()
assert output.rstrip() == test_path, error
Expand All @@ -87,7 +87,7 @@ def test_render_output_build_path_and_file(
test_path = os.path.join(
testing_config.croot,
testing_metadata.config.host_subdir,
"test_render_output_build_path_and_file-1.0-1.tar.bz2",
"test_render_output_build_path_and_file-1.0-1.conda",
)
output, error = capfd.readouterr()
assert output.rstrip() == test_path, error
Expand All @@ -114,7 +114,7 @@ def test_render_output_build_path_set_python(testing_workdir, testing_metadata,

_hash = metadata.hash_dependencies()
test_path = (
"test_render_output_build_path_set_python-1.0-py{}{}{}_1.tar.bz2".format(
"test_render_output_build_path_set_python-1.0-py{}{}{}_1.conda".format(
version.split(".")[0], version.split(".")[1], _hash
)
)
Expand Down
16 changes: 13 additions & 3 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def test_git_describe_info_on_branch(testing_config):
test_path = os.path.join(
testing_config.croot,
testing_config.host_subdir,
"git_describe_number_branch-1.20.2.0-1_g82c6ba6.tar.bz2",
"git_describe_number_branch-1.20.2.0-1_g82c6ba6.conda",
)
assert test_path == output

Expand Down Expand Up @@ -307,7 +307,8 @@ def test_output_build_path_git_source(testing_config):
test_path = os.path.join(
testing_config.croot,
testing_config.host_subdir,
f"conda-build-test-source-git-jinja2-1.20.2-py{sys.version_info.major}{sys.version_info.minor}{_hash}_0_g262d444.tar.bz2",
"conda-build-test-source-git-jinja2-1.20.2-"
f"py{sys.version_info.major}{sys.version_info.minor}{_hash}_0_g262d444.conda",
)
assert output == test_path

Expand Down Expand Up @@ -576,6 +577,7 @@ def test_requirements_txt_for_run_reqs(testing_config):
reason="Python 3.10+, py_compile terminates once it finds an invalid file",
)
def test_compileall_compiles_all_good_files(testing_config):
testing_config.conda_pkg_format = 1
output = api.build(
os.path.join(metadata_dir, "_compile-test"), config=testing_config
)[0]
Expand Down Expand Up @@ -625,7 +627,7 @@ def test_numpy_setup_py_data(testing_config):
_hash = metadata.hash_dependencies()
assert (
os.path.basename(api.get_output_file_paths(metadata)[0])
== f"load_setup_py_test-0.1.0-np116py{sys.version_info.major}{sys.version_info.minor}{_hash}_0.tar.bz2"
== f"load_setup_py_test-0.1.0-np116py{sys.version_info.major}{sys.version_info.minor}{_hash}_0.conda"
)


Expand Down Expand Up @@ -879,6 +881,7 @@ def test_about_json_content(testing_metadata):
"name,field", [("license", "license_file"), ("prelink_message", "prelink_message")]
)
def test_about_license_file_and_prelink_message(testing_config, name, field):
testing_config.conda_pkg_format = 1
base_dir = os.path.join(metadata_dir, f"_about_{field}/recipes")

recipe = os.path.join(base_dir, "single")
Expand Down Expand Up @@ -945,6 +948,7 @@ def test_noarch_python_1(testing_config):

@pytest.mark.sanity
def test_skip_compile_pyc(testing_config):
testing_config.conda_pkg_format = 1
outputs = api.build(
os.path.join(metadata_dir, "skip_compile_pyc"), config=testing_config
)
Expand All @@ -969,6 +973,7 @@ def test_skip_compile_pyc(testing_config):


def test_detect_binary_files_with_prefix(testing_config):
testing_config.conda_pkg_format = 1
outputs = api.build(
os.path.join(metadata_dir, "_detect_binary_files_with_prefix"),
config=testing_config,
Expand All @@ -991,6 +996,7 @@ def test_detect_binary_files_with_prefix(testing_config):


def test_skip_detect_binary_files_with_prefix(testing_config):
testing_config.conda_pkg_format = 1
recipe = os.path.join(metadata_dir, "_skip_detect_binary_files_with_prefix")
outputs = api.build(recipe, config=testing_config)
matches = []
Expand All @@ -1014,6 +1020,7 @@ def test_skip_detect_binary_files_with_prefix(testing_config):


def test_fix_permissions(testing_config):
testing_config.conda_pkg_format = 1
recipe = os.path.join(metadata_dir, "fix_permissions")
outputs = api.build(recipe, config=testing_config)
with tarfile.open(outputs[0]) as tf:
Expand Down Expand Up @@ -1050,6 +1057,7 @@ def test_output_folder_moves_file(testing_metadata, testing_workdir):
"pkg_dirs to conda_pkgs_dir.",
)
def test_info_files_json(testing_config):
testing_config.conda_pkg_format = 1
outputs = api.build(
os.path.join(metadata_dir, "_ignore_some_prefix_files"), config=testing_config
)
Expand Down Expand Up @@ -1611,6 +1619,7 @@ def test_source_cache_build(testing_workdir):

@pytest.mark.slow
def test_copy_test_source_files(testing_config):
testing_config.conda_pkg_format = 1
recipe = os.path.join(metadata_dir, "_test_test_source_files")
filenames = set()
for copy in (False, True):
Expand Down Expand Up @@ -1959,6 +1968,7 @@ def test_activated_prefixes_in_actual_path(testing_metadata):
"""
file = "env-path-dump"
testing_metadata.config.activate = True
testing_metadata.config.conda_pkg_format = 1
meta = testing_metadata.meta
meta["requirements"]["host"] = []
meta["build"]["script"] = [
Expand Down
6 changes: 3 additions & 3 deletions tests/test_api_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_get_output_file_paths(testing_workdir, testing_metadata):
assert build_path == os.path.join(
testing_metadata.config.croot,
testing_metadata.config.host_subdir,
"test_get_output_file_paths-1.0-1.tar.bz2",
"test_get_output_file_paths-1.0-1.conda",
)


Expand All @@ -80,7 +80,7 @@ def test_get_output_file_paths_metadata_object(testing_metadata):
assert build_path == os.path.join(
testing_metadata.config.croot,
testing_metadata.config.host_subdir,
"test_get_output_file_paths_metadata_object-1.0-1.tar.bz2",
"test_get_output_file_paths_metadata_object-1.0-1.conda",
)


Expand All @@ -104,7 +104,7 @@ def test_get_output_file_paths_jinja2(testing_config):
assert build_path == os.path.join(
testing_config.croot,
testing_config.host_subdir,
f"conda-build-test-source-git-jinja2-1.20.2-py{python}{_hash}_0_g262d444.tar.bz2",
f"conda-build-test-source-git-jinja2-1.20.2-py{python}{_hash}_0_g262d444.conda",
)


Expand Down
12 changes: 6 additions & 6 deletions tests/test_subpackages.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def test_loops_do_not_remove_earlier_packages(testing_config):
api.build(recipe, config=testing_config)
assert len(output_files) == len(
glob(
os.path.join(testing_config.croot, testing_config.host_subdir, "*.tar.bz2")
os.path.join(testing_config.croot, testing_config.host_subdir, "*.conda")
)
)

Expand All @@ -484,18 +484,18 @@ def test_build_string_does_not_incorrectly_add_hash(testing_config):
recipe = os.path.join(subpackage_dir, "_build_string_with_variant")
output_files = api.get_output_file_paths(recipe, config=testing_config)
assert len(output_files) == 4
assert any("clang_variant-1.0-cling.tar.bz2" in f for f in output_files)
assert any("clang_variant-1.0-default.tar.bz2" in f for f in output_files)
assert any("clang_variant-1.0-cling.conda" in f for f in output_files)
assert any("clang_variant-1.0-default.conda" in f for f in output_files)


def test_multi_outputs_without_package_version(testing_config):
# outputs without package/version is allowed
recipe = os.path.join(subpackage_dir, "_multi_outputs_without_package_version")
outputs = api.build(recipe, config=testing_config)
assert len(outputs) == 3
assert outputs[0].endswith("a-1-0.tar.bz2")
assert outputs[1].endswith("b-2-0.tar.bz2")
assert outputs[2].endswith("c-3-0.tar.bz2")
assert outputs[0].endswith("a-1-0.conda")
assert outputs[1].endswith("b-2-0.conda")
assert outputs[2].endswith("c-3-0.conda")


def test_empty_outputs_requires_package_version(testing_config):
Expand Down

0 comments on commit 4f6b981

Please sign in to comment.