Skip to content

Commit

Permalink
Merge pull request #179 from yilei/push_up_to_405738888
Browse files Browse the repository at this point in the history
Push up to 405738888
  • Loading branch information
yilei authored Oct 27, 2021
2 parents 6c18fdd + fa5c66e commit 4a81f36
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 881 deletions.
27 changes: 0 additions & 27 deletions absl/testing/BUILD
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
licenses(["notice"]) # Apache 2.0

config_setting(
name = "osx",
constraint_values = ["//third_party/bazel_platforms/os:osx"],
)

config_setting(
name = "ios",
flag_values = {"//tools/cpp:cc_target_os": "apple"},
)

_absl_test_platform_deps = select({
":osx": [],
":ios": [],
# TODO(b/75911467): Remove after :osx works in host mode
"//tools/cc_target_os:platform_macos": [],
"//conditions:default": [
"//third_party/py/faulthandler",
"//third_party/py/readline", # Enables arrow keys and tab-completion in (pdb).
],
})

py_library(
name = "absltest",
srcs = ["absltest.py"],
Expand All @@ -33,7 +12,6 @@ py_library(
"//absl:app",
"//absl/flags",
"//absl/logging",
"//absl/third_party/unittest3_backport",
"@six_archive//:six",
],
)
Expand Down Expand Up @@ -72,7 +50,6 @@ py_library(
visibility = ["//visibility:public"],
deps = [
":_pretty_print_reporter",
"//absl/third_party/unittest3_backport",
"@six_archive//:six",
],
)
Expand All @@ -92,9 +69,6 @@ py_library(
name = "_pretty_print_reporter",
srcs = ["_pretty_print_reporter.py"],
srcs_version = "PY2AND3",
deps = [
"//absl/third_party/unittest3_backport",
],
)

py_library(
Expand Down Expand Up @@ -275,7 +249,6 @@ py_test(
":parameterized",
":xml_reporter",
"//absl/logging",
"//absl/third_party/unittest3_backport",
"@mock_archive//:mock",
"@six_archive//:six",
],
Expand Down
3 changes: 1 addition & 2 deletions absl/testing/_pretty_print_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
from __future__ import print_function

import unittest
from absl.third_party import unittest3_backport


class TextTestResult(unittest3_backport.TextTestResult):
class TextTestResult(unittest.TextTestResult):
"""TestResult class that provides the default text result formatting."""

def __init__(self, stream, descriptions, verbosity):
Expand Down
26 changes: 5 additions & 21 deletions absl/testing/absltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
from absl._collections_abc import abc
from absl.testing import _pretty_print_reporter
from absl.testing import xml_reporter
from absl.third_party import unittest3_backport
import six
from six.moves import urllib
from six.moves import xrange # pylint: disable=redefined-builtin
Expand All @@ -81,11 +80,8 @@
# Unbounded TypeVar for general usage
_T = typing.TypeVar('_T')

if six.PY2:
_OutcomeType = unittest3_backport.case._Outcome
else:
import unittest.case
_OutcomeType = unittest.case._Outcome # pytype: disable=module-attr
import unittest.case
_OutcomeType = unittest.case._Outcome # pytype: disable=module-attr


if six.PY3:
Expand Down Expand Up @@ -593,7 +589,7 @@ def __get__(self, obj, type_):
return func.__get__(obj, type_) # pytype: disable=attribute-error


class TestCase(unittest3_backport.TestCase):
class TestCase(unittest.TestCase):
"""Extension of unittest.TestCase providing more power."""

# When to cleanup files/directories created by our `create_tempfile()` and
Expand Down Expand Up @@ -1198,18 +1194,6 @@ def assertBetween(self, value, minv, maxv, msg=None):
self.assertTrue(minv <= value, msg)
self.assertTrue(maxv >= value, msg)

# Backport these names so that Py2 code can be written in Py3 style.
if six.PY2:

def assertRegex(self, *args, **kwargs):
return self.assertRegexpMatches(*args, **kwargs)

def assertRaisesRegex(self, *args, **kwargs):
return self.assertRaisesRegexp(*args, **kwargs)

def assertNotRegex(self, *args, **kwargs):
return self.assertNotRegexpMatches(*args, **kwargs)

def assertRegexMatch(self, actual_str, regexes, message=None):
r"""Asserts that at least one regex in regexes matches str.
Expand Down Expand Up @@ -1625,7 +1609,7 @@ def CheckEqual(a, b):
'%r unexpectedly less than %r' %
(b, a)))
self.assertLessEqual(a, b, msg)
self.assertLessEqual(b, a, msg)
self.assertLessEqual(b, a, msg) # pylint: disable=arguments-out-of-order
self.assertFalse(a > b,
self._formatMessage(msg,
'%r unexpectedly greater than %r' %
Expand All @@ -1635,7 +1619,7 @@ def CheckEqual(a, b):
'%r unexpectedly greater than %r' %
(b, a)))
self.assertGreaterEqual(a, b, msg)
self.assertGreaterEqual(b, a, msg)
self.assertGreaterEqual(b, a, msg) # pylint: disable=arguments-out-of-order

msg = kwargs.get('msg')

Expand Down
30 changes: 6 additions & 24 deletions absl/testing/tests/xml_reporter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from absl.testing import absltest
from absl.testing import parameterized
from absl.testing import xml_reporter
from absl.third_party import unittest3_backport
import mock
import six

Expand Down Expand Up @@ -198,10 +197,7 @@ def test_with_passing_subtest(self):
result = self._make_result((start_time, start_time, end_time, end_time))

test = MockTest('__main__.MockTest.passing_test')
if six.PY3:
subtest = unittest.case._SubTest(test, 'msg', None)
else:
subtest = unittest3_backport.case._SubTest(test, 'msg', None)
subtest = unittest.case._SubTest(test, 'msg', None)
result.startTestRun()
result.startTest(test)
result.addSubTest(test, subtest, None)
Expand Down Expand Up @@ -231,15 +227,7 @@ def test_with_passing_subtest_with_dots_in_parameter_name(self):
result = self._make_result((start_time, start_time, end_time, end_time))

test = MockTest('__main__.MockTest.passing_test')
if six.PY3:
subtest = unittest.case._SubTest(test, 'msg', {'case': 'a.b.c'})
else:
# In Python 3 subTest uses a ChainMap to hold the parameters, but ChainMap
# does not exist in Python 2, so a list of dict is used to simulate the
# behavior of a ChainMap. This is why a list is provided as a parameter
# here.
subtest = unittest3_backport.case._SubTest(test, 'msg',
[{'case': 'a.b.c'}])
subtest = unittest.case._SubTest(test, 'msg', {'case': 'a.b.c'})
result.startTestRun()
result.startTest(test)
result.addSubTest(test, subtest, None)
Expand Down Expand Up @@ -346,10 +334,7 @@ def test_with_failing_subtest(self):
result = self._make_result((start_time, start_time, end_time, end_time))

test = MockTest('__main__.MockTest.failing_test')
if six.PY3:
subtest = unittest.case._SubTest(test, 'msg', None)
else:
subtest = unittest3_backport.case._SubTest(test, 'msg', None)
subtest = unittest.case._SubTest(test, 'msg', None)
result.startTestRun()
result.startTest(test)
result.addSubTest(test, subtest, self.get_sample_failure())
Expand Down Expand Up @@ -412,10 +397,7 @@ def test_with_error_subtest(self):
result = self._make_result((start_time, start_time, end_time, end_time))

test = MockTest('__main__.MockTest.error_test')
if six.PY3:
subtest = unittest.case._SubTest(test, 'msg', None)
else:
subtest = unittest3_backport.case._SubTest(test, 'msg', None)
subtest = unittest.case._SubTest(test, 'msg', None)
result.startTestRun()
result.startTest(test)
result.addSubTest(test, subtest, self.get_sample_error())
Expand Down Expand Up @@ -900,10 +882,10 @@ def test_add_failure_during_stop_test(self):
result.startTestRun()
result.startTest(test)

# Replace parent stopTest method from unittest3_backport.TextTestResult with
# Replace parent stopTest method from unittest.TextTestResult with
# a version that calls self.addFailure().
with mock.patch.object(
unittest3_backport.TextTestResult,
unittest.TextTestResult,
'stopTest',
side_effect=lambda t: result.addFailure(t, self.get_sample_failure())):
# Run stopTest in a separate thread since we are looking to verify that
Expand Down
9 changes: 2 additions & 7 deletions absl/testing/xml_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import unittest
from xml.sax import saxutils
from absl.testing import _pretty_print_reporter
from absl.third_party import unittest3_backport
import six


Expand Down Expand Up @@ -166,8 +165,7 @@ def __init__(self, test):
full_class_name = match.group(2)
else:
class_name = unittest.util.strclass(test.__class__)
if ((six.PY3 and isinstance(test, unittest.case._SubTest)) or
(six.PY2 and isinstance(test, unittest3_backport.case._SubTest))):
if isinstance(test, unittest.case._SubTest):
# If the test case is a _SubTest, the real TestCase instance is
# available as _SubTest.test_case.
class_name = unittest.util.strclass(test.test_case.__class__)
Expand Down Expand Up @@ -249,10 +247,7 @@ def add_test_case_result(self, test_case_result):
# _ErrorHolder is a special case created by unittest for class / module
# level functions.
suite_name = test_case_result.full_class_name.rsplit('.')[-1]
if ((six.PY3 and
isinstance(test_case_result.test, unittest.case._SubTest)) or
(six.PY2 and
isinstance(test_case_result.test, unittest3_backport.case._SubTest))):
if isinstance(test_case_result.test, unittest.case._SubTest):
# If the test case is a _SubTest, the real TestCase instance is
# available as _SubTest.test_case.
suite_name = type(test_case_result.test.test_case).__name__
Expand Down
Empty file removed absl/third_party/__init__.py
Empty file.
46 changes: 0 additions & 46 deletions absl/third_party/unittest3_backport/BUILD

This file was deleted.

Loading

0 comments on commit 4a81f36

Please sign in to comment.