|
13 | 13 | from mock import MagicMock, PropertyMock, patch
|
14 | 14 |
|
15 | 15 | from readthedocs.builds.models import Version
|
16 |
| -from readthedocs.config import BuildConfigV1, InvalidConfig, ProjectConfig |
| 16 | +from readthedocs.config import ALL, BuildConfigV1, InvalidConfig, ProjectConfig |
17 | 17 | from readthedocs.config.tests.utils import apply_fs
|
18 | 18 | from readthedocs.doc_builder.config import load_yaml_config
|
19 | 19 | from readthedocs.doc_builder.environments import LocalBuildEnvironment
|
20 | 20 | from readthedocs.doc_builder.python_environments import Conda, Virtualenv
|
21 | 21 | from readthedocs.projects import tasks
|
22 | 22 | from readthedocs.projects.models import Feature, Project
|
| 23 | +from readthedocs.rtd_tests.utils import create_git_submodule, make_git_repo |
23 | 24 |
|
24 | 25 |
|
25 | 26 | def create_load(config=None):
|
@@ -889,3 +890,104 @@ def test_mkdocs_fail_on_warning(
|
889 | 890 | assert '--strict' in args
|
890 | 891 | append_conf.assert_called_once()
|
891 | 892 | move.assert_called_once()
|
| 893 | + |
| 894 | + @pytest.mark.parametrize('value,expected', [(ALL, ['one', 'two', 'three']), |
| 895 | + (['one', 'two'], ['one', 'two'])]) |
| 896 | + @patch('readthedocs.vcs_support.backends.git.Backend.checkout_submodules') |
| 897 | + def test_submodules_include(self, checkout_submodules, |
| 898 | + checkout_path, tmpdir, value, expected): |
| 899 | + checkout_path.return_value = str(tmpdir) |
| 900 | + self.create_config_file( |
| 901 | + tmpdir, |
| 902 | + { |
| 903 | + 'submodules': { |
| 904 | + 'include': value, |
| 905 | + }, |
| 906 | + } |
| 907 | + ) |
| 908 | + |
| 909 | + git_repo = make_git_repo(str(tmpdir)) |
| 910 | + create_git_submodule(git_repo, 'one') |
| 911 | + create_git_submodule(git_repo, 'two') |
| 912 | + create_git_submodule(git_repo, 'three') |
| 913 | + |
| 914 | + update_docs = self.get_update_docs_task() |
| 915 | + checkout_path.return_value = git_repo |
| 916 | + update_docs.additional_vcs_operations() |
| 917 | + |
| 918 | + args, kwargs = checkout_submodules.call_args |
| 919 | + assert set(args[0]) == set(expected) |
| 920 | + assert update_docs.config.submodules.recursive is False |
| 921 | + |
| 922 | + @patch('readthedocs.vcs_support.backends.git.Backend.checkout_submodules') |
| 923 | + def test_submodules_exclude(self, checkout_submodules, |
| 924 | + checkout_path, tmpdir): |
| 925 | + checkout_path.return_value = str(tmpdir) |
| 926 | + self.create_config_file( |
| 927 | + tmpdir, |
| 928 | + { |
| 929 | + 'submodules': { |
| 930 | + 'exclude': ['one'], |
| 931 | + 'recursive': True, |
| 932 | + }, |
| 933 | + } |
| 934 | + ) |
| 935 | + |
| 936 | + git_repo = make_git_repo(str(tmpdir)) |
| 937 | + create_git_submodule(git_repo, 'one') |
| 938 | + create_git_submodule(git_repo, 'two') |
| 939 | + create_git_submodule(git_repo, 'three') |
| 940 | + |
| 941 | + update_docs = self.get_update_docs_task() |
| 942 | + checkout_path.return_value = git_repo |
| 943 | + update_docs.additional_vcs_operations() |
| 944 | + |
| 945 | + args, kwargs = checkout_submodules.call_args |
| 946 | + assert set(args[0]) == {'two', 'three'} |
| 947 | + assert update_docs.config.submodules.recursive is True |
| 948 | + |
| 949 | + @patch('readthedocs.vcs_support.backends.git.Backend.checkout_submodules') |
| 950 | + def test_submodules_exclude_all(self, checkout_submodules, |
| 951 | + checkout_path, tmpdir): |
| 952 | + checkout_path.return_value = str(tmpdir) |
| 953 | + self.create_config_file( |
| 954 | + tmpdir, |
| 955 | + { |
| 956 | + 'submodules': { |
| 957 | + 'exclude': ALL, |
| 958 | + 'recursive': True, |
| 959 | + }, |
| 960 | + } |
| 961 | + ) |
| 962 | + |
| 963 | + git_repo = make_git_repo(str(tmpdir)) |
| 964 | + create_git_submodule(git_repo, 'one') |
| 965 | + create_git_submodule(git_repo, 'two') |
| 966 | + create_git_submodule(git_repo, 'three') |
| 967 | + |
| 968 | + update_docs = self.get_update_docs_task() |
| 969 | + checkout_path.return_value = git_repo |
| 970 | + update_docs.additional_vcs_operations() |
| 971 | + |
| 972 | + checkout_submodules.assert_not_called() |
| 973 | + |
| 974 | + @patch('readthedocs.vcs_support.backends.git.Backend.checkout_submodules') |
| 975 | + def test_submodules_default_exclude_all(self, checkout_submodules, |
| 976 | + checkout_path, tmpdir): |
| 977 | + |
| 978 | + checkout_path.return_value = str(tmpdir) |
| 979 | + self.create_config_file( |
| 980 | + tmpdir, |
| 981 | + {} |
| 982 | + ) |
| 983 | + |
| 984 | + git_repo = make_git_repo(str(tmpdir)) |
| 985 | + create_git_submodule(git_repo, 'one') |
| 986 | + create_git_submodule(git_repo, 'two') |
| 987 | + create_git_submodule(git_repo, 'three') |
| 988 | + |
| 989 | + update_docs = self.get_update_docs_task() |
| 990 | + checkout_path.return_value = git_repo |
| 991 | + update_docs.additional_vcs_operations() |
| 992 | + |
| 993 | + checkout_submodules.assert_not_called() |
0 commit comments