Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard committed May 23, 2024
1 parent f4f622e commit aadfd01
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
5 changes: 3 additions & 2 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2833,9 +2833,10 @@ def warn_on_use_of_SRC_DIR(metadata):
"3.16.0",
"24.7.0",
addendum=(
"Test built packages instead, not recipes. E.g., "
"`conda build --test package.conda` instead of `conda build --test recipe/`."
"Test built packages instead, not recipes "
"(e.g., `conda build --test package` instead of `conda build --test recipe/`)."
),
deprecation_type=FutureWarning, # we need to warn users, not developers
)
def _construct_metadata_for_test_from_recipe(recipe_dir, config):
config.need_cleanup = False
Expand Down
13 changes: 11 additions & 2 deletions conda_build/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __call__(
*,
addendum: str | None = None,
stack: int = 0,
deprecation_type: type[Warning] = DeprecationWarning,
) -> Callable[[Callable[P, T]], Callable[P, T]]:
"""Deprecation decorator for functions, methods, & classes.
Expand All @@ -102,6 +103,7 @@ def deprecated_decorator(func: Callable[P, T]) -> Callable[P, T]:
remove_in=remove_in,
prefix=f"{func.__module__}.{func.__qualname__}",
addendum=addendum,
deprecation_type=deprecation_type,
)

# alert developer that it's time to remove something
Expand All @@ -128,6 +130,7 @@ def argument(
rename: str | None = None,
addendum: str | None = None,
stack: int = 0,
deprecation_type: type[Warning] = DeprecationWarning,
) -> Callable[[Callable[P, T]], Callable[P, T]]:
"""Deprecation decorator for keyword arguments.
Expand All @@ -149,6 +152,7 @@ def deprecated_decorator(func: Callable[P, T]) -> Callable[P, T]:
addendum=(
f"Use '{rename}' instead." if rename and not addendum else addendum
),
deprecation_type=deprecation_type,
)

# alert developer that it's time to remove something
Expand Down Expand Up @@ -181,6 +185,7 @@ def action(
*,
addendum: str | None = None,
stack: int = 0,
deprecation_type: type[Warning] = FutureWarning,
) -> ActionType:
"""Wraps any argparse.Action to issue a deprecation warning."""

Expand All @@ -203,7 +208,7 @@ def __init__(inner_self: Self, *args: Any, **kwargs: Any) -> None:
else f"`{inner_self.dest}`"
),
addendum=addendum,
deprecation_type=FutureWarning,
deprecation_type=deprecation_type,
)

# alert developer that it's time to remove something
Expand Down Expand Up @@ -263,6 +268,7 @@ def constant(
*,
addendum: str | None = None,
stack: int = 0,
deprecation_type: type[Warning] = DeprecationWarning,
) -> None:
"""Deprecation function for module constant/global.
Expand All @@ -281,6 +287,7 @@ def constant(
remove_in=remove_in,
prefix=f"{fullname}.{constant}",
addendum=addendum,
deprecation_type=deprecation_type,
)

# alert developer that it's time to remove something
Expand Down Expand Up @@ -310,6 +317,7 @@ def topic(
topic: str,
addendum: str | None = None,
stack: int = 0,
deprecation_type: type[Warning] = DeprecationWarning,
) -> None:
"""Deprecation function for a topic.
Expand All @@ -325,6 +333,7 @@ def topic(
remove_in=remove_in,
prefix=topic,
addendum=addendum,
deprecation_type=deprecation_type,
)

# alert developer that it's time to remove something
Expand Down Expand Up @@ -379,7 +388,7 @@ def _generate_message(
prefix: str,
addendum: str | None,
*,
deprecation_type: type[Warning] = DeprecationWarning,
deprecation_type: type[Warning],
) -> tuple[type[Warning] | None, str]:
"""Generate the standardized deprecation message and determine whether the
deprecation is pending, active, or past.
Expand Down
19 changes: 19 additions & 0 deletions news/3192-deprecate-testing-recipes
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* <news item>

### Deprecations

* Mark `conda_build.build._construct_metadata_for_test_from_recipe` as deprecated. Test built packages instead, not recipes (e.g., `conda build --test package` instead of `conda build --test recipe/`). (#3192)

### Docs

* <news item>

### Other

* <news item>
14 changes: 13 additions & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
import sys
from contextlib import nullcontext
from pathlib import Path
from typing import TYPE_CHECKING

import pytest

from conda_build import api, build

from .utils import get_noarch_python_meta, metadata_dir
from .utils import get_noarch_python_meta, metadata_dir, metadata_path

if TYPE_CHECKING:
from conda_build.config import Config


def test_build_preserves_PATH(testing_config):
Expand Down Expand Up @@ -324,3 +328,11 @@ def test_guess_interpreter(
):
with pytest.raises(error) if error else nullcontext():
assert build.guess_interpreter(script) == interpreter


def test_construct_metadata_for_test_from_recipe(testing_config: Config) -> None:
with pytest.warns(FutureWarning):
build._construct_metadata_for_test_from_recipe(
str(metadata_path / "test_source_files"),
testing_config,
)

0 comments on commit aadfd01

Please sign in to comment.