This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Make the write_file() helper function in test_shutil return the file name it wrote to
Type: enhancement Stage:
Components: Tests Versions: Python 3.3
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, hynek
Priority: normal Keywords: patch

Created on 2011-08-23 08:31 by hynek, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
write_file_returns_filename.diff hynek, 2011-08-23 08:31 Make write_file return file name and simplify some tests. review
Messages (3)
msg142795 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2011-08-23 08:31
test_shutil contains a handy helper function called write_file(filename. contents). If *filename* is a tuple, os.path.join() is used to concatenate it to a path.

To be really useful, the resulting file name should be returned, so the user can work with it.

So instead of:
fn = os.path.join(x,y)
write_file(fn, 'contents')

I'd prefer:
fn = write_file((x,y), 'contents')

I have attached a simple patch that achieves this and also applied the resulting simplification to some of the tests.
msg142802 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-08-23 09:00
Hm, I don’t think the patch makes the test easier to read or maintain.  As I wrote in the commit message for #12721:

> For simple open then read/write calls, I have left the usual idiom
> (with open + read/write), as it is short and readable enough.

In the current tests, sometimes os.path.join is called and the resulting name (e.g. src) is used to write contents and then as argument to a shutil function; I actually prefer that src paths are created right before dst and with similar code.

So I think I’ll reject this patch.
msg142888 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2011-08-24 17:00
ok. it would have saved some LOC for me, but it's nothing essential of course.
Date User Action Args
2022-04-11 14:57:21adminsetgithub: 57033
2011-08-24 17:00:39hyneksetstatus: open -> closed
resolution: rejected
messages: + msg142888
2011-08-23 09:00:50eric.araujosetmessages: + msg142802
2011-08-23 08:31:35hynekcreate