no tests#1767
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation has critical failures that must be fixed before approval. All 7 tests are failing because the core functionality is not working: argument parsing for -d and -f flags is broken, os.makedirs() is not creating directory hierarchies, and input() is never being called to collect user content. This means the primary purpose of the application—creating files and directories from terminal input—is completely non-functional. Once the core functionality is working, please also extract reusable operations into separate functions (e.g., get_content(), write_to_file(), parse_arguments()) as noted in the review comments to address the DRY principle violation. Use double quotes consistently throughout the code as required by the style checklist.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| from datetime import datetime | ||
|
|
||
|
|
||
| def main() -> None: |
There was a problem hiding this comment.
Create separate functions instead of placing all logic in main(). The checklist requires separate functions to avoid repeating code. Consider extracting content reading and file writing into their own functions.
| del argv[index: index + 2] | ||
| break | ||
| except IndexError: | ||
| print("Error: після -f має бути вказано filename") |
There was a problem hiding this comment.
Use double quotes consistently as per the checklist requirement. This line uses single quotes while other string literals use double quotes.
| for index in range(len(argv)): | ||
| if argv[index].strip() == "-d": | ||
| if index == len(argv) - 1: | ||
| print("Error: після -d має бути вказано dirname") |
There was a problem hiding this comment.
Use double quotes consistently as per the checklist requirement.
|
|
||
| while not stop: | ||
| line = input("Enter content line: ") | ||
| if line.lower() == "stop": |
There was a problem hiding this comment.
Use double quotes consistently as per the checklist requirement.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes to address the critical issues preventing task completion. The argument parsing logic in app/create_file.py causes an IndexError when -d appears before -f because the loop range is evaluated once but elements are deleted during iteration. This is confirmed by 4 of 7 tests failing with 'list assignment index out of range'. Additionally, the timestamp is written without a trailing newline (line 57), but the first content line has a \n prefix (line 50), causing them to be concatenated on the same line instead of separate lines as the spec requires. There is also no blank line separator when appending to existing files. Per [CHECKLIST ITEM #5], you need to extract content collection into get_content(), file writing into write_to_file(), and argument parsing into parse_arguments() to avoid repeating blocks of code.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| for index in range(len(argv)): | ||
| if argv[index].strip() == "-d": | ||
| if index == len(argv) - 1: | ||
| print("Error: correct format -d <directory name(s)>") | ||
| exit(1) | ||
| directory = [name.strip() for name in argv[index + 1:]] |
There was a problem hiding this comment.
CRITICAL BUG: This logic is broken when -d comes before -f. The range(len(argv)) is evaluated once at loop start, but argv elements are deleted in the first loop. When -d appears first (e.g., ['-d', 'dir1', '-f', 'file.txt']), after processing -d, the code tries to access indices beyond the shortened list, causing IndexError. Fix: collect -d arguments until another flag is encountered, not all remaining args.
| with open(full_path, "a") as f: | ||
| f.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) |
There was a problem hiding this comment.
The timestamp is written without a trailing newline (line 57), but first content line has \n prefix (line 50). This causes the output to be 2022-02-01 14:41:101 Line1 content on the SAME line instead of separate lines. Add newline after timestamp.
| # current_dir = getcwd() | ||
| # print(current_dir) | ||
|
|
||
| with open(full_path, "a") as f: |
There was a problem hiding this comment.
When appending to an existing file, there's no blank line added before the new timestamp. Per the requirements example, there should be a blank line between content batches. Consider checking if file exists and adding separator.
|
|
||
| while not stop: | ||
| line = input("Enter content line: ") | ||
| if line.lower() == "stop": | ||
| stop = True | ||
| else: | ||
| content.append(f"\n{line_number} {line}") | ||
| line_number += 1 | ||
| # content.append("\n") | ||
|
|
||
| # current_dir = getcwd() | ||
| # print(current_dir) | ||
|
|
||
| with open(full_path, "a") as f: | ||
| f.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) | ||
| for line in content: | ||
| f.write(line) |
There was a problem hiding this comment.
CHECKLIST ITEM #5 VIOLATION: The code doesn't use separate functions for reusable operations. Per the checklist 'Create separate functions in order not to have repeating blocks of code', extract content collection into get_content(), file writing into write_to_file(), and argument parsing into parse_arguments().
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved for educational purposes, allowing you to progress while learning. You've done well implementing argument parsing correctly and using proper path construction with os.path.join(). However, there are two remaining issues to address: 1. Timestamp newline issue (line 62): The timestamp written via datetime.now().strftime("%Y-%m-%d %H:%M:%S") is missing a trailing \n, causing the first content line to concatenate directly after the timestamp. Add + "\n" after the strftime call. 2. DRY principle [CHECKLIST ITEM #5]: The content collection logic (input loop, lines 64-69) and file writing logic should be extracted into separate get_content() and write_to_file() functions rather than being embedded in create_file(). This improves code reusability and maintainability. Once you fix these two issues, your implementation will be complete. Keep up the good work on the parts that are already correct!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| new_line = "\n\n" if path.isfile(full_path) else "" | ||
|
|
||
| with open(full_path, "a") as f: | ||
| f.write(new_line + datetime.now().strftime("%Y-%m-%d %H:%M:%S")) |
There was a problem hiding this comment.
The timestamp line has no trailing newline, causing the first content line to be concatenated on the same line. Add + "\n" at the end of the strftime call, or add \n before the first content line.
| if arguments["flag_f"]: | ||
| full_path = path.join(*arguments["directory"], arguments["filename"]) | ||
|
|
||
| stop = False | ||
| line_number = 1 | ||
|
|
||
| new_line = "\n\n" if path.isfile(full_path) else "" | ||
|
|
||
| with open(full_path, "a") as f: | ||
| f.write(new_line + datetime.now().strftime("%Y-%m-%d %H:%M:%S")) | ||
|
|
||
| while not stop: | ||
| line = input("Enter content line: ") | ||
| if line.lower() == "stop": | ||
| stop = True | ||
| else: | ||
| f.write(f"\n{line_number} {line}") | ||
| line_number += 1 |
There was a problem hiding this comment.
Per [CHECKLIST ITEM #5] and the DRY principle, extract the content collection (lines 64-69) into a separate get_content() function that returns a list of content lines. Then extract the file writing logic into a separate write_to_file() function.
No description provided.