From 9f0362f2b0ebaaf144f5c8330b28d810ef222ac4 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Thu, 4 Oct 2018 09:37:49 -0700 Subject: Tempfile management APIs for absltest.TestCase This adds two methods to absltest.TestCase: create_tempfile() and create_tempdir(), which allow easy and correct creation of tempfiles and tempdirs in tests. Creating tempfiles in tests has a variety of subtleties that these methods take care of. Notable subtlties are platform compatibility, passing FLAGS.test_tmpdir around correctly, passing the right arguments to mkstemp, mkdtemp, and NamedTemporaryFile, cleanup of files, Python 2/3 API differences in file/path functions, and ensuring file isolation between tests, among other difficulties. To aid debugging, cleanup of files/dirs can be controlled by the class/instance level, by setting tempfile_cleanup, or at the `create_temp{file,dir}()` call level by passing the `cleanup` arg. The net effect is that tempfile setup/teardown is reduced from ~20 lines to ~3 lines, and the previously mentioned problems are taken care of by the test framework. New Dependencies: * enum34: Required under Python 2.7. Under Bazel, it is always required, but is not used under Python 3. Other changes: * Some unrelated lines had type annotations added; this was necessary to make pytype happy. PiperOrigin-RevId: 215751711 --- setup.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setup.py') diff --git a/setup.py b/setup.py index be45325..7d43ec8 100644 --- a/setup.py +++ b/setup.py @@ -52,6 +52,7 @@ setuptools.setup( ]), install_requires=[ 'six', + "enum34; python_version<='3.4'" ], license='Apache 2.0', classifiers=[ -- cgit v1.2.3