Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Feb 26, 2025
1 parent 6c1ce84 commit dba1439
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pixi_to_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ def create_pypi_package_entry(
}


def _list_of_str_dependencies_to_dict(requires_dist: list[str]) -> dict[str, str]:
"""Convert package requirements from 'requires_dist' format to conda-lock format."""
def _list_of_str_dependencies_to_dict(dependencies_list: list[str]) -> dict[str, str]:
"""Convert package requirements from 'dependencies' format to conda-lock format."""
dependencies = {}
for requirement in requires_dist:
for requirement in dependencies_list:
# Split by first occurrence of any version specifier
match = re.match(r"([^<>=!~]+)(.+)?", requirement)
if match:
Expand Down
50 changes: 50 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from pixi_to_conda_lock import (
_get_output_filename,
_list_of_str_dependencies_to_dict,
_parse_args,
_prepare_output_directory,
convert_env_to_conda_lock,
Expand Down Expand Up @@ -218,3 +219,52 @@ def test_create_pypi_package_entry(lock_file_pypi: LockFile) -> None:
assert "url" in result
assert "hash" in result
assert "sha256" in result["hash"]


def test_list_of_str_dependencies_to_dict() -> None:
"""Test the _list_of_str_dependencies_to_dict function with various inputs."""
# Test with the provided example
package_info = [
"decorator>=5.1.0",
"requests>=2.24.0",
"importlib-metadata>=4.11.4",
"python-dotenv>=1.0.1",
"qiskit",
"qiskit>=1.0.0 ; extra == 'test'",
"pytest ; extra == 'test'",
"requests-mock>=1.8.0 ; extra == 'test'",
"pytest-cov==2.10.1 ; extra == 'test'",
]

expected = {
"decorator": ">=5.1.0",
"requests": ">=2.24.0",
"importlib-metadata": ">=4.11.4",
"python-dotenv": ">=1.0.1",
"qiskit": ">=1.0.0 ; extra == 'test'",
"pytest ; extra": "== 'test'",
"requests-mock": ">=1.8.0 ; extra == 'test'",
"pytest-cov": "==2.10.1 ; extra == 'test'",
}

result = _list_of_str_dependencies_to_dict(package_info)
assert result == expected

# Test with empty requires_dist
assert _list_of_str_dependencies_to_dict([]) == {}

# Test with more complex version specifiers
complex_package_info = [
"numpy>=1.19.3,<2.0.0",
"pandas>1.0.0,!=1.1.0,<2",
"scipy~=1.7.0",
]

expected_complex = {
"numpy": ">=1.19.3,<2.0.0",
"pandas": ">1.0.0,!=1.1.0,<2",
"scipy": "~=1.7.0",
}

result_complex = _list_of_str_dependencies_to_dict(complex_package_info)
assert result_complex == expected_complex

0 comments on commit dba1439

Please sign in to comment.