|
14 | 14 | from readthedocs.config.exceptions import ConfigError, ConfigValidationError
|
15 | 15 | from readthedocs.config.models import (
|
16 | 16 | BuildJobs,
|
| 17 | + BuildJobsBuildTypes, |
17 | 18 | BuildWithOs,
|
18 | 19 | PythonInstall,
|
19 | 20 | PythonInstallRequirements,
|
@@ -627,17 +628,120 @@ def test_jobs_build_config(self):
|
627 | 628 | assert build.build.jobs.pre_create_environment == [
|
628 | 629 | "echo pre_create_environment"
|
629 | 630 | ]
|
| 631 | + assert build.build.jobs.create_environment is None |
630 | 632 | assert build.build.jobs.post_create_environment == [
|
631 | 633 | "echo post_create_environment"
|
632 | 634 | ]
|
633 | 635 | assert build.build.jobs.pre_install == ["echo pre_install", "echo `date`"]
|
| 636 | + assert build.build.jobs.install is None |
634 | 637 | assert build.build.jobs.post_install == ["echo post_install"]
|
635 | 638 | assert build.build.jobs.pre_build == [
|
636 | 639 | "echo pre_build",
|
637 | 640 | 'sed -i -e "s|{VERSION}|${READTHEDOCS_VERSION_NAME}|g"',
|
638 | 641 | ]
|
| 642 | + assert build.build.jobs.build == BuildJobsBuildTypes() |
639 | 643 | assert build.build.jobs.post_build == ["echo post_build"]
|
640 | 644 |
|
| 645 | + def test_build_jobs_partial_override(self): |
| 646 | + build = get_build_config( |
| 647 | + { |
| 648 | + "formats": ["pdf", "htmlzip", "epub"], |
| 649 | + "build": { |
| 650 | + "os": "ubuntu-20.04", |
| 651 | + "tools": {"python": "3"}, |
| 652 | + "jobs": { |
| 653 | + "create_environment": ["echo make_environment"], |
| 654 | + "install": ["echo install"], |
| 655 | + "build": { |
| 656 | + "html": ["echo build html"], |
| 657 | + "pdf": ["echo build pdf"], |
| 658 | + "epub": ["echo build epub"], |
| 659 | + "htmlzip": ["echo build htmlzip"], |
| 660 | + }, |
| 661 | + }, |
| 662 | + }, |
| 663 | + }, |
| 664 | + ) |
| 665 | + build.validate() |
| 666 | + assert isinstance(build.build, BuildWithOs) |
| 667 | + assert isinstance(build.build.jobs, BuildJobs) |
| 668 | + assert build.build.jobs.create_environment == ["echo make_environment"] |
| 669 | + assert build.build.jobs.install == ["echo install"] |
| 670 | + assert build.build.jobs.build.html == ["echo build html"] |
| 671 | + assert build.build.jobs.build.pdf == ["echo build pdf"] |
| 672 | + assert build.build.jobs.build.epub == ["echo build epub"] |
| 673 | + assert build.build.jobs.build.htmlzip == ["echo build htmlzip"] |
| 674 | + |
| 675 | + def test_build_jobs_build_should_match_formats(self): |
| 676 | + build = get_build_config( |
| 677 | + { |
| 678 | + "formats": ["pdf"], |
| 679 | + "build": { |
| 680 | + "os": "ubuntu-24.04", |
| 681 | + "tools": {"python": "3"}, |
| 682 | + "jobs": { |
| 683 | + "build": { |
| 684 | + "epub": ["echo build epub"], |
| 685 | + }, |
| 686 | + }, |
| 687 | + }, |
| 688 | + }, |
| 689 | + ) |
| 690 | + with raises(ConfigError) as excinfo: |
| 691 | + build.validate() |
| 692 | + assert ( |
| 693 | + excinfo.value.message_id |
| 694 | + == ConfigError.BUILD_JOBS_BUILD_TYPE_MISSING_IN_FORMATS |
| 695 | + ) |
| 696 | + |
| 697 | + def test_build_jobs_build_defaults(self): |
| 698 | + build = get_build_config( |
| 699 | + { |
| 700 | + "build": { |
| 701 | + "os": "ubuntu-24.04", |
| 702 | + "tools": {"python": "3"}, |
| 703 | + "jobs": { |
| 704 | + "build": { |
| 705 | + "html": ["echo build html"], |
| 706 | + }, |
| 707 | + }, |
| 708 | + }, |
| 709 | + }, |
| 710 | + ) |
| 711 | + build.validate() |
| 712 | + assert build.build.jobs.build.html == ["echo build html"] |
| 713 | + assert build.build.jobs.build.pdf is None |
| 714 | + assert build.build.jobs.build.htmlzip is None |
| 715 | + assert build.build.jobs.build.epub is None |
| 716 | + |
| 717 | + def test_build_jobs_partial_override_empty_commands(self): |
| 718 | + build = get_build_config( |
| 719 | + { |
| 720 | + "formats": ["pdf"], |
| 721 | + "build": { |
| 722 | + "os": "ubuntu-24.04", |
| 723 | + "tools": {"python": "3"}, |
| 724 | + "jobs": { |
| 725 | + "create_environment": [], |
| 726 | + "install": [], |
| 727 | + "build": { |
| 728 | + "html": [], |
| 729 | + "pdf": [], |
| 730 | + }, |
| 731 | + }, |
| 732 | + }, |
| 733 | + }, |
| 734 | + ) |
| 735 | + build.validate() |
| 736 | + assert isinstance(build.build, BuildWithOs) |
| 737 | + assert isinstance(build.build.jobs, BuildJobs) |
| 738 | + assert build.build.jobs.create_environment == [] |
| 739 | + assert build.build.jobs.install == [] |
| 740 | + assert build.build.jobs.build.html == [] |
| 741 | + assert build.build.jobs.build.pdf == [] |
| 742 | + assert build.build.jobs.build.epub == None |
| 743 | + assert build.build.jobs.build.htmlzip == None |
| 744 | + |
641 | 745 | @pytest.mark.parametrize(
|
642 | 746 | "value",
|
643 | 747 | [
|
@@ -1757,10 +1861,18 @@ def test_as_dict_new_build_config(self, tmpdir):
|
1757 | 1861 | "pre_system_dependencies": [],
|
1758 | 1862 | "post_system_dependencies": [],
|
1759 | 1863 | "pre_create_environment": [],
|
| 1864 | + "create_environment": None, |
1760 | 1865 | "post_create_environment": [],
|
1761 | 1866 | "pre_install": [],
|
| 1867 | + "install": None, |
1762 | 1868 | "post_install": [],
|
1763 | 1869 | "pre_build": [],
|
| 1870 | + "build": { |
| 1871 | + "html": None, |
| 1872 | + "pdf": None, |
| 1873 | + "epub": None, |
| 1874 | + "htmlzip": None, |
| 1875 | + }, |
1764 | 1876 | "post_build": [],
|
1765 | 1877 | },
|
1766 | 1878 | "apt_packages": [],
|
|
0 commit comments