On 16 Feb 2016 05:57, "Ben Finney" <ben+pyt...@benfinney.id.au> wrote:
>
> Cameron Simpson <c...@zip.com.au> writes:
>
> > I've been watching this for a few days, and am struggling to
> > understand your use case.
>
> Yes, you're not alone. This surprises me, which is why I'm persisting.
>
> > Can you elaborate with a concrete example and its purpose which would
> > work with a mktemp-ish official function?
>
> 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)

If you're going to patch open to return a fake file when asked to open
fake_file_path why do you care whether there is a real file of that name?

--
Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to