[Lldb-commits] [lldb] [lldb][test] Remove vendored packages `unittest2` and `progress` (PR #82670)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Feb 22 10:16:14 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Jordan Rupprecht (rupprecht)
<details>
<summary>Changes</summary>
The `unittest2` package is unused since 5b386158aacac4b41126983a5379d36ed413d0ea.
The `progress` package was only used internally by `unittest2`, so it can be deleted as well.
---
Patch is 317.19 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/82670.diff
30 Files Affected:
- (removed) lldb/third_party/Python/module/progress/progress.py (-181)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/__init__.py (-78)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/__main__.py (-10)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/case.py (-1169)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/collector.py (-10)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/compatibility.py (-67)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/loader.py (-339)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/main.py (-257)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/result.py (-197)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/runner.py (-206)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/signals.py (-63)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/suite.py (-286)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/__init__.py (-1)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/dummy.py ()
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/support.py (-189)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_assertions.py (-269)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_break.py (-258)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_case.py (-1244)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_discovery.py (-392)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_functiontestcase.py (-148)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_loader.py (-1380)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_new_tests.py (-52)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_program.py (-251)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_result.py (-426)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_runner.py (-136)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_setups.py (-596)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_skipping.py (-154)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_suite.py (-363)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/test/test_unittest2_with.py (-148)
- (removed) lldb/third_party/Python/module/unittest2/unittest2/util.py (-105)
``````````diff
diff --git a/lldb/third_party/Python/module/progress/progress.py b/lldb/third_party/Python/module/progress/progress.py
deleted file mode 100644
index f844b9800c0192..00000000000000
--- a/lldb/third_party/Python/module/progress/progress.py
+++ /dev/null
@@ -1,181 +0,0 @@
-#!/usr/bin/env python
-
-import use_lldb_suite
-
-import sys
-import time
-
-
-class ProgressBar(object):
- """ProgressBar class holds the options of the progress bar.
- The options are:
- start State from which start the progress. For example, if start is
- 5 and the end is 10, the progress of this state is 50%
- end State in which the progress has terminated.
- width --
- fill String to use for "filled" used to represent the progress
- blank String to use for "filled" used to represent remaining space.
- format Format
- incremental
- """
- light_block = chr(0x2591).encode("utf-8")
- solid_block = chr(0x2588).encode("utf-8")
- solid_right_arrow = chr(0x25BA).encode("utf-8")
-
- def __init__(self,
- start=0,
- end=10,
- width=12,
- fill=chr(0x25C9).encode("utf-8"),
- blank=chr(0x25CC).encode("utf-8"),
- marker=chr(0x25CE).encode("utf-8"),
- format='[%(fill)s%(marker)s%(blank)s] %(progress)s%%',
- incremental=True):
- super(ProgressBar, self).__init__()
-
- self.start = start
- self.end = end
- self.width = width
- self.fill = fill
- self.blank = blank
- self.marker = marker
- self.format = format
- self.incremental = incremental
- self.step = 100 / float(width) # fix
- self.reset()
-
- def __add__(self, increment):
- increment = self._get_progress(increment)
- if 100 > self.progress + increment:
- self.progress += increment
- else:
- self.progress = 100
- return self
-
- def complete(self):
- self.progress = 100
- return self
-
- def __str__(self):
- progressed = int(self.progress / self.step) # fix
- fill = progressed * self.fill
- blank = (self.width - progressed) * self.blank
- return self.format % {
- 'fill': fill,
- 'blank': blank,
- 'marker': self.marker,
- 'progress': int(
- self.progress)}
-
- __repr__ = __str__
-
- def _get_progress(self, increment):
- return float(increment * 100) / self.end
-
- def reset(self):
- """Resets the current progress to the start point"""
- self.progress = self._get_progress(self.start)
- return self
-
-
-class AnimatedProgressBar(ProgressBar):
- """Extends ProgressBar to allow you to use it straighforward on a script.
- Accepts an extra keyword argument named `stdout` (by default use sys.stdout)
- and may be any file-object to which send the progress status.
- """
-
- def __init__(self,
- start=0,
- end=10,
- width=12,
- fill=chr(0x25C9).encode("utf-8"),
- blank=chr(0x25CC).encode("utf-8"),
- marker=chr(0x25CE).encode("utf-8"),
- format='[%(fill)s%(marker)s%(blank)s] %(progress)s%%',
- incremental=True,
- stdout=sys.stdout):
- super(
- AnimatedProgressBar,
- self).__init__(
- start,
- end,
- width,
- fill,
- blank,
- marker,
- format,
- incremental)
- self.stdout = stdout
-
- def show_progress(self):
- if hasattr(self.stdout, 'isatty') and self.stdout.isatty():
- self.stdout.write('\r')
- else:
- self.stdout.write('\n')
- self.stdout.write(str(self))
- self.stdout.flush()
-
-
-class ProgressWithEvents(AnimatedProgressBar):
- """Extends AnimatedProgressBar to allow you to track a set of events that
- cause the progress to move. For instance, in a deletion progress bar, you
- can track files that were nuked and files that the user doesn't have access to
- """
-
- def __init__(self,
- start=0,
- end=10,
- width=12,
- fill=chr(0x25C9).encode("utf-8"),
- blank=chr(0x25CC).encode("utf-8"),
- marker=chr(0x25CE).encode("utf-8"),
- format='[%(fill)s%(marker)s%(blank)s] %(progress)s%%',
- incremental=True,
- stdout=sys.stdout):
- super(
- ProgressWithEvents,
- self).__init__(
- start,
- end,
- width,
- fill,
- blank,
- marker,
- format,
- incremental,
- stdout)
- self.events = {}
-
- def add_event(self, event):
- if event in self.events:
- self.events[event] += 1
- else:
- self.events[event] = 1
-
- def show_progress(self):
- isatty = hasattr(self.stdout, 'isatty') and self.stdout.isatty()
- if isatty:
- self.stdout.write('\r')
- else:
- self.stdout.write('\n')
- self.stdout.write(str(self))
- if len(self.events) == 0:
- return
- self.stdout.write('\n')
- for key in list(self.events.keys()):
- self.stdout.write(str(key) + ' = ' + str(self.events[key]) + ' ')
- if isatty:
- self.stdout.write('\033[1A')
- self.stdout.flush()
-
-
-if __name__ == '__main__':
- p = AnimatedProgressBar(end=200, width=200)
-
- while True:
- p + 5
- p.show_progress()
- time.sleep(0.3)
- if p.progress == 100:
- break
- print() # new line
diff --git a/lldb/third_party/Python/module/unittest2/unittest2/__init__.py b/lldb/third_party/Python/module/unittest2/unittest2/__init__.py
deleted file mode 100644
index 14fea5a2599eec..00000000000000
--- a/lldb/third_party/Python/module/unittest2/unittest2/__init__.py
+++ /dev/null
@@ -1,78 +0,0 @@
-"""
-unittest2
-
-unittest2 is a backport of the new features added to the unittest testing
-framework in Python 2.7. It is tested to run on Python 2.4 - 2.6.
-
-To use unittest2 instead of unittest simply replace ``import unittest`` with
-``import unittest2``.
-
-
-Copyright (c) 1999-2003 Steve Purcell
-Copyright (c) 2003-2010 Python Software Foundation
-This module is free software, and you may redistribute it and/or modify
-it under the same terms as Python itself, so long as this copyright message
-and disclaimer are retained in their original form.
-
-IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
-SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
-THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGE.
-
-THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
-AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
-SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-"""
-
-import sys
-
-if sys.version_info[0] >= 3:
- # Python 3 doesn't have the builtin `cmp` function anymore
- cmp_ = lambda x, y: (x > y) - (x < y)
-else:
- cmp_ = cmp
-
-reversed_cmp_ = lambda x, y: -cmp_(x, y)
-
-__all__ = ['TestResult', 'TestCase', 'TestSuite',
- 'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main',
- 'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless',
- 'expectedFailure', 'TextTestResult', '__version__', 'collector']
-
-__version__ = '0.5.1'
-
-# Expose obsolete functions for backwards compatibility
-__all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases'])
-
-
-from unittest2.collector import collector
-from unittest2.result import TestResult
-from unittest2.case import (
- TestCase, FunctionTestCase, SkipTest, skip, skipIf,
- skipUnless, expectedFailure
-)
-from unittest2.suite import BaseTestSuite, TestSuite
-from unittest2.loader import (
- TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
- findTestCases
-)
-from unittest2.main import TestProgram, main, main_
-from unittest2.runner import TextTestRunner, TextTestResult
-
-try:
- from unittest2.signals import (
- installHandler, registerResult, removeResult, removeHandler
- )
-except ImportError:
- # Compatibility with platforms that don't have the signal module
- pass
-else:
- __all__.extend(['installHandler', 'registerResult', 'removeResult',
- 'removeHandler'])
-
-# deprecated
-_TextTestResult = TextTestResult
-
-__unittest = True
diff --git a/lldb/third_party/Python/module/unittest2/unittest2/__main__.py b/lldb/third_party/Python/module/unittest2/unittest2/__main__.py
deleted file mode 100644
index 04ed982df0fbeb..00000000000000
--- a/lldb/third_party/Python/module/unittest2/unittest2/__main__.py
+++ /dev/null
@@ -1,10 +0,0 @@
-"""Main entry point"""
-
-import sys
-if sys.argv[0].endswith("__main__.py"):
- sys.argv[0] = "unittest2"
-
-__unittest = True
-
-from unittest2.main import main_
-main_()
diff --git a/lldb/third_party/Python/module/unittest2/unittest2/case.py b/lldb/third_party/Python/module/unittest2/unittest2/case.py
deleted file mode 100644
index a24b9af98f40b6..00000000000000
--- a/lldb/third_party/Python/module/unittest2/unittest2/case.py
+++ /dev/null
@@ -1,1169 +0,0 @@
-"""Test case implementation"""
-
-import sys
-import difflib
-import pprint
-import re
-import unittest
-import warnings
-
-from unittest2 import result
-from unittest2.util import (
- safe_repr, safe_str, strclass,
- unorderable_list_difference
-)
-
-from unittest2.compatibility import wraps
-
-__unittest = True
-
-
-DIFF_OMITTED = ('\nDiff is %s characters long. '
- 'Set self.maxDiff to None to see it.')
-
-
-class SkipTest(Exception):
- """
- Raise this exception in a test to skip it.
-
- Usually you can use TestResult.skip() or one of the skipping decorators
- instead of raising this directly.
- """
-
-
-class _ExpectedFailure(Exception):
- """
- Raise this when a test is expected to fail.
-
- This is an implementation detail.
- """
-
- def __init__(self, exc_info, bugnumber=None):
- # can't use super because Python 2.4 exceptions are old style
- Exception.__init__(self)
- self.exc_info = exc_info
- self.bugnumber = bugnumber
-
-
-class _UnexpectedSuccess(Exception):
- """
- The test was supposed to fail, but it didn't!
- """
-
- def __init__(self, exc_info, bugnumber=None):
- # can't use super because Python 2.4 exceptions are old style
- Exception.__init__(self)
- self.exc_info = exc_info
- self.bugnumber = bugnumber
-
-
-def _id(obj):
- return obj
-
-
-def skip(reason):
- """
- Unconditionally skip a test.
- """
- def decorator(test_item):
- if not (
- isinstance(
- test_item,
- type) and issubclass(
- test_item,
- TestCase)):
- @wraps(test_item)
- def skip_wrapper(*args, **kwargs):
- raise SkipTest(reason)
- test_item = skip_wrapper
-
- test_item.__unittest_skip__ = True
- test_item.__unittest_skip_why__ = reason
- return test_item
- return decorator
-
-
-def skipIf(condition, reason):
- """
- Skip a test if the condition is true.
- """
- if condition:
- return skip(reason)
- return _id
-
-
-def skipUnless(condition, reason):
- """
- Skip a test unless the condition is true.
- """
- if not condition:
- return skip(reason)
- return _id
-
-
-def expectedFailure(bugnumber=None):
- if callable(bugnumber):
- @wraps(bugnumber)
- def expectedFailure_easy_wrapper(*args, **kwargs):
- try:
- bugnumber(*args, **kwargs)
- except Exception:
- raise _ExpectedFailure(sys.exc_info(), None)
- raise _UnexpectedSuccess(sys.exc_info(), None)
- return expectedFailure_easy_wrapper
- else:
- def expectedFailure_impl(func):
- @wraps(func)
- def wrapper(*args, **kwargs):
- try:
- func(*args, **kwargs)
- except Exception:
- raise _ExpectedFailure(sys.exc_info(), bugnumber)
- raise _UnexpectedSuccess(sys.exc_info(), bugnumber)
- return wrapper
- return expectedFailure_impl
-
-
-class _AssertRaisesContext(object):
- """A context manager used to implement TestCase.assertRaises* methods."""
-
- def __init__(self, expected, test_case, expected_regexp=None):
- self.expected = expected
- self.failureException = test_case.failureException
- self.expected_regexp = expected_regexp
-
- def __enter__(self):
- return self
-
- def __exit__(self, exc_type, exc_value, tb):
- if exc_type is None:
- try:
- exc_name = self.expected.__name__
- except AttributeError:
- exc_name = str(self.expected)
- raise self.failureException(
- "%s not raised" % (exc_name,))
- if not issubclass(exc_type, self.expected):
- # let unexpected exceptions pass through
- return False
- self.exception = exc_value # store for later retrieval
- if self.expected_regexp is None:
- return True
-
- expected_regexp = self.expected_regexp
- if isinstance(expected_regexp, str):
- expected_regexp = re.compile(expected_regexp)
- if not expected_regexp.search(str(exc_value)):
- raise self.failureException(
- '"%s" does not match "%s"' %
- (expected_regexp.pattern, str(exc_value)))
- return True
-
-
-class _TypeEqualityDict(object):
-
- def __init__(self, testcase):
- self.testcase = testcase
- self._store = {}
-
- def __setitem__(self, key, value):
- self._store[key] = value
-
- def __getitem__(self, key):
- value = self._store[key]
- if isinstance(value, str):
- return getattr(self.testcase, value)
- return value
-
- def get(self, key, default=None):
- if key in self._store:
- return self[key]
- return default
-
-
-class TestCase(unittest.TestCase):
- """A class whose instances are single test cases.
-
- By default, the test code itself should be placed in a method named
- 'runTest'.
-
- If the fixture may be used for many test cases, create as
- many test methods as are needed. When instantiating such a TestCase
- subclass, specify in the constructor arguments the name of the test method
- that the instance is to execute.
-
- Test authors should subclass TestCase for their own tests. Construction
- and deconstruction of the test's environment ('fixture') can be
- implemented by overriding the 'setUp' and 'tearDown' methods respectively.
-
- If it is necessary to override the __init__ method, the base class
- __init__ method must always be called. It is important that subclasses
- should not change the signature of their __init__ method, since instances
- of the classes are instantiated automatically by parts of the framework
- in order to be run.
- """
-
- # This attribute determines which exception will be raised when
- # the instance's assertion methods fail; test methods raising this
- # exception will be deemed to have 'failed' rather than 'errored'
-
- failureException = AssertionError
-
- # This attribute sets the maximum length of a diff in failure messages
- # by assert methods using difflib. It is looked up as an instance attribute
- # so can be configured by individual tests if required.
-
- maxDiff = 80 * 8
-
- # This attribute determines whether long messages (including repr of
- # objects used in assert methods) will be printed on failure in *addition*
- # to any explicit message passed.
-
- longMessage = True
-
- # Attribute used by TestSuite for classSetUp
-
- _classSetupFailed = False
-
- def __init__(self, methodName='runTest'):
- """Create an instance of the class that will use the named test
- method when executed. Raises a ValueError if the instance does
- not have a method with the specified name.
- """
- self._testMethodName = methodName
- self._resultForDoCleanups = None
- try:
- testMethod = getattr(self, methodName)
- except AttributeError:
- raise ValueError("no such test method in %s: %s" %
- (self.__class__, methodName))
- self._testMethodDoc = testMethod.__doc__
- self._cleanups = []
-
- # Map types to custom assertEqual functions that will compare
- # instances of said type in more detail to generate a more useful
- # error message.
- self._type_equality_funcs = _TypeEqualityDict(self)
- self.addTypeEqualityFunc(dict, 'assertDictEqual')
- self.addTypeEqualityFunc(list, 'assertListEqual')
- self.addTypeEqualityFunc(tuple, 'assertTupleEqual')
- self.addTypeEqualityFunc(set, 'assertSetEqual')
- self.addTypeEqualityFunc(frozenset, 'assertSetEqual')
- self.addTypeEqualityFunc(str, 'assertMultiLineEqual')
-
- def addTypeEqualityFunc(self, typeobj, function):
- """Add a type specific assertEqual style function to compare a type.
-
- This method is for use by TestCase subclasses that need to register
- their own type equality functions to provide nicer error messages.
-
- Args:
- typeobj: The data type to call this function on when both values
- are of the same type in assertEqual().
- function: The callable taking two arguments and an optional
- msg= argument that raises self.failureException with a
- useful error message when the two arguments are not equal.
- """
- self._type_equality_funcs[typeobj] = function
-
- def addCleanup(self, function, *args, **kwargs):
- """Add a function, with arguments, to be called when the test is
- completed. Functions added are called on a LIFO basis and are
- called after tearDown on test failure or success.
-
- Cleanup items are called even if setUp fails (unlike tearDown)."""
- self._cleanups.append((function, args, kwargs))
-
- def setUp(self):
- "Hook method for setting up the test fixture before exercising it."
-
- @classmethod
- def setUpClass(cls):
- "Hook method for setting up class fixture before running tests in the class."
-
- @classmethod
- def tearDownClass(cls):
- "Hook method for deconstructing the class fixture after running all tests in the class."
-
- def tearDown(self):
- "Hook method for deconstructing the test fixture after testing it."
-
- def countTestCases(self):
- return 1
-
- def defaultTestResult(self):
- return result.TestResult()
-
- def shortDescription(self):
- """Returns a one-line description of the test, or None if no
- description has been provided.
-
- The default implementation of this method returns the first line of
- the specified test method's docstring.
- """
- doc = self._testMethodDoc
- return doc and doc.split("\n")[0].strip() or None
-
- def id(self):
- return "%s.%s" % (strclass(self.__class__), self._testMethodName)
-
- def __eq__(self, other):
- if not isinstance(self, type(other)):
- return NotImplemented
-
- return self._testMethodName == other._testMethodName
-
- def __ne__(self, other):
- return not self == other
-
- def __hash__(self):
- return hash((type(self), self._testMethodName))
-
- def __str__(self):
- return "%s (%s)" % (self._testMethodName, strclass(self.__class__))
-
- def __repr__(self):
- retur...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/82670
More information about the lldb-commits
mailing list