Skip to content

Commit

Permalink
test: Adapt libmambapy tests accordingly
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
  • Loading branch information
jjerphan committed Oct 14, 2024
1 parent 05f490f commit 1f4a1c9
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 102 deletions.
59 changes: 59 additions & 0 deletions libmambapy/src/libmambapy/solver/libsolv.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,61 @@
import warnings

# This file exists on its own rather than in `__init__.py` to make `import libmambapy.solver.libsolv` work.
from libmambapy.bindings.solver.libsolv import * # noqa: F403

from libmambapy.bindings.solver import (
Priorities as _Priorities,
RepodataParser as _RepodataParser,
PipAsPythonDependency as _PipAsPythonDependency,
PackageTypes as _PackageTypes,
VerifyPackages as _VerifyPackages,
RepodataOrigin as _RepodataOrigin,
)

_WARN_TEMPLATE_MSG = (
"`libmambapy.bindings.solver.libsolv.{name}` has been moved "
"to `libmambapy.bindings.solver.{name}` in 2.0. "
"This import path will be removed in 2.2"
)


class Priorities(_Priorities):
warnings.warn(
_WARN_TEMPLATE_MSG.format(name="Priorities"),
category=DeprecationWarning,
)


class RepodataParser(_RepodataParser):
warnings.warn(
_WARN_TEMPLATE_MSG.format(name="RepodataParser"),
category=DeprecationWarning,
)


class PipAsPythonDependency(_PipAsPythonDependency):
warnings.warn(
_WARN_TEMPLATE_MSG.format(name="PipAsPythonDependency"),
category=DeprecationWarning,
)


class PackageTypes(_PackageTypes):
warnings.warn(
_WARN_TEMPLATE_MSG.format(name="PackageTypes"),
category=DeprecationWarning,
)


class VerifyPackages(_VerifyPackages):
warnings.warn(
_WARN_TEMPLATE_MSG.format(name="VerifyPackages"),
category=DeprecationWarning,
)


class RepodataOrigin(_RepodataOrigin):
warnings.warn(
_WARN_TEMPLATE_MSG.format(name="RepodataOrigin"),
category=DeprecationWarning,
)
100 changes: 100 additions & 0 deletions libmambapy/tests/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,103 @@ def test_CompressedProblemsGraph_NamedList():
# Clear
named_list.clear()
assert len(named_list) == 0


def test_RepodataParser():
assert libmambapy.solver.RepodataParser.Mamba.name == "Mamba"
assert libmambapy.solver.RepodataParser.Libsolv.name == "Libsolv"

assert libmambapy.solver.RepodataParser("Libsolv") == libmambapy.solver.RepodataParser.Libsolv

with pytest.raises(KeyError):
libmambapy.solver.RepodataParser("NoParser")


def test_PipASPythonDependency():
assert libmambapy.solver.PipAsPythonDependency.No.name == "No"
assert libmambapy.solver.PipAsPythonDependency.Yes.name == "Yes"

assert (
libmambapy.solver.PipAsPythonDependency(True) == libmambapy.solver.PipAsPythonDependency.Yes
)


def test_PackageTypes():
assert libmambapy.solver.PackageTypes.CondaOnly.name == "CondaOnly"
assert libmambapy.solver.PackageTypes.TarBz2Only.name == "TarBz2Only"
assert libmambapy.solver.PackageTypes.CondaAndTarBz2.name == "CondaAndTarBz2"
assert libmambapy.solver.PackageTypes.CondaOrElseTarBz2.name == "CondaOrElseTarBz2"

assert libmambapy.solver.PackageTypes("TarBz2Only") == libmambapy.solver.PackageTypes.TarBz2Only

with pytest.raises(KeyError):
libmambapy.solver.RepodataParser("tarbz2-only")


def test_VerifyPackages():
assert libmambapy.solver.VerifyPackages.No.name == "No"
assert libmambapy.solver.VerifyPackages.Yes.name == "Yes"

assert libmambapy.solver.VerifyPackages(True) == libmambapy.solver.VerifyPackages.Yes


def test_Platform():
assert libmambapy.solver.LogLevel.Debug.name == "Debug"
assert libmambapy.solver.LogLevel.Warning.name == "Warning"
assert libmambapy.solver.LogLevel.Error.name == "Error"
assert libmambapy.solver.LogLevel.Fatal.name == "Fatal"

assert libmambapy.solver.LogLevel("Error") == libmambapy.solver.LogLevel.Error

with pytest.raises(KeyError):
# No parsing, explicit name
libmambapy.solver.LogLevel("Unicorn")


def test_Priorities():
p = libmambapy.solver.Priorities(priority=-1, subpriority=-2)

assert p.priority == -1
assert p.subpriority == -2

# Setters
p.priority = 33
p.subpriority = 0
assert p.priority == 33
assert p.subpriority == 0

# Operators
assert p == p
assert p != libmambapy.solver.Priorities()

# Copy
other = copy.deepcopy(p)
assert other is not p
assert other == p


def test_RepodataOrigin():
orig = libmambapy.solver.RepodataOrigin(
url="https://conda.anaconda.org/conda-forge", mod="the-mod", etag="the-etag"
)

assert orig.url == "https://conda.anaconda.org/conda-forge"
assert orig.etag == "the-etag"
assert orig.mod == "the-mod"

# Setters
orig.url = "https://repo.mamba.pm"
orig.etag = "other-etag"
orig.mod = "other-mod"
assert orig.url == "https://repo.mamba.pm"
assert orig.etag == "other-etag"
assert orig.mod == "other-mod"

# Operators
assert orig == orig
assert orig != libmambapy.solver.RepodataOrigin()

# Copy
other = copy.deepcopy(orig)
assert other is not orig
assert other == orig
105 changes: 3 additions & 102 deletions libmambapy/tests/test_solver_libsolv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
import json
import itertools

Expand All @@ -9,115 +8,17 @@


def test_import_submodule():
import libmambapy.solver.libsolv as solv
import libmambapy.solver.libsolv as libsolv

# Dummy execution
_p = solv.Priorities
_p = libsolv.Solver


def test_import_recursive():
import libmambapy as mamba

# Dummy execution
_p = mamba.solver.libsolv.Priorities


def test_RepodataParser():
assert libsolv.RepodataParser.Mamba.name == "Mamba"
assert libsolv.RepodataParser.Libsolv.name == "Libsolv"

assert libsolv.RepodataParser("Libsolv") == libsolv.RepodataParser.Libsolv

with pytest.raises(KeyError):
libsolv.RepodataParser("NoParser")


def test_PipASPythonDependency():
assert libsolv.PipAsPythonDependency.No.name == "No"
assert libsolv.PipAsPythonDependency.Yes.name == "Yes"

assert libsolv.PipAsPythonDependency(True) == libsolv.PipAsPythonDependency.Yes


def test_PackageTypes():
assert libsolv.PackageTypes.CondaOnly.name == "CondaOnly"
assert libsolv.PackageTypes.TarBz2Only.name == "TarBz2Only"
assert libsolv.PackageTypes.CondaAndTarBz2.name == "CondaAndTarBz2"
assert libsolv.PackageTypes.CondaOrElseTarBz2.name == "CondaOrElseTarBz2"

assert libsolv.PackageTypes("TarBz2Only") == libsolv.PackageTypes.TarBz2Only

with pytest.raises(KeyError):
libsolv.RepodataParser("tarbz2-only")


def test_VerifyPackages():
assert libsolv.VerifyPackages.No.name == "No"
assert libsolv.VerifyPackages.Yes.name == "Yes"

assert libsolv.VerifyPackages(True) == libsolv.VerifyPackages.Yes


def test_Platform():
assert libsolv.LogLevel.Debug.name == "Debug"
assert libsolv.LogLevel.Warning.name == "Warning"
assert libsolv.LogLevel.Error.name == "Error"
assert libsolv.LogLevel.Fatal.name == "Fatal"

assert libsolv.LogLevel("Error") == libsolv.LogLevel.Error

with pytest.raises(KeyError):
# No parsing, explicit name
libsolv.LogLevel("Unicorn")


def test_Priorities():
p = libsolv.Priorities(priority=-1, subpriority=-2)

assert p.priority == -1
assert p.subpriority == -2

# Setters
p.priority = 33
p.subpriority = 0
assert p.priority == 33
assert p.subpriority == 0

# Operators
assert p == p
assert p != libsolv.Priorities()

# Copy
other = copy.deepcopy(p)
assert other is not p
assert other == p


def test_RepodataOrigin():
orig = libsolv.RepodataOrigin(
url="https://conda.anaconda.org/conda-forge", mod="the-mod", etag="the-etag"
)

assert orig.url == "https://conda.anaconda.org/conda-forge"
assert orig.etag == "the-etag"
assert orig.mod == "the-mod"

# Setters
orig.url = "https://repo.mamba.pm"
orig.etag = "other-etag"
orig.mod = "other-mod"
assert orig.url == "https://repo.mamba.pm"
assert orig.etag == "other-etag"
assert orig.mod == "other-mod"

# Operators
assert orig == orig
assert orig != libsolv.RepodataOrigin()

# Copy
other = copy.deepcopy(orig)
assert other is not orig
assert other == orig
_p = mamba.solver.libsolv.Solver


def test_Database_logger():
Expand Down

0 comments on commit 1f4a1c9

Please sign in to comment.