-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Validate docs dir before writing custom js #5569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -488,6 +488,42 @@ def test_write_js_data_docs_dir(self, checkout_path, run, generate_rtd_data): | |
mkdocs_config=mock.ANY, | ||
) | ||
|
||
@patch('readthedocs.doc_builder.backends.mkdocs.BaseMkdocs.generate_rtd_data') | ||
@patch('readthedocs.projects.models.Project.checkout_path') | ||
def test_write_js_data_on_invalid_docs_dir(self, checkout_path, generate_rtd_data): | ||
tmpdir = tempfile.mkdtemp() | ||
os.mkdir(os.path.join(tmpdir, 'docs')) | ||
yaml_file = os.path.join(tmpdir, 'mkdocs.yml') | ||
yaml.safe_dump( | ||
{ | ||
'site_name': 'mkdocs', | ||
'google_analytics': ['UA-1234-5', 'mkdocs.org'], | ||
'docs_dir': 'invalid_docs_dir', | ||
'extra_css': [ | ||
'http://readthedocs.org/static/css/badge_only.css' | ||
], | ||
'extra_javascript': ['readthedocs-data.js'], | ||
}, | ||
open(yaml_file, 'w'), | ||
) | ||
checkout_path.return_value = tmpdir | ||
|
||
python_env = Virtualenv( | ||
version=self.version, | ||
build_env=self.build_env, | ||
config=None, | ||
) | ||
self.searchbuilder = MkdocsHTML( | ||
build_env=self.build_env, | ||
python_env=python_env, | ||
) | ||
with self.assertRaises(MkDocsYAMLParseError): | ||
self.searchbuilder.append_conf() | ||
generate_rtd_data.assert_called_with( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we don't need this assert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stsewd then how should we check if invalid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we only need that check. The second assert wouldn't happen anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that's True. 👍 updated the PR. |
||
docs_dir='docs', | ||
mkdocs_config=mock.ANY, | ||
) | ||
|
||
@patch('readthedocs.doc_builder.base.BaseBuilder.run') | ||
@patch('readthedocs.projects.models.Project.checkout_path') | ||
def test_append_conf_existing_yaml_with_extra(self, checkout_path, run): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually need to check if this path doesn't exists https://github.com/rtfd/readthedocs.org/blob/4fea14e86fe0aabffd73352402ddf8dbba39ff40/readthedocs/doc_builder/backends/mkdocs.py#L159-L162
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! you meant
docs_path
I thought you meant thedocs_dir
which user adds in the yaml. okay I'll Update the PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear, it is the one the users put in the mkdocs.yml file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the docs dir is relative to the mkdocs.yml file, which can be located in other places not jus in the root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stsewd Thanks for the explanation. 👍