From 8d15d2216795768160231080b245633631eba05e Mon Sep 17 00:00:00 2001 From: kschopmeyer Date: Mon, 23 Sep 2024 08:04:42 -0500 Subject: [PATCH] Remove additional python 2.7 leftover. Removes another couple of things involving python 2.7 1. Test that was specialized for python 2.7 on windows, Issue 1590 2. Reference to python 2.7 in pywbem_server 3. Remove tests/unit/pywbemcli/test_python_tell.py - This test was created to confirm that there were no issues between the tell() function on windows with python 2.7 and to verify that test_build_mockenv() works. With the removal of python 2.7 as a platform, this test is no longer necessary. 4. version doc that used python 2.7.11 as example in tools. Note that one test in test_pywbemcli_operations.py from the group that was disabled because of a windows issue is still marked disabled because that test fails. See issue #1440. --- docs/pywbemcli/cmdshelp.rst | 4 +- pywbemtools/pywbemcli/_pywbem_server.py | 3 +- tests/unit/pywbemcli/test_python_tell.py | 87 ------------------- .../pywbemcli/test_pywbemcli_operations.py | 47 ++++------ tools/python_version.py | 2 +- 5 files changed, 21 insertions(+), 122 deletions(-) delete mode 100644 tests/unit/pywbemcli/test_python_tell.py diff --git a/docs/pywbemcli/cmdshelp.rst b/docs/pywbemcli/cmdshelp.rst index 507c0d37..53f22739 100644 --- a/docs/pywbemcli/cmdshelp.rst +++ b/docs/pywbemcli/cmdshelp.rst @@ -659,7 +659,7 @@ Help text for ``pywbemcli connection`` (see :ref:`connection command group`): delete Delete a WBEM connection definition. select Select a WBEM connection definition as current or default. test Test the current connection with a predefined WBEM request. - save Save the current connection parameters to a named WBEM connection. + save Save the current connection parameters to a named connection. list List the WBEM connection definitions. set-default Set a connection as the default connection. @@ -762,7 +762,7 @@ Help text for ``pywbemcli connection save`` (see :ref:`connection save command`) Usage: pywbemcli [GENERAL-OPTIONS] connection save NAME [COMMAND-OPTIONS] - Save the current connection parameters to a named WBEM connection. + Save the current connection parameters to a named connection. Save the current connection to the connections file as a connection definition named NAME. The NAME argument is required. If a connection definition with that name already exists, it is overwritten without warning. diff --git a/pywbemtools/pywbemcli/_pywbem_server.py b/pywbemtools/pywbemcli/_pywbem_server.py index 1929188e..1a6dd450 100644 --- a/pywbemtools/pywbemcli/_pywbem_server.py +++ b/pywbemtools/pywbemcli/_pywbem_server.py @@ -467,8 +467,7 @@ def copy(self): Used to copy PywbemServer so that a deep copy is not applied to conn which would cause the repository to be copied in the - case of FakedWBEMConnection, and possible exceptions - with pywbem 2.7 + case of FakedWBEMConnection. """ cpy = PywbemServer( server=self.server, diff --git a/tests/unit/pywbemcli/test_python_tell.py b/tests/unit/pywbemcli/test_python_tell.py deleted file mode 100644 index ae320d57..00000000 --- a/tests/unit/pywbemcli/test_python_tell.py +++ /dev/null @@ -1,87 +0,0 @@ -""" -Tests for Python tell() behavior. - -This test exists because certain uses of tell() behave differently between -Windows and Unix-like platforms on Python 2.7. - -They document these differences, and verify that the approach used in -test_build_mockenv() works on all platforms. -""" -# TODO: Eliminate this module. - - -import os -import pytest - -# pylint: disable=use-dict-literal - - -@pytest.fixture() -def file_path(): - """ - Create a text file with one line, and remove it after the test. - - Returns the file path of the text file. - """ - - _file_path = 'tmp_file.txt' - with open(_file_path, 'w', encoding='utf-8') as fp: - fp.write('first line\n') - - # The yield causes the remainder of this fixture to be executed at the - # end of the test. - yield _file_path - - os.remove(_file_path) - - -def test_tell_append_diff(file_path): - # pylint: disable=redefined-outer-name - """ - Test the different behavior of tell() after opening for appending on - Python 2 on Windows. - """ - - size = os.stat(file_path).st_size - - # Get the stream position via tell() and append a line - with open(file_path, 'a', encoding='utf-8') as fp: - pos = fp.tell() - fp.write('second line\n') - - # Remove the line again by truncating the file to the previous stream - # position. - with open(file_path, 'a', encoding='utf-8') as fp: - fp.seek(pos) - fp.truncate() - - new_size = os.stat(file_path).st_size - exp_size = size - assert new_size == exp_size, \ - f"original size: {size}, tell() result: {pos}, " \ - f"actual new size: {new_size}, expected new size: {exp_size}" - - -def test_truncate_append_same(file_path): - # pylint: disable=redefined-outer-name - """ - Test the behavior of truncate(size) after opening for appending. - - This is the approach used in test_build_mockenv(). - """ - - size = os.stat(file_path).st_size - - # Append a line - with open(file_path, 'a', encoding='utf-8') as fp: - fp.write('second line\n') - - # Remove the line again by truncating the file using truncate() with size. - with open(file_path, 'a', encoding='utf-8') as fp: - fp.truncate(size) - - new_size = os.stat(file_path).st_size - exp_size = size - assert new_size == exp_size, \ - f"original size: {size}, actual new size: {new_size}, " \ - f"expected new size: {exp_size}" diff --git a/tests/unit/pywbemcli/test_pywbemcli_operations.py b/tests/unit/pywbemcli/test_pywbemcli_operations.py index f629863c..211eae5e 100644 --- a/tests/unit/pywbemcli/test_pywbemcli_operations.py +++ b/tests/unit/pywbemcli/test_pywbemcli_operations.py @@ -52,11 +52,6 @@ URLLIB3_VERSION = packaging.version.parse(urllib3.__version__) -# Click (as of 7.1.2) raises UnsupportedOperation in click.echo() when -# the pytest capsys fixture is used. That happens only on Windows. -# See Click issue https://github.com/pallets/click/issues/1590. This -# run condition skips the testcases on Windows. -CLICK_ISSUE_1590 = sys.platform == 'win32' SCRIPT_DIR = os.path.dirname(__file__) USER_CONNECTIONS_FILE = os.path.join(SCRIPT_DIR, '.user_connections_file.yaml') @@ -503,7 +498,7 @@ def remove_mockcache(connection_name): exp_stdout_lines_all=False, exp_stderr_lines=[], ), - None, DeprecatedSetupWarning, not CLICK_ISSUE_1590 + None, DeprecatedSetupWarning, OK ), ( "Mock env with MOF file and old-style mock script, " @@ -528,7 +523,7 @@ def remove_mockcache(connection_name): exp_stdout_lines_all=False, exp_stderr_lines=[], ), - None, DeprecatedSetupWarning, not CLICK_ISSUE_1590 + None, DeprecatedSetupWarning, OK ), ( "Mock env with MOF file and old-style mock script, " @@ -553,8 +548,7 @@ def remove_mockcache(connection_name): # preparation for executing the code to be tested. If the mock env is # not cached, there is no pkl file that can be removed, so this # testcase is skipped when the mock env cannot be cached. - None, DeprecatedSetupWarning, - NEWSTYLE_SUPPORTED and not CLICK_ISSUE_1590 + None, DeprecatedSetupWarning, OK ), ( "Mock env with MOF file and old-style mock script, " @@ -580,7 +574,7 @@ def remove_mockcache(connection_name): # not cached, there is no md5 file that can be removed, so this # testcase is skipped when the mock env cannot be cached. None, DeprecatedSetupWarning, - NEWSTYLE_SUPPORTED and not CLICK_ISSUE_1590 + NEWSTYLE_SUPPORTED ), ( "Mock env with MOF file and old-style mock script, " @@ -606,7 +600,7 @@ def remove_mockcache(connection_name): # not cached, there is no dep file that can be removed, so this # testcase is skipped when the mock env cannot be cached. None, DeprecatedSetupWarning, - NEWSTYLE_SUPPORTED and not CLICK_ISSUE_1590 + NEWSTYLE_SUPPORTED ), ( "Mock env with MOF file and old-style mock script, " @@ -632,7 +626,7 @@ def remove_mockcache(connection_name): exp_stdout_lines_all=False, exp_stderr_lines=[], ), - None, DeprecatedSetupWarning, not CLICK_ISSUE_1590 + None, DeprecatedSetupWarning, OK ), ( "Mock env with MOF file and old-style mock script, " @@ -658,7 +652,7 @@ def remove_mockcache(connection_name): exp_stdout_lines_all=False, exp_stderr_lines=[], ), - None, DeprecatedSetupWarning, not CLICK_ISSUE_1590 + None, DeprecatedSetupWarning, OK ), ( "Mock env with MOF file and new-style mock script, " @@ -680,8 +674,7 @@ def remove_mockcache(connection_name): exp_stderr_lines=[], ), None if NEWSTYLE_SUPPORTED else SetupNotSupportedError, - DeprecationWarning if RETRY_DEPRECATION else None, - not CLICK_ISSUE_1590 + DeprecationWarning if RETRY_DEPRECATION else None, OK ), ( @@ -703,8 +696,7 @@ def remove_mockcache(connection_name): exp_stderr_lines=[], ), None if NEWSTYLE_SUPPORTED else SetupNotSupportedError, - DeprecationWarning if RETRY_DEPRECATION else None, - not CLICK_ISSUE_1590 + DeprecationWarning if RETRY_DEPRECATION else None, OK ), ( "Mock env with MOF file and new-style mock script, " @@ -726,8 +718,7 @@ def remove_mockcache(connection_name): exp_stderr_lines=[], ), None if NEWSTYLE_SUPPORTED else SetupNotSupportedError, - DeprecationWarning if RETRY_DEPRECATION else None, - not CLICK_ISSUE_1590 + DeprecationWarning if RETRY_DEPRECATION else None, OK ), ( "Mock env with MOF file and new-style mock script, " @@ -749,8 +740,7 @@ def remove_mockcache(connection_name): exp_stderr_lines=[], ), None if NEWSTYLE_SUPPORTED else SetupNotSupportedError, - DeprecationWarning if RETRY_DEPRECATION else None, - not CLICK_ISSUE_1590 + DeprecationWarning if RETRY_DEPRECATION else None, OK ), ( "Mock env with MOF file and new-style mock script, " @@ -773,8 +763,7 @@ def remove_mockcache(connection_name): exp_stderr_lines=[], ), None if NEWSTYLE_SUPPORTED else SetupNotSupportedError, - DeprecationWarning if RETRY_DEPRECATION else None, - not CLICK_ISSUE_1590 + DeprecationWarning if RETRY_DEPRECATION else None, OK ), ( "Mock env with MOF file and new-style mock script, " @@ -797,8 +786,7 @@ def remove_mockcache(connection_name): exp_stderr_lines=[], ), None if NEWSTYLE_SUPPORTED else SetupNotSupportedError, - DeprecationWarning if RETRY_DEPRECATION else None, - not CLICK_ISSUE_1590 + DeprecationWarning if RETRY_DEPRECATION else None, OK ), # Testcases with non-cacheable user-specified connections file @@ -825,7 +813,7 @@ def remove_mockcache(connection_name): exp_stdout_lines_all=False, exp_stderr_lines=[], ), - None, DeprecatedSetupWarning, not CLICK_ISSUE_1590 + None, DeprecatedSetupWarning, OK ), # Testcases with standalone mock script that has dependents @@ -848,8 +836,7 @@ def remove_mockcache(connection_name): exp_stderr_lines=[], ), None if NEWSTYLE_SUPPORTED else SetupNotSupportedError, - DeprecationWarning if RETRY_DEPRECATION else None, - not CLICK_ISSUE_1590 + DeprecationWarning if RETRY_DEPRECATION else None, OK ), ( "Mock env with standalone mock script with deps; change dependent file", @@ -870,9 +857,9 @@ def remove_mockcache(connection_name): exp_stdout_lines_all=False, exp_stderr_lines=[], ), + # See issue #1440 failure of this test with windows None if NEWSTYLE_SUPPORTED else SetupNotSupportedError, - DeprecationWarning if RETRY_DEPRECATION else None, - not CLICK_ISSUE_1590 + DeprecationWarning if RETRY_DEPRECATION else None, not "win32" ), ] diff --git a/tools/python_version.py b/tools/python_version.py index d3766d13..a1bc4353 100755 --- a/tools/python_version.py +++ b/tools/python_version.py @@ -6,7 +6,7 @@ print("Error: Incorrect number of command line arguments") print(f"Usage: {sys.argv[0]} version_level") print("Where version_level is the number of components in the " - "version string from 1 to 3, e.g. 3 means Python 2.7.11") + "version string from 1 to 3, e.g. 3 means Python 3.12.1") sys.exit(2)