:py:mod:`testing` ================= .. py:module:: conda.testing .. toctree:: :hidden: :titlesonly: :maxdepth: 3 cases/index.rst fixtures/index.rst gateways/index.rst helpers/index.rst integration/index.rst notices/index.rst solver_helpers/index.rst Classes ------- .. autoapisummary:: conda.testing.EntityEncoder conda.testing.PackageCacheData conda.testing.PackageRecord conda.testing.CondaCLIFixture conda.testing.PathFactoryFixture conda.testing.TmpEnvFixture conda.testing.TmpChannelFixture Functions --------- .. autoapisummary:: conda.testing.reset_context conda.testing.main_subshell conda.testing.path_to_url conda.testing.conda_ensure_sys_python_is_base_env_python conda.testing.conda_move_to_front_of_PATH conda.testing.conda_cli conda.testing.path_factory conda.testing.tmp_env conda.testing.tmp_channel conda.testing.context_aware_monkeypatch conda.testing.tmp_pkgs_dir Attributes ---------- .. autoapisummary:: conda.testing.PACKAGE_CACHE_MAGIC_FILE conda.testing.context conda.testing.on_win conda.testing.deprecated .. py:class:: EntityEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None) Bases: :py:obj:`json.JSONEncoder` Extensible JSON encoder for Python data structures. Supports the following objects and types by default: +-------------------+---------------+ | Python | JSON | +===================+===============+ | dict | object | +-------------------+---------------+ | list, tuple | array | +-------------------+---------------+ | str | string | +-------------------+---------------+ | int, float | number | +-------------------+---------------+ | True | true | +-------------------+---------------+ | False | false | +-------------------+---------------+ | None | null | +-------------------+---------------+ To extend this to recognize other objects, subclass and implement a ``.default()`` method with another method that returns a serializable object for ``o`` if possible, otherwise it should call the superclass implementation (to raise ``TypeError``). .. py:method:: default(obj) Implement this method in a subclass such that it returns a serializable object for ``o``, or calls the base implementation (to raise a ``TypeError``). For example, to support arbitrary iterators, you could implement default like this:: def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) .. py:data:: PACKAGE_CACHE_MAGIC_FILE :value: 'urls.txt' .. py:data:: context .. py:function:: reset_context(search_path=SEARCH_PATH, argparse_args=None) .. py:function:: main_subshell(*args, post_parse_hook=None, **kwargs) Entrypoint for the "subshell" invocation of CLI interface. E.g. `conda create`. .. py:data:: on_win .. py:function:: path_to_url(path) .. py:class:: PackageCacheData(pkgs_dir) .. py:property:: _package_cache_records .. py:property:: is_writable .. py:attribute:: _cache_ :type: dict[str, PackageCacheData] .. py:method:: insert(package_cache_record) .. py:method:: load() .. py:method:: reload() .. py:method:: get(package_ref, default=NULL) .. py:method:: remove(package_ref, default=NULL) .. py:method:: query(package_ref_or_match_spec) .. py:method:: iter_records() .. py:method:: query_all(package_ref_or_match_spec, pkgs_dirs=None) :classmethod: .. py:method:: first_writable(pkgs_dirs=None) :classmethod: .. py:method:: writable_caches(pkgs_dirs=None) :classmethod: .. py:method:: read_only_caches(pkgs_dirs=None) :classmethod: .. py:method:: all_caches_writable_first(pkgs_dirs=None) :classmethod: .. py:method:: get_all_extracted_entries() :classmethod: .. py:method:: get_entry_to_link(package_ref) :classmethod: .. py:method:: tarball_file_in_cache(tarball_path, md5sum=None, exclude_caches=()) :classmethod: .. py:method:: clear() :classmethod: .. py:method:: tarball_file_in_this_cache(tarball_path, md5sum=None) .. py:method:: _check_writable() .. py:method:: _clean_tarball_path_and_get_md5sum(tarball_path, md5sum=None) :staticmethod: .. py:method:: _scan_for_dist_no_channel(dist_str) .. py:method:: itervalues() .. py:method:: values() .. py:method:: __repr__() Return repr(self). .. py:method:: _make_single_record(package_filename) .. py:method:: _dedupe_pkgs_dir_contents(pkgs_dir_contents) :staticmethod: .. py:data:: deprecated .. py:exception:: CondaExitZero(message, caused_by=None, **kwargs) Bases: :py:obj:`CondaError` Common base class for all non-exit exceptions. .. py:attribute:: return_code :value: 0 .. py:class:: PackageRecord(*args, **kwargs) Bases: :py:obj:`conda.auxlib.entity.DictSafeMixin`, :py:obj:`conda.auxlib.entity.Entity` .. py:property:: schannel .. py:property:: _pkey .. py:property:: is_unmanageable .. py:property:: combined_depends .. py:property:: namekey .. py:attribute:: name .. py:attribute:: version .. py:attribute:: build .. py:attribute:: build_number .. py:attribute:: channel .. py:attribute:: subdir .. py:attribute:: fn .. py:attribute:: md5 .. py:attribute:: legacy_bz2_md5 .. py:attribute:: legacy_bz2_size .. py:attribute:: url .. py:attribute:: sha256 .. py:attribute:: arch .. py:attribute:: platform .. py:attribute:: depends .. py:attribute:: constrains .. py:attribute:: track_features .. py:attribute:: features .. py:attribute:: noarch .. py:attribute:: preferred_env .. py:attribute:: license .. py:attribute:: license_family .. py:attribute:: package_type .. py:attribute:: timestamp .. py:attribute:: date .. py:attribute:: size .. py:attribute:: metadata :type: set[str] .. py:method:: __hash__() Return hash(self). .. py:method:: __eq__(other) Return self==value. .. py:method:: dist_str() .. py:method:: dist_fields_dump() .. py:method:: __str__() Return str(self). .. py:method:: to_match_spec() .. py:method:: to_simple_match_spec() .. py:method:: record_id() .. py:function:: conda_ensure_sys_python_is_base_env_python() .. py:function:: conda_move_to_front_of_PATH() .. py:class:: CondaCLIFixture .. py:attribute:: capsys :type: pytest.CaptureFixture .. py:method:: __call__(*argv: str | os.PathLike | pathlib.Path, raises: type[Exception] | tuple[type[Exception], Ellipsis]) -> tuple[str, str, pytest.ExceptionInfo] __call__(*argv: str | os.PathLike | pathlib.Path) -> tuple[str, str, int] Test conda CLI. Mimic what is done in `conda.cli.main.main`. `conda ...` == `conda_cli(...)` :param argv: Arguments to parse. :param raises: Expected exception to intercept. If provided, the raised exception will be returned instead of exit code (see pytest.raises and pytest.ExceptionInfo). :return: Command results (stdout, stderr, exit code or pytest.ExceptionInfo). .. py:function:: conda_cli(capsys: pytest.CaptureFixture) -> CondaCLIFixture Fixture returning CondaCLIFixture instance. .. py:class:: PathFactoryFixture .. py:attribute:: tmp_path :type: pathlib.Path .. py:method:: __call__(name: str | None = None, prefix: str | None = None, suffix: str | None = None) -> pathlib.Path Unique, non-existent path factory. Extends pytest's `tmp_path` fixture with a new unique, non-existent path for usage in cases where we need a temporary path that doesn't exist yet. :param name: Path name to append to `tmp_path` :param prefix: Prefix to prepend to unique name generated :param suffix: Suffix to append to unique name generated :return: A new unique path .. py:function:: path_factory(tmp_path: pathlib.Path) -> PathFactoryFixture Fixture returning PathFactoryFixture instance. .. py:class:: TmpEnvFixture .. py:attribute:: path_factory :type: PathFactoryFixture .. py:attribute:: conda_cli :type: CondaCLIFixture .. py:method:: __call__(*packages: str, prefix: str | os.PathLike | None = None) -> Iterator[pathlib.Path] Generate a conda environment with the provided packages. :param packages: The packages to install into environment :param prefix: The prefix at which to install the conda environment :return: The conda environment's prefix .. py:function:: tmp_env(path_factory: PathFactoryFixture, conda_cli: CondaCLIFixture) -> TmpEnvFixture Fixture returning TmpEnvFixture instance. .. py:class:: TmpChannelFixture .. py:attribute:: path_factory :type: PathFactoryFixture .. py:attribute:: conda_cli :type: CondaCLIFixture .. py:method:: __call__(*packages: str) -> Iterator[tuple[pathlib.Path, str]] .. py:function:: tmp_channel(path_factory: PathFactoryFixture, conda_cli: CondaCLIFixture) -> TmpChannelFixture Fixture returning TmpChannelFixture instance. .. py:function:: context_aware_monkeypatch(monkeypatch: pytest.MonkeyPatch) -> pytest.MonkeyPatch A monkeypatch fixture that resets context after each test .. py:function:: tmp_pkgs_dir(path_factory: PathFactoryFixture, mocker: pytest_mock.MockerFixture) -> pathlib.Path