-
Notifications
You must be signed in to change notification settings - Fork 0
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
Ml2 write docstring to file #19
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a89f8e0
write to docstring script
Lukman-Lateef 5e94d9b
write to docstring script
Lukman-Lateef 36fbe61
writing docstring
Lukman-Lateef af4a3b9
writing docstring
Lukman-Lateef cfb31b5
writing docstring
Lukman-Lateef e2832c8
completed the function
Lukman-Lateef df8347c
fixed indentation error
Lukman-Lateef f8a89cc
making write to file optional
Lukman-Lateef ea7cc85
modified function
Lukman-Lateef 3a7e71f
created test file for write_docstring_to_file.py
Lukman-Lateef 29f0c58
writing test functions from write_docstring_to_file
Lukman-Lateef ac37c6d
updated test functions
Lukman-Lateef c3a38b4
modified write_docstring_function
Lukman-Lateef 7718bc9
modified write_docstring_function
Lukman-Lateef 05ee07c
fixing test issues
Lukman-Lateef 23b3cbf
modified test functions
Lukman-Lateef 4af2e39
removed temp notebook
Lukman-Lateef 28b02a5
modified test for write docstring
Lukman-Lateef dc2cd19
deleted docsrc/fml_doc_gen/docstring_output.txt
Lukman-Lateef 0db5dbf
made changes based on mike's review
Lukman-Lateef 0646970
made changes based on mike's review
Lukman-Lateef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
from tempfile import NamedTemporaryFile, TemporaryDirectory | ||
import pytest | ||
from fml_doc_gen.write_docstring_to_file import write_docstring_to_file | ||
|
||
|
||
@pytest.fixture | ||
def valid_docstring(): | ||
"""Fixture for a valid docstring.""" | ||
return """ | ||
Writes the generated docstring to a specified output file. | ||
|
||
Parameters | ||
---------- | ||
docstring : str | ||
The docstring to be written to the file. | ||
output_file : str | ||
The path to the output file. | ||
|
||
Returns | ||
------- | ||
None | ||
This function does not return anything. | ||
""" | ||
|
||
|
||
def test_write_to_valid_file(valid_docstring): | ||
"""Test writing the docstring to a valid file""" | ||
with NamedTemporaryFile(suffix=".txt",delete=False) as temp_file: | ||
file_path = temp_file.name | ||
|
||
try: | ||
write_docstring_to_file(valid_docstring, output_file=file_path) | ||
|
||
with open(file_path, "r") as file: | ||
content = file.read() | ||
|
||
assert content.strip() == valid_docstring.strip() | ||
finally: | ||
if os.path.exists(file_path): | ||
os.remove(file_path) | ||
|
||
|
||
def test_invalid_directory(valid_docstring): | ||
"""Test writing to a file in a non-existent directory.""" | ||
with TemporaryDirectory() as temp_dir: | ||
non_existent_dir = os.path.join(temp_dir, "nonexistent") | ||
file_path = os.path.join(non_existent_dir, "docstring_output.txt") | ||
with pytest.raises(ValueError, match=f"This directory '{non_existent_dir}' does not exist"): | ||
write_docstring_to_file(valid_docstring, output_file=file_path) | ||
|
||
def test_non_writable_directory(valid_docstring): | ||
"""Test writing to a file in a non-writable directory.""" | ||
with TemporaryDirectory() as temp_dir: | ||
# Make the temp_dir directory non writable | ||
os.chmod(temp_dir, 0o500) | ||
file_path = os.path.join(temp_dir, "docstring_output.txt") | ||
try: | ||
with pytest.raises(ValueError, match=f"This directory '{temp_dir}' is not writable"): | ||
write_docstring_to_file(valid_docstring, output_file=file_path) | ||
finally: | ||
os.chmod(temp_dir, 0o700) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 can keep this, but use raise
ValueError
instead :)