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


Groups > comp.lang.python > #102992

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

From Oscar Benjamin <oscar.j.benjamin@gmail.com>
Newsgroups comp.lang.python
Subject Re: Make a unique filesystem path, without creating the file
Date 2016-02-16 08:35 +0000
Message-ID <mailman.156.1455611742.22075.python-list@python.org> (permalink)
References <85egce6a8a.fsf@benfinney.id.au> <20160215230539.GA42677@cskk.homeip.net> <851t8d42rt.fsf@benfinney.id.au>

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web