Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102992 > unrolled thread

Re: Make a unique filesystem path, without creating the file

Started byOscar Benjamin <oscar.j.benjamin@gmail.com>
First post2016-02-16 08:35 +0000
Last post2016-02-16 08:35 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Make a unique filesystem path, without creating the file Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-02-16 08:35 +0000

#102992 — Re: Make a unique filesystem path, without creating the file

FromOscar Benjamin <oscar.j.benjamin@gmail.com>
Date2016-02-16 08:35 +0000
SubjectRe: Make a unique filesystem path, without creating the file
Message-ID<mailman.156.1455611742.22075.python-list@python.org>
On 16 Feb 2016 05:57, "Ben Finney" <ben+python@benfinney.id.au> wrote:
>
> Cameron Simpson <cs@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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web