Untitled
unknown
plain_text
a year ago
1.3 kB
8
Indexable
from pro_filer.actions.main_actions import show_details # NOQA
import os
from datetime import date
def test_show_details_valid(tmp_path, capsys):
file_path = os.path.join(tmp_path, "smiley.png")
with open(file_path, "w") as f:
f.write("smiley")
creation_time = date.fromtimestamp(os.path.getmtime(file_path))
context = {
"base_path": str(file_path)
}
show_details(context)
captured = capsys.readouterr()
assert captured.out == f"File name: smiley.png\nFile size in bytes: 6\nFile type: file\nFile extension: .png\nLast modified date: {creation_time}\n"
def test_show_details_invalid(tmp_path, capsys):
file_path = tmp_path / "????"
with open(file_path, "w") as f:
f.write("smiley")
creation_time = date.fromtimestamp(os.path.getmtime(file_path))
context = {
"base_path": str(file_path)
}
show_details(context)
captured = capsys.readouterr()
assert captured.out == f"File name: ????\nFile size in bytes: 6\nFile type: file\nFile extension: [no extension]\nLast modified date: {creation_time}\n"
def test_show_details_no_extension(capsys):
context = {
"base_path": "foo/bar/???"
}
show_details(context)
captured = capsys.readouterr()
assert captured.out == f"File '???' does not exist\n"
Editor is loading...
Leave a Comment