python/tests: add TestCaseInTempdir.mktemp()
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 25 Oct 2018 00:33:02 +0000 (13:33 +1300)
committerDouglas Bagnall <dbagnall@samba.org>
Tue, 8 Jan 2019 22:55:34 +0000 (23:55 +0100)
commit71cb2605e86d04e489fbb8081daff8f7b8e56ae1
tree99a7a65ef1c5156431cdae75c837b8d311836fbd
parentaffaeb944fd77ea67d6fb9ece2c53e6433e3b4a7
python/tests: add TestCaseInTempdir.mktemp()

This gives you a name of a temporary file within the test case's tempdir.
Use it like this:

  with self.mktemp() as filename:
     self.check_run("samba-tool foo --output %s" % filename)
     self.assertStringsEqual(open(filename).read(), expected)

and filename will flick out of existence when the with block ends.

This is based on an idea used in the traffic_runner tests, which will
soon be adapted to use this method.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/__init__.py