Message260349
An example::
import io
import tempfile
names = tempfile._get_candidate_names()
def test_frobnicates_configured_spungfile():
""" ‘foo’ should frobnicate the configured spungfile. """
fake_file_path = os.path.join(tempfile.gettempdir(), names.next())
fake_file = io.BytesIO("Lorem ipsum, dolor sit amet".encode("utf-8"))
patch_builtins_open(
when_accessing_path=fake_file_path,
provide_file=fake_file)
system_under_test.config.spungfile_path = fake_file_path
system_under_test.foo()
assert_correctly_frobnicated(fake_file)
With a supported standard library API for this – ‘tempfile.makepath’
for example – the generation of the filesystem path would change from
four separate function calls::
names = tempfile._get_candidate_names()
fake_file_path = os.path.join(tempfile.gettempdir(), names.next())
to a simple function call::
fake_file_path = tempfile.makepath()
and have the benefit of not reaching in to a private API. |
|
Date |
User |
Action |
Args |
2016-02-16 05:53:53 | bignose | set | recipients:
+ bignose, ethan.furman |
2016-02-16 05:53:53 | bignose | set | messageid: <1455602033.68.0.493197345296.issue26362@psf.upfronthosting.co.za> |
2016-02-16 05:53:53 | bignose | link | issue26362 messages |
2016-02-16 05:53:53 | bignose | create | |
|