Skip to content

no tests#1767

Open
VictorMatveyshyn wants to merge 7 commits intomate-academy:masterfrom
VictorMatveyshyn:create_file
Open

no tests#1767
VictorMatveyshyn wants to merge 7 commits intomate-academy:masterfrom
VictorMatveyshyn:create_file

Conversation

@VictorMatveyshyn
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread app/create_file.py Outdated
from datetime import datetime


def main() -> None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread app/create_file.py Outdated
del argv[index: index + 2]
break
except IndexError:
print("Error: після -f має бути вказано filename")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use double quotes consistently as per the checklist requirement. This line uses single quotes while other string literals use double quotes.

Comment thread app/create_file.py Outdated
for index in range(len(argv)):
if argv[index].strip() == "-d":
if index == len(argv) - 1:
print("Error: після -d має бути вказано dirname")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use double quotes consistently as per the checklist requirement.

Comment thread app/create_file.py

while not stop:
line = input("Enter content line: ")
if line.lower() == "stop":
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use double quotes consistently as per the checklist requirement.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread app/create_file.py Outdated
Comment on lines +29 to +34
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:]]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread app/create_file.py Outdated
Comment on lines +57 to +58
with open(full_path, "a") as f:
f.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread app/create_file.py Outdated
# current_dir = getcwd()
# print(current_dir)

with open(full_path, "a") as f:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread app/create_file.py
Comment on lines +44 to +60

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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

Comment thread app/create_file.py Outdated
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"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread app/create_file.py Outdated
Comment on lines +53 to +70
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants