|
19 | 19 | _find_pre_built, |
20 | 20 | _matches_hatch_pattern, |
21 | 21 | _module_name_from_project, |
| 22 | + _normalize_name, |
| 23 | + _resolve_module_from_hatch, |
22 | 24 | _sdist_expected_files, |
23 | 25 | check_absent, |
24 | 26 | check_dist, |
@@ -678,6 +680,81 @@ def test_no_change(self): |
678 | 680 | assert _module_name_from_project("mypkg") == "mypkg" |
679 | 681 |
|
680 | 682 |
|
| 683 | +class TestNormalizeName: |
| 684 | + def test_underscores(self): |
| 685 | + assert _normalize_name("jupyter_fs") == "jupyterfs" |
| 686 | + |
| 687 | + def test_hyphens(self): |
| 688 | + assert _normalize_name("jupyter-fs") == "jupyterfs" |
| 689 | + |
| 690 | + def test_periods(self): |
| 691 | + assert _normalize_name("jupyter.fs") == "jupyterfs" |
| 692 | + |
| 693 | + def test_mixed(self): |
| 694 | + assert _normalize_name("my_pkg-name.ext") == "mypkgnameext" |
| 695 | + |
| 696 | + def test_no_separators(self): |
| 697 | + assert _normalize_name("mypkg") == "mypkg" |
| 698 | + |
| 699 | + def test_case_insensitive(self): |
| 700 | + assert _normalize_name("MyPkg") == "mypkg" |
| 701 | + |
| 702 | + |
| 703 | +class TestResolveModuleFromHatch: |
| 704 | + def test_wheel_packages_match(self): |
| 705 | + hatch = {"targets": {"wheel": {"packages": ["jupyterfs"]}}} |
| 706 | + assert _resolve_module_from_hatch("jupyter_fs", hatch) == "jupyterfs" |
| 707 | + |
| 708 | + def test_sdist_packages_match(self): |
| 709 | + hatch = {"targets": {"sdist": {"packages": ["jupyterfs", "js"]}}} |
| 710 | + assert _resolve_module_from_hatch("jupyter_fs", hatch) == "jupyterfs" |
| 711 | + |
| 712 | + def test_no_match_returns_original(self): |
| 713 | + hatch = {"targets": {"wheel": {"packages": ["otherpkg"]}}} |
| 714 | + assert _resolve_module_from_hatch("jupyter_fs", hatch) == "jupyter_fs" |
| 715 | + |
| 716 | + def test_empty_hatch_config(self): |
| 717 | + assert _resolve_module_from_hatch("jupyter_fs", {}) == "jupyter_fs" |
| 718 | + |
| 719 | + def test_exact_match_unchanged(self): |
| 720 | + hatch = {"targets": {"wheel": {"packages": ["my_project"]}}} |
| 721 | + assert _resolve_module_from_hatch("my_project", hatch) == "my_project" |
| 722 | + |
| 723 | + def test_only_include_match(self): |
| 724 | + hatch = {"targets": {"wheel": {"only-include": ["jupyterfs"]}}} |
| 725 | + assert _resolve_module_from_hatch("jupyter_fs", hatch) == "jupyterfs" |
| 726 | + |
| 727 | + def test_top_level_packages(self): |
| 728 | + hatch = {"packages": ["jupyterfs"]} |
| 729 | + assert _resolve_module_from_hatch("jupyter_fs", hatch) == "jupyterfs" |
| 730 | + |
| 731 | + def test_period_variant(self): |
| 732 | + hatch = {"targets": {"wheel": {"packages": ["my.pkg"]}}} |
| 733 | + assert _resolve_module_from_hatch("my_pkg", hatch) == "my.pkg" |
| 734 | + |
| 735 | + |
| 736 | +class TestCopierDefaultsWithHatchModuleResolution: |
| 737 | + def test_hatch_resolves_module_name(self): |
| 738 | + hatch = {"targets": {"wheel": {"packages": ["jupyterfs"]}}} |
| 739 | + cfg = copier_defaults( |
| 740 | + {"add_extension": "jupyter", "project_name": "jupyter-fs"}, |
| 741 | + hatch_config=hatch, |
| 742 | + ) |
| 743 | + assert cfg is not None |
| 744 | + assert "jupyterfs" in cfg["sdist"]["present"] |
| 745 | + assert "jupyterfs" in cfg["wheel"]["present"] |
| 746 | + assert "jupyter_fs" not in cfg["sdist"]["present"] |
| 747 | + assert "jupyter_fs" not in cfg["wheel"]["present"] |
| 748 | + |
| 749 | + def test_no_hatch_uses_default_module(self): |
| 750 | + cfg = copier_defaults( |
| 751 | + {"add_extension": "jupyter", "project_name": "jupyter-fs"}, |
| 752 | + ) |
| 753 | + assert cfg is not None |
| 754 | + assert "jupyter_fs" in cfg["sdist"]["present"] |
| 755 | + assert "jupyter_fs" in cfg["wheel"]["present"] |
| 756 | + |
| 757 | + |
681 | 758 | class TestLoadCopierConfig: |
682 | 759 | def test_missing_file(self, tmp_path): |
683 | 760 | assert load_copier_config(tmp_path) == {} |
|
0 commit comments