1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
|
import os
import logging
import platform
import unittest
from collections.abc import Callable, Sequence
from tempfile import TemporaryDirectory
from typing import Any
from unittest.mock import patch
from dhpython.fs import ScanResult
from dhpython.pydist import PyDist, Standard
from dhpython.depends import Dependencies
from dhpython.options import DHPythonOptions
from dhpython.version import Version
def pep386(d: dict[str, str]) -> dict[str, list[PyDist]]:
"""Mark all pydist entries as being PEP386"""
result: dict[str, list[PyDist]] = {}
for name, dependency in d.items():
result[name] = [
pydist(name=name, dependency=dependency, standard=Standard.PEP386)
]
return result
def pydist(
name: str,
dependency: str,
versions: set[Version] = set(),
standard: Standard | None = None,
rules: list[str] | None = None,
) -> PyDist:
return PyDist(
name=name,
versions=versions,
dependency=dependency,
standard=standard,
rules=rules or [],
)
def prime_pydist(impl: str, contents: dict[str, list[PyDist]]) -> Callable[[], None]:
"""Fake the pydist data for impl. Returns a cleanup function"""
from dhpython.pydist import normalize_name
normalized_pydist = {}
for name, entries in contents.items():
normalized_pydist[normalize_name(name)] = entries
def fake(req_impl: str) -> dict[str, list[PyDist]]:
if req_impl == impl:
return normalized_pydist
return {}
patcher = patch("dhpython.pydist.load", side_effect=fake)
patcher.start()
return patcher.stop
class DependenciesTestCase(unittest.TestCase):
pkg = "foo"
impl = "cpython3"
pydist: dict[str, list[PyDist]] = {}
stats: dict[str, Any] = {}
prepared_stats: ScanResult
requires: dict[str, Sequence[str]] = {}
dist_info_metadata: dict[str, Sequence[str]] = {}
options = DHPythonOptions()
parse = True
def setUp(self) -> None:
self.d = Dependencies(self.pkg, self.impl)
stats = ScanResult(
{
"compile": False,
"dist-info": set(),
"egg-info": set(),
"ext_no_version": set(),
"ext_stableabi": set(),
"ext_vers": set(),
"nsp.txt": set(),
"private_dirs": {},
"public_vers": set(),
"requires.txt": set(),
"shebangs": set(),
}
)
for k, v in self.stats.items():
assert k in stats
stats[k] = v # type: ignore
write_files = {}
if self.requires:
for fn, lines in self.requires.items():
write_files[fn] = lines
stats["requires.txt"].add(fn)
if self.dist_info_metadata:
for fn, lines in self.dist_info_metadata.items():
write_files[fn] = lines
stats["dist-info"].add(fn)
if write_files:
self.tempdir = TemporaryDirectory() # pylint: disable=consider-using-with
self.addCleanup(self.tempdir.cleanup)
old_wd = os.getcwd()
os.chdir(self.tempdir.name)
self.addCleanup(os.chdir, old_wd)
for fn, lines in write_files.items():
os.makedirs(os.path.dirname(fn))
with open(fn, "w", encoding="UTF-8") as f:
f.write("\n".join(lines))
cleanup = prime_pydist(self.impl, self.pydist)
self.addCleanup(cleanup)
if self.parse:
self.d.parse(stats, self.options)
else:
self.prepared_stats = stats
def assertNotInDepends(self, pkg: str) -> None:
"""Assert that pkg doesn't appear *anywhere* in self.d.depends"""
for dep in self.d.depends:
for alt in dep.split("|"):
alt = alt.strip().split("(", 1)[0].strip()
if pkg == alt:
raise AssertionError(f"{pkg} appears in {alt}")
class TestRequiresCPython3(DependenciesTestCase):
options = DHPythonOptions(guess_deps=True)
pydist = {
"bar": [pydist(name="bar", dependency="python3-bar")],
"baz": [pydist(name="baz", dependency="python3-baz", standard=Standard.PEP386)],
"quux": [
pydist(name="quux", dependency="python3-quux", standard=Standard.PEP440)
],
}
requires = {
"debian/foo/usr/lib/python3/dist-packages/foo.egg-info/requires.txt": (
"bar",
"baz >= 1.0",
"quux >= 1.0a1",
),
}
def test_depends_on_bar(self) -> None:
self.assertIn("python3-bar", self.d.depends)
def test_depends_on_baz(self) -> None:
self.assertIn("python3-baz (>= 1.0)", self.d.depends)
def test_depends_on_quux(self) -> None:
self.assertIn("python3-quux (>= 1.0~a1)", self.d.depends)
class TestRequiresCompatible(DependenciesTestCase):
options = DHPythonOptions(guess_deps=True)
pydist = {
"bar": [pydist(name="bar", dependency="python3-bar")],
"baz": [pydist(name="baz", dependency="python3-baz", standard=Standard.PEP386)],
"qux": [pydist(name="qux", dependency="python3-qux", standard=Standard.PEP386)],
"quux": [
pydist(name="quux", dependency="python3-quux", standard=Standard.PEP386)
],
"corge": [
pydist(name="corge", dependency="python3-corge", standard=Standard.PEP440)
],
}
requires = {
"debian/foo/usr/lib/python3/dist-packages/foo.egg-info/requires.txt": (
"bar",
"baz ~= 1.1",
"qux == 1.*",
"quux",
"corge == 1.0",
),
}
def test_depends_on_bar(self) -> None:
self.assertIn("python3-bar", self.d.depends)
def test_depends_on_baz(self) -> None:
self.assertIn("python3-baz (>= 1.1), python3-baz (<< 2)", self.d.depends)
def test_depends_on_qux(self) -> None:
self.assertIn("python3-qux (>= 1.0), python3-qux (<< 2)", self.d.depends)
def test_depends_on_corge(self) -> None:
self.assertIn("python3-corge (>= 1.0), python3-corge (<< 1.1~)", self.d.depends)
class TestRequiresDistPython3(DependenciesTestCase):
options = DHPythonOptions(guess_deps=True)
pydist = {
"bar": [pydist(name="bar", dependency="python3-bar")],
"baz": [pydist(name="baz", dependency="python3-baz", standard=Standard.PEP386)],
"qux": [pydist(name="qux", dependency="python3-qux", standard=Standard.PEP386)],
"quux": [
pydist(name="quux", dependency="python3-quux", standard=Standard.PEP386)
],
"corge": [
pydist(name="corge", dependency="python3-corge", standard=Standard.PEP440)
],
}
dist_info_metadata = {
"debian/foo/usr/lib/python3/dist-packages/foo.dist-info/METADATA": (
"Requires-Dist: bar",
"Requires-Dist: baz >= 1.0",
"Requires-Dist: qux == 1.*",
"Requires-Dist: quux ~= 1.1",
"Requires-Dist: corge == 1.0",
),
}
def test_depends_on_bar(self) -> None:
self.assertIn("python3-bar", self.d.depends)
def test_depends_on_baz(self) -> None:
self.assertIn("python3-baz (>= 1.0)", self.d.depends)
def test_depends_on_qux(self) -> None:
self.assertIn("python3-qux (>= 1.0), python3-qux (<< 2)", self.d.depends)
def test_depends_on_quux(self) -> None:
self.assertIn("python3-quux (>= 1.1), python3-quux (<< 2)", self.d.depends)
def test_depends_on_corge(self) -> None:
self.assertIn("python3-corge (>= 1.0), python3-corge (<< 1.1~)", self.d.depends)
class TestEnvironmentMarkersDistInfo(DependenciesTestCase):
options = DHPythonOptions(guess_deps=True, depends_section=["feature"])
pydist = pep386(
{
"no_markers": "python3-no-markers",
"os_posix": "python3-os-posix",
"os_java": "python3-os-java",
"sys_platform_linux": "python3-sys-platform-linux",
"sys_platform_darwin": "python3-sys-platform-darwin",
"platform_machine_x86_64": "python3-platform-machine-x86-64",
"platform_machine_mips64": "python3-platform-machine-mips64",
"platform_python_implementation_cpython": "python3-platform-python-implementation-cpython",
"platform_python_implementation_jython": "python3-platform-python-implementation-jython",
"platform_python_implementation_not_pypy": "python3-platform-python-implementation-not-pypy",
"platform_python_implementation_pypy": "python3-platform-python-implementation-pypy",
"platform_release_lt2": "python3-platform-release-lt2",
"platform_release_ge2": "python3-platform-release-ge2",
"platform_system_linux": "python3-platform-system-linux",
"platform_system_windows": "python3-platform-system-windows",
"platform_version_lt1": "python3-platform-version-lt1",
"platform_version_ge1": "python3-platform-version-ge1",
"python_version_ge3": "python3-python-version-ge3",
"python_version_gt3": "python3-python-version-gt3",
"python_version_lt3": "python3-python-version-lt3",
"python_version_lt30": "python3-python-version-lt30",
"python_version_lt38": "python3-python-version-lt38",
"python_version_lt313": "python3-python-version-lt313",
"python_version_le313": "python3-python-version-le313",
"python_version_ge27": "python3-python-version-ge27",
"python_version_ge313": "python3-python-version-ge313",
"python_version_gt313": "python3-python-version-gt313",
"python_version_eq313": "python3-python-version-eq313",
"python_version_ne313": "python3-python-version-ne313",
"python_version_aeq313": "python3-python-version-aeq313",
"python_version_ceq313": "python3-python-version-ceq313",
"python_version_weq313": "python3-python-version-weq313",
"python_version_full_lt300": "python3-python-version-full-lt300",
"python_version_full_lt3131": "python3-python-version-full-lt3131",
"python_version_full_le3131": "python3-python-version-full-le3131",
"python_version_full_ge3131": "python3-python-version-full-ge3131",
"python_version_full_ge3131a1": "python3-python-version-full-ge3131a1",
"python_version_full_ge3131b1post1": "python3-python-version-full-ge3131b1post1",
"python_version_full_gt3131": "python3-python-version-full-gt3131",
"python_version_full_eq3131": "python3-python-version-full-eq3131",
"python_version_full_ne3131": "python3-python-version-full-ne3131",
"python_version_full_aeq3131": "python3-python-version-full-aeq3131",
"python_version_full_ceq3131": "python3-python-version-full-ceq3131",
"python_version_full_weq313": "python3-python-version-full-weq313",
"implementation_name_cpython": "python3-implementation-name-cpython",
"implementation_name_pypy": "python3-implementation-name-pypy",
"implementation_version_lt313": "python3-implementation-version-lt313",
"implementation_version_ge313": "python3-implementation-version-ge313",
"invalid_marker": "python3-invalid-marker",
"extra_feature": "python3-extra-feature",
"extra_test": "python3-extra-test",
"complex_marker": "python3-complex-marker",
"complex_marker_2": "python3-complex-marker-2",
"no_markers_2": "python3-no-markers-2",
}
)
dist_info_metadata = {
"debian/foo/usr/lib/python3/dist-packages/foo.dist-info/METADATA": (
"Requires-Dist: no_markers",
"Requires-Dist: os_posix; (os_name == 'posix')",
'Requires-Dist: os_java; os_name == "java"',
"Requires-Dist: sys_platform_linux ; sys_platform == 'linux'",
"Requires-Dist: sys_platform_darwin;sys_platform == 'darwin'",
"Requires-Dist: platform_machine_x86_64; " "platform_machine == 'x86_64'",
"Requires-Dist: platform_machine_mips64; " "platform_machine == 'mips64'",
"Requires-Dist: platform_python_implementation_cpython; "
"platform_python_implementation == 'CPython'",
"Requires-Dist: platform_python_implementation_jython; "
"platform_python_implementation == 'Jython'",
"Requires-Dist: platform_python_implementation_pypy; "
"platform_python_implementation == 'PyPy'",
"Requires-Dist: platform_python_implementation_not_pypy; "
"platform_python_implementation != 'PyPy'",
"Requires-Dist: platform_release_lt2; platform_release < '2.0'",
"Requires-Dist: platform_release_ge2; platform_release >= '2.0'",
"Requires-Dist: platform_system_linux; platform_system == 'Linux'",
"Requires-Dist: platform_system_windows; " "platform_system == 'Windows'",
"Requires-Dist: platform_version_lt1; platform_version < '1'",
"Requires-Dist: platform_version_ge1; platform_version >= '1'",
"Requires-Dist: python_version_ge3; python_version >= '3'",
"Requires-Dist: python_version_gt3; python_version > '3'",
"Requires-Dist: python_version_lt3; python_version < '3'",
"Requires-Dist: python_version_lt30; python_version < '3.0'",
"Requires-Dist: python_version_lt38; python_version < '3.8'",
"Requires-Dist: python_version_lt313; python_version < '3.13'",
"Requires-Dist: python_version_le313; python_version <= '3.13'",
"Requires-Dist: python_version_gt313; python_version > '3.13'",
"Requires-Dist: python_version_ge27; python_version >= '2.7'",
"Requires-Dist: python_version_ge313; python_version >= '3.13'",
"Requires-Dist: python_version_eq313; python_version == '3.13'",
"Requires-Dist: python_version_ne313; python_version != '3.13'",
"Requires-Dist: python_version_aeq313; python_version === '3.13'",
"Requires-Dist: python_version_ceq313; python_version ~= '3.13'",
"Requires-Dist: python_version_weq313; python_version == '3.13.*'",
"Requires-Dist: python_version_full_lt300; "
"python_full_version < '3.0.0'",
"Requires-Dist: python_version_full_lt3131; "
"python_full_version < '3.13.1'",
"Requires-Dist: python_version_full_le3131; "
"python_full_version <= '3.13.1'",
"Requires-Dist: python_version_full_gt3131; "
"python_full_version > '3.13.1'",
"Requires-Dist: python_version_full_ge3131; "
"python_full_version >= '3.13.1'",
"Requires-Dist: python_version_full_ge3131a1; "
"python_full_version >= '3.13.1a1'",
"Requires-Dist: python_version_full_ge3131b1post1; "
"python_full_version >= '3.13.1b1.post1'",
"Requires-Dist: python_version_full_eq3131; "
"python_full_version == '3.13.1'",
"Requires-Dist: python_version_full_ne3131; "
"python_full_version != '3.13.1'",
"Requires-Dist: python_version_full_aeq3131; "
"python_full_version === '3.13.1'",
"Requires-Dist: python_version_full_ceq3131; "
"python_full_version ~= '3.13.1'",
"Requires-Dist: python_version_full_weq313; "
"python_full_version == '3.13.*'",
"Requires-Dist: implementation_name_cpython; "
"implementation_name == 'cpython'",
"Requires-Dist: implementation_name_pypy; " "implementation_name == 'pypy'",
"Requires-Dist: implementation_version_lt313; "
"implementation_version < '3.13'",
"Requires-Dist: implementation_version_ge313; "
"implementation_version >= '3.13'",
"Requires-Dist: invalid_marker; invalid_marker > '1'",
"Requires-Dist: extra_feature; extra == 'feature'",
"Requires-Dist: extra_test; extra == 'test'",
"Requires-Dist: complex_marker; os_name != 'windows' "
"and implementation_name == 'cpython'",
'Requires-Dist: complex_marker_2; (python_version > "3.4") '
"and extra == 'test'",
"Requires-Dist: no_markers_2",
),
}
def test_depends_on_unmarked_packages(self) -> None:
self.assertIn("python3-no-markers", self.d.depends)
def test_depends_on_posix_packages(self) -> None:
self.assertIn("python3-os-posix", self.d.depends)
def test_skips_non_posix_packages(self) -> None:
self.assertNotInDepends("python3-os-java")
def test_depends_on_linux_packages(self) -> None:
self.assertIn("python3-sys-platform-linux", self.d.depends)
def test_skips_darwin_packages(self) -> None:
self.assertNotInDepends("python3-sys-platform-darwin")
def test_depends_on_x86_64_packages_on_x86_64(self) -> None:
if platform.machine() == "x86_64":
self.assertIn("python3-platform-machine-x86-64", self.d.depends)
else:
self.assertNotInDepends("python3-platform-machine-x86-64")
def test_depends_on_mips64_packages_on_mips64(self) -> None:
if platform.machine() == "mips64":
self.assertIn("python3-platform-machine-mips64", self.d.depends)
else:
self.assertNotInDepends("python3-platform-machine-mips64")
def test_depends_on_plat_cpython_packages(self) -> None:
self.assertIn("python3-platform-python-implementation-cpython", self.d.depends)
def test_depends_on_plat_pypy_packages(self) -> None:
self.assertIn("python3-platform-python-implementation-pypy", self.d.depends)
def test_depends_on_plat_not_pypy_packages(self) -> None:
self.assertIn("python3-platform-python-implementation-not-pypy", self.d.depends)
def test_skips_plat_jython_packages(self) -> None:
self.assertNotInDepends("python3-platform-python-implementation-jython")
def test_skips_release_lt_2_packages(self) -> None:
self.assertNotInDepends("python3-platform-release-lt2")
def test_skips_release_gt_2_packages(self) -> None:
self.assertNotInDepends("python3-platform-release-ge2")
def test_depends_on_platform_linux_packages(self) -> None:
self.assertIn("python3-platform-system-linux", self.d.depends)
def test_skips_platform_windows_packages(self) -> None:
self.assertNotInDepends("python3-platform-system-windows")
def test_skips_platfrom_version_lt_1_packages(self) -> None:
self.assertNotInDepends("python3-platform-version-lt1")
def test_skips_platform_version_ge_1_packages(self) -> None:
self.assertNotInDepends("python3-platform-version-ge1")
def test_skips_py_version_lt_3_packages(self) -> None:
self.assertNotInDepends("python3-python-version-lt3")
def test_elides_py_version_ge_3(self) -> None:
self.assertIn("python3-python-version-ge3", self.d.depends)
def test_elides_py_version_gt_3(self) -> None:
self.assertIn("python3-python-version-gt3", self.d.depends)
def test_skips_py_version_lt_30_packages(self) -> None:
self.assertNotInDepends("python3-python-version-lt30")
def test_skips_py_version_lt_38_packages(self) -> None:
self.assertNotInDepends("python3-python-version-lt38")
def test_depends_on_py_version_lt_313_packages(self) -> None:
self.assertIn(
"python3-supported-min (>= 3.13) " "| python3-python-version-lt313",
self.d.depends,
)
def test_depends_on_py_version_le_313_packages(self) -> None:
self.assertIn(
"python3-supported-min (>> 3.13) " "| python3-python-version-le313",
self.d.depends,
)
def test_depends_on_py_version_ge_27_packages(self) -> None:
self.assertIn("python3-python-version-ge27", self.d.depends)
def test_depends_on_py_version_ge_313_packages(self) -> None:
self.assertIn(
"python3-python-version-ge313 " "| python3-supported-max (<< 3.13)",
self.d.depends,
)
def test_depends_on_py_version_gt_313_packages(self) -> None:
self.assertIn(
"python3-python-version-gt313 " "| python3-supported-max (<= 3.13)",
self.d.depends,
)
def test_depends_on_py_version_eq_313_packages(self) -> None:
self.assertIn(
"python3-python-version-eq313 | python3-supported-max (<< 3.13) "
"| python3-supported-min (>= 3.14)",
self.d.depends,
)
def test_depends_on_py_version_ne_313_packages(self) -> None:
# Can't be represented in Debian depends
self.assertIn("python3-python-version-ne313", self.d.depends)
def test_depends_on_py_version_aeq_313_packages(self) -> None:
self.assertIn(
"python3-python-version-aeq313 | python3-supported-max (<< 3.13) "
"| python3-supported-min (>> 3.13)",
self.d.depends,
)
def test_depends_on_py_version_ceq_313_packages(self) -> None:
self.assertIn(
"python3-python-version-ceq313 | python3-supported-max (<< 3.13) "
"| python3-supported-min (>= 3.14)",
self.d.depends,
)
def test_depends_on_py_version_weq_313_packages(self) -> None:
self.assertIn(
"python3-python-version-weq313 | python3-supported-max (<< 3.13) "
"| python3-supported-min (>= 3.14)",
self.d.depends,
)
def test_skips_py_version_full_lt_300_packages(self) -> None:
self.assertNotInDepends("python3-python-version-full-lt300")
def test_depends_on_py_version_full_lt_3131_packages(self) -> None:
self.assertIn(
"python3-supported-min (>= 3.13.1) " "| python3-python-version-full-lt3131",
self.d.depends,
)
def test_depends_on_py_version_full_le_3131_packages(self) -> None:
self.assertIn(
"python3-supported-min (>> 3.13.1) " "| python3-python-version-full-le3131",
self.d.depends,
)
def test_depends_on_py_version_full_ge_3131_packages(self) -> None:
self.assertIn(
"python3-python-version-full-ge3131 " "| python3-supported-max (<< 3.13.1)",
self.d.depends,
)
def test_depends_on_py_version_full_ge_3131a1_packages(self) -> None:
# With full PEP-440 parsing this should be (<< 3.13.1~a1)
self.assertIn(
"python3-python-version-full-ge3131a1 "
"| python3-supported-max (<< 3.13.0)",
self.d.depends,
)
def test_depends_on_py_version_full_ge_3131b1post1_packages(self) -> None:
# With full PEP-440 parsing this should be (<< 3.13.1~b1.post1)
self.assertIn(
"python3-python-version-full-ge3131a1 "
"| python3-supported-max (<< 3.13.0)",
self.d.depends,
)
def test_depends_on_py_version_full_gt_3131_packages(self) -> None:
self.assertIn(
"python3-python-version-full-gt3131 " "| python3-supported-max (<= 3.13.1)",
self.d.depends,
)
def test_depends_on_py_version_full_eq_3131_packages(self) -> None:
self.assertIn(
"python3-python-version-full-eq3131 "
"| python3-supported-max (<< 3.13.1) "
"| python3-supported-min (>> 3.13.1)",
self.d.depends,
)
def test_depends_on_py_version_full_ne_3131_packages(self) -> None:
# Can't be represented in Debian depends
self.assertIn("python3-python-version-full-ne3131", self.d.depends)
def test_skips_py_version_full_aeq_3131_packages(self) -> None:
# Can't be represented in Debian depends
self.assertNotInDepends("python3-python-version-full-aeq3131")
def test_depends_on_py_version_full_ceq_3131_packages(self) -> None:
self.assertIn(
"python3-python-version-full-ceq3131 "
"| python3-supported-max (<< 3.13.1) "
"| python3-supported-min (>= 3.14)",
self.d.depends,
)
def test_depends_on_py_version_full_weq_313_packages(self) -> None:
self.assertIn(
"python3-python-version-full-weq313 "
"| python3-supported-max (<< 3.13) "
"| python3-supported-min (>= 3.14)",
self.d.depends,
)
def test_depends_on_sys_cpython_packages(self) -> None:
self.assertIn("python3-implementation-name-cpython", self.d.depends)
def test_depends_on_sys_pypy_packages(self) -> None:
self.assertIn("python3-implementation-name-pypy", self.d.depends)
def test_depends_on_sys_implementation_lt313_packages(self) -> None:
self.assertIn(
"python3-supported-min (>= 3.13) " "| python3-implementation-version-lt313",
self.d.depends,
)
def test_depends_on_sys_implementation_ge313_packages(self) -> None:
self.assertIn(
"python3-implementation-version-ge313 " "| python3-supported-max (<< 3.13)",
self.d.depends,
)
def test_ignores_invalid_marker(self) -> None:
self.assertNotInDepends("python3-invalid-marker")
def test_depends_on_extra_feature_packages(self) -> None:
self.assertIn("python3-extra-feature", self.d.depends)
def test_skips_extra_test_packages(self) -> None:
self.assertNotInDepends("python3-extra-test")
def test_ignores_complex_environment_markers(self) -> None:
self.assertNotInDepends("python3-complex-marker")
self.assertNotInDepends("python3-complex-marker-2")
def test_depends_on_un_marked_dependency_after_extra(self) -> None:
self.assertIn("python3-no-markers-2", self.d.depends)
class TestEnvironmentMarkersEggInfo(TestEnvironmentMarkersDistInfo):
dist_info_metadata = {}
requires = {
"debian/foo/usr/lib/python3/dist-packages/foo.egg-info/requires.txt": (
"no_markers",
"[:(os_name == 'posix')]",
"os_posix",
'[:os_name == "java"]',
"os_java",
"[:sys_platform == 'linux']",
"sys_platform_linux",
"[:sys_platform == 'darwin']",
"sys_platform_darwin",
"[:platform_machine == 'x86_64']",
"platform_machine_x86_64",
"[:platform_machine == 'mips64']",
"platform_machine_mips64",
"[:platform_python_implementation == 'CPython']",
"platform_python_implementation_cpython",
"[:platform_python_implementation == 'Jython']",
"platform_python_implementation_jython",
"[:platform_python_implementation == 'PyPy']",
"platform_python_implementation_pypy",
"[:platform_python_implementation != 'PyPy']",
"platform_python_implementation_not_pypy",
"[:platform_release < '2.0']",
"platform_release_lt2",
"[:platform_release >= '2.0']",
"platform_release_ge2",
"[:platform_system == 'Linux']",
"platform_system_linux",
"[:platform_system == 'Windows']",
"platform_system_windows",
"[:platform_version < '1']",
"platform_version_lt1",
"[:platform_version >= '1']",
"platform_version_ge1",
"[:python_version >= '3']",
"python_version_ge3",
"[:python_version > '3']",
"python_version_gt3",
"[:python_version < '3']",
"python_version_lt3",
"[:python_version < '3.0']",
"python_version_lt30",
"[:python_version < '3.8']",
"python_version_lt313",
"[:python_version < '3.13']",
"python_version_lt313",
"[:python_version <= '3.13']",
"python_version_le313",
"[:python_version > '3.13']",
"python_version_gt313",
"[:python_version >= '2.7']",
"python_version_ge27",
"[:python_version >= '3.13']",
"python_version_ge313",
"[:python_version == '3.13']",
"python_version_eq313",
"[:python_version != '3.13']",
"python_version_ne313",
"[:python_version === '3.13']",
"python_version_aeq313",
"[:python_version ~= '3.13']",
"python_version_ceq313",
"[:python_version == '3.13.*']",
"python_version_weq313",
"[:python_full_version < '3.0.0']",
"python_version_full_lt300",
"[:python_full_version < '3.13.1']",
"python_version_full_lt3131",
"[:python_full_version <= '3.13.1']",
"python_version_full_le3131",
"[:python_full_version > '3.13.1']",
"python_version_full_gt3131",
"[:python_full_version >= '3.13.1']",
"python_version_full_ge3131",
"[:python_full_version >= '3.13.1a1']",
"python_version_full_ge3131a1",
"[:python_full_version >= '3.13.1b1.post1']",
"python_version_full_ge3131b1post1",
"[:python_full_version == '3.13.1']",
"python_version_full_eq3131",
"[:python_full_version != '3.13.1']",
"python_version_full_ne3131",
"[:python_full_version === '3.13.1']",
"python_version_full_aeq3131",
"[:python_full_version ~= '3.13.1']",
"python_version_full_ceq3131",
"[:python_full_version == '3.13.*']",
"python_version_full_weq313",
"[:implementation_name == 'cpython']",
"implementation_name_cpython",
"[:implementation_name == 'pypy']",
"implementation_name_pypy",
"[:implementation_version < '3.13']",
"implementation_version_lt313",
"[:implementation_version >= '3.13']",
"implementation_version_ge313",
"[:invalid_marker > '1']",
"invalid_marker",
"[feature]",
"extra_feature",
"[test]",
"extra_test",
"[:os_name != 'windows' and implementation_name == 'cpython']",
"complex_marker",
"[test:(os_name != 'windows')]",
"complex_marker_2",
),
}
def test_depends_on_un_marked_dependency_after_extra(self) -> None:
raise unittest.SkipTest("Not possible in requires.txt")
class TestIgnoresUnusedModulesDistInfo(DependenciesTestCase):
options = DHPythonOptions(guess_deps=True, depends_section=["feature"])
dist_info_metadata = {
"debian/foo/usr/lib/python3/dist-packages/foo.dist-info/METADATA": (
"Requires-Dist: unusued-complex-module ; "
"(sys_platform == \"darwin\") and extra == 'nativelib'",
'Requires-Dist: unused-win-module ; (sys_platform == "win32")',
"Requires-Dist: unused-extra-module ; extra == 'unused'",
),
}
parse = False
def test_ignores_unused_dependencies(self) -> None:
if not hasattr(self, "assertLogs"):
raise unittest.SkipTest("Requires Python >= 3.4")
with self.assertLogs(logger="dhpython", level=logging.INFO) as logs:
self.d.parse(self.prepared_stats, self.options)
for line in logs.output:
self.assertTrue(
line.startswith("INFO:dhpython:Ignoring complex environment marker"),
"Expecting only complex environment marker messages, but "
"got: {}".format(line),
)
class TestIgnoresUnusedModulesEggInfo(DependenciesTestCase):
options = DHPythonOptions(guess_deps=True, depends_section=["feature"])
requires = {
"debian/foo/usr/lib/python3/dist-packages/foo.egg-info/requires.txt": (
"[nativelib:(sys_platform == 'darwin')]",
"unusued-complex-module",
"[:sys_platform == 'win32']",
"unused-win-module",
"[unused]",
"unused-extra-module",
)
}
parse = False
def test_ignores_unused_dependencies(self) -> None:
if not hasattr(self, "assertNoLogs"):
raise unittest.SkipTest("Requires Python >= 3.10")
with self.assertNoLogs(logger="dhpython", level=logging.INFO):
self.d.parse(self.prepared_stats, self.options)
class TestCExtensionPython3(DependenciesTestCase):
stats = {
"public_vers": {Version("3")},
"ext_vers": {Version("3.14")},
}
def test_python_depends(self) -> None:
self.assertIn("python3 (>= 3.14~)", self.d.depends)
self.assertIn("python3 (<< 3.15)", self.d.depends)
class TestCExtensionsPython3(DependenciesTestCase):
stats = {
"public_vers": {Version("3")},
"ext_vers": {Version("3.14"), Version("3.13")},
}
def test_python_depends(self) -> None:
self.assertIn("python3 (>= 3.13~)", self.d.depends)
self.assertIn("python3 (<< 3.15)", self.d.depends)
class TestStableABIExtensionPython3(DependenciesTestCase):
stats = {
"public_vers": {Version("3")},
"ext_stableabi": {"foo.abi3.so"},
}
def test_python_depends(self) -> None:
self.assertIn("python3", self.d.depends)
class TestMixedExtensionsPython3(DependenciesTestCase):
stats = {
"public_vers": {Version("3")},
"ext_vers": {Version("3.14"), Version("3.13")},
"ext_stableabi": {"foo.abi3.so"},
}
def test_python_depends(self) -> None:
self.assertIn("python3 (>= 3.13~)", self.d.depends)
self.assertIn("python3 (<< 3.15)", self.d.depends)
class TestUnversionedExtensionPython3(DependenciesTestCase):
stats = {
"public_vers": {Version("3")},
"ext_no_version": {"foo.so"},
}
def test_python_depends(self) -> None:
# This test is to maintain the status-quo where this case is only
# handled in private modules. That's *probably* OK?
self.assertNotInDepends("python3")
|