From e30e265344e21d51f6cf1d350f146a7aedf76569 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Sun, 7 Jun 2020 11:23:13 +0800 Subject: [PATCH] Adding filesystem_helper submodule in test.support --- Doc/library/test.rst | 23 +++++++++++++++++------ Lib/test/support/__init__.py | 14 ++------------ Lib/test/support/filesystem_helper.py | 13 +++++++++++++ 3 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 Lib/test/support/filesystem_helper.py diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 7580fb5e9b174f..0baffdf52ae1d5 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -252,12 +252,6 @@ The :mod:`test.support` module defines the following constants: A non-ASCII character encodable by :func:`os.fsencode`. -.. data:: TESTFN - - Set to a name that is safe to use as the name of a temporary file. Any - temporary file that is created should be closed and unlinked (removed). - - .. data:: TESTFN_UNICODE Set to a non-ASCII name for a temporary file. @@ -1634,3 +1628,20 @@ The :mod:`test.support.threading_helper` module provides support for threading t # (to avoid reference cycles) .. versionadded:: 3.8 + + +:mod:`test.support.filesystem_helper` --- Utilities for filesystem tests +======================================================================== + +.. module:: test.support.filesystem_helper + :synopsis: Support for filesystem tests. + +The :mod:`test.support.filesystem_helper` module provides support for filesystem tests. + +.. versionadded:: 3.10 + + +.. data:: TESTFN + + Set to a name that is safe to use as the name of a temporary file. Any + temporary file that is created should be closed and unlinked (removed). diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index bb905bd895de8b..88074c464a7cbe 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -22,6 +22,7 @@ import unittest import warnings +from .filesystem_helper import TESTFN from .testresult import get_test_runner __all__ = [ @@ -37,7 +38,7 @@ "record_original_stdout", "get_original_stdout", "captured_stdout", "captured_stdin", "captured_stderr", # filesystem - "TESTFN", "SAVEDCWD", "unlink", "rmtree", "temp_cwd", "findfile", + "SAVEDCWD", "unlink", "rmtree", "temp_cwd", "findfile", "create_empty_file", "can_symlink", "fs_is_case_insensitive", # unittest "is_resource_enabled", "requires", "requires_freebsd_version", @@ -714,17 +715,6 @@ def requires_lzma(reason='requires lzma'): else: unix_shell = None -# Filename used for testing -if os.name == 'java': - # Jython disallows @ in module names - TESTFN = '$test' -else: - TESTFN = '@test' - -# Disambiguate TESTFN for parallel testing, while letting it remain a valid -# module name. -TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid()) - # Define the URL of a dedicated HTTP server for the network tests. # The URL must use clear-text HTTP: no redirection to encrypted HTTPS. TEST_HTTP_URL = "http://www.pythontest.net" diff --git a/Lib/test/support/filesystem_helper.py b/Lib/test/support/filesystem_helper.py new file mode 100644 index 00000000000000..ba4d17071df805 --- /dev/null +++ b/Lib/test/support/filesystem_helper.py @@ -0,0 +1,13 @@ +import os + + +# Filename used for testing +if os.name == 'java': + # Jython disallows @ in module names + TESTFN = '$test' +else: + TESTFN = '@test' + +# Disambiguate TESTFN for parallel testing, while letting it remain a valid +# module name. +TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid())