[3.12] gh-71339: Add additional assertion methods in test.support (GH-128707) (GH-128815) (GH-129059)

Add a mix-in class ExtraAssertions containing the following methods:

* assertHasAttr() and assertNotHasAttr()
* assertIsSubclass() and assertNotIsSubclass()
* assertStartsWith() and assertNotStartsWith()
* assertEndsWith() and assertNotEndsWith()

(cherry picked from commit c6a566e47b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 06cad77a5b)
This commit is contained in:
Serhiy Storchaka 2025-01-20 14:06:02 +02:00 committed by GitHub
parent 7f68e7bf2a
commit 032058cb62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 68 additions and 49 deletions

View file

@ -25,6 +25,7 @@ from test.support import (captured_stdout, captured_stderr,
requires_resource, copy_python_src_ignore)
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree,
TESTFN, FakePath)
from test.support.testcase import ExtraAssertions
import unittest
import venv
from unittest.mock import patch, Mock
@ -58,7 +59,7 @@ def check_output(cmd, encoding=None):
p.returncode, cmd, out, err)
return out, err
class BaseTest(unittest.TestCase):
class BaseTest(unittest.TestCase, ExtraAssertions):
"""Base class for venv tests."""
maxDiff = 80 * 50
@ -98,10 +99,6 @@ class BaseTest(unittest.TestCase):
result = f.read()
return result
def assertEndsWith(self, string, tail):
if not string.endswith(tail):
self.fail(f"String {string!r} does not end with {tail!r}")
class BasicTest(BaseTest):
"""Test venv module functionality."""