当前位置: 首页>>代码示例>>Python>>正文


Python parameterized.TestCase方法代码示例

本文整理汇总了Python中absl.testing.parameterized.TestCase方法的典型用法代码示例。如果您正苦于以下问题:Python parameterized.TestCase方法的具体用法?Python parameterized.TestCase怎么用?Python parameterized.TestCase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在absl.testing.parameterized的用法示例。


在下文中一共展示了parameterized.TestCase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _run_quantiles_combiner_test

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def _run_quantiles_combiner_test(test: absltest.TestCase,
                                 q_combiner: quantiles_util.QuantilesCombiner,
                                 batches: List[List[np.ndarray]],
                                 expected_result: np.ndarray):
  """Tests quantiles combiner."""
  summaries = [q_combiner.add_input(q_combiner.create_accumulator(),
                                    batch) for batch in batches]
  result = q_combiner.extract_output(q_combiner.merge_accumulators(summaries))
  test.assertEqual(result.dtype, expected_result.dtype)
  test.assertEqual(result.size, expected_result.size)
  for i in range(expected_result.size):
    test.assertAlmostEqual(result[i], expected_result[i]) 
开发者ID:tensorflow,项目名称:data-validation,代码行数:14,代码来源:quantiles_util_test.py

示例2: _assert_buckets_almost_equal

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def _assert_buckets_almost_equal(test: parameterized.TestCase,
                                 a: List[Tuple[float, float, float]],
                                 b: List[Tuple[float, float, float]]):
  """Check if the histogram buckets are almost equal."""
  test.assertEqual(len(a), len(b))
  for i in range(len(a)):
    test.assertAlmostEqual(a[i].low_value, b[i].low_value)
    test.assertAlmostEqual(a[i].high_value, b[i].high_value)
    test.assertAlmostEqual(a[i].sample_count, b[i].sample_count) 
开发者ID:tensorflow,项目名称:data-validation,代码行数:11,代码来源:quantiles_util_test.py

示例3: setUp

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def setUp(self):  # pylint: disable=invalid-name
    """Sets the seed for tensorflow and numpy."""
    super(TestCase, self).setUp()
    try:
      seed = flags.FLAGS.test_random_seed
    except flags.UnparsedFlagAccessError:
      seed = 301  # Default seed in case test_random_seed is not defined.
    tf.compat.v1.set_random_seed(seed)
    np.random.seed(seed)
    FLAGS[tfg_flags.TFG_ADD_ASSERTS_TO_GRAPH].value = True 
开发者ID:tensorflow,项目名称:graphics,代码行数:12,代码来源:test_case.py

示例4: setUp

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def setUp(self):
    super(TestCase, self).setUp()
    self._rng = npr.RandomState(zlib.adler32(self._testMethodName.encode()))

  # copied from jax.test_util 
开发者ID:google,项目名称:trax,代码行数:7,代码来源:test_util.py

示例5: _get_fatal_log_expectation

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def _get_fatal_log_expectation(testcase, message, include_stacktrace):
  """Returns the expectation for fatal logging tests.

  Args:
    testcase: The TestCase instance.
    message: The extra fatal logging message.
    include_stacktrace: Whether or not to include stacktrace.

  Returns:
    A callable, the expectation for fatal logging tests. It will be passed to
    FunctionalTest._exec_test as third items in the expected_logs list.
    See _exec_test's docstring for more information.
  """
  def assert_logs(logs):
    if os.name == 'nt':
      # On Windows, it also dumps extra information at the end, something like:
      # This application has requested the Runtime to terminate it in an
      # unusual way. Please contact the application's support team for more
      # information.
      logs = '\n'.join(logs.split('\n')[:-3])
    format_string = (
        'F1231 23:59:59.000000 12345 logging_functional_test_helper.py:175] '
        '%s message\n')
    expected_logs = format_string % message
    if include_stacktrace:
      expected_logs += 'Stack trace:\n'
    if six.PY3:
      faulthandler_start = 'Fatal Python error: Aborted'
      testcase.assertIn(faulthandler_start, logs)
      log_message = logs.split(faulthandler_start)[0]
      testcase.assertEqual(_munge_log(expected_logs), _munge_log(log_message))

  return assert_logs 
开发者ID:abseil,项目名称:abseil-py,代码行数:35,代码来源:logging_functional_test.py

示例6: __call__

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def __call__(self, *args, **kwargs):
    raise RuntimeError('You appear to be running a parameterized test case '
                       'without having inherited from parameterized.'
                       'TestCase. This is bad because none of '
                       'your test cases are actually being run. You may also '
                       'be using another decorator before the parameterized '
                       'one, in which case you should reverse the order.') 
开发者ID:abseil,项目名称:abseil-py,代码行数:9,代码来源:parameterized.py

示例7: __new__

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def __new__(mcs, class_name, bases, dct):
    test_method_ids = dct.setdefault('_test_method_ids', {})
    for name, obj in six.iteritems(dct.copy()):
      if (name.startswith(unittest.TestLoader.testMethodPrefix) and
          _non_string_or_bytes_iterable(obj)):
        if isinstance(obj, _ParameterizedTestIter):
          # Update the original test method name so it's more accurate.
          # The mismatch might happen when another decorator is used inside
          # the parameterized decrators, and the inner decorator doesn't
          # preserve its __name__.
          # `obj` might be a generator, not _ParameterizedTestIter.
          obj._original_name = name
        iterator = iter(obj)
        dct.pop(name)
        _update_class_dict_for_param_test_case(
            class_name, dct, test_method_ids, name, iterator)
    # If the base class is a subclass of parameterized.TestCase, inherit its
    # _test_method_ids too.
    for base in bases:
      # Check if the base has _test_method_ids first, then check if it's a
      # subclass of parameterized.TestCase. Otherwise when this is called for
      # the parameterized.TestCase definition itself, this raises because
      # itself is not defined yet. This works as long as absltest.TestCase does
      # not define _test_method_ids.
      if getattr(base, '_test_method_ids', None) and issubclass(base, TestCase):
        for test_method, test_method_id in six.iteritems(base._test_method_ids):
          # test_method may both exists in base and this class.
          # This class's method overrides base class's.
          # That's why it should only inherit it if it does not exist.
          test_method_ids.setdefault(test_method, test_method_id)

    return type.__new__(mcs, class_name, bases, dct) 
开发者ID:abseil,项目名称:abseil-py,代码行数:34,代码来源:parameterized.py

示例8: CoopTestCase

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def CoopTestCase(other_base_class):  # pylint: disable=invalid-name
  """Returns a new base class with a cooperative metaclass base.

  This enables the TestCase to be used in combination
  with other base classes that have custom metaclasses, such as
  mox.MoxTestBase.

  Only works with metaclasses that do not override type.__new__.

  Example:

    from absl.testing import parameterized

    class ExampleTest(parameterized.CoopTestCase(OtherTestCase)):
      ...

  Args:
    other_base_class: (class) A test case base class.

  Returns:
    A new class object.
  """
  metaclass = type(
      'CoopMetaclass',
      (other_base_class.__metaclass__,
       TestGeneratorMetaclass), {})
  return metaclass(
      'CoopTestCase',
      (other_base_class, TestCase), {}) 
开发者ID:abseil,项目名称:abseil-py,代码行数:31,代码来源:parameterized.py

示例9: test_addition

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def test_addition(self, op1, op2, result):
      self.arguments = (op1, op2, result)
      self.assertEqual(result, op1 + op2)

  # This class does not inherit from TestCase. 
开发者ID:abseil,项目名称:abseil-py,代码行数:7,代码来源:parameterized_test.py

示例10: test_generator_tests

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def test_generator_tests(self):
    with self.assertRaises(AssertionError):

      # This fails because the generated test methods share the same test id.
      class GeneratorTests(parameterized.TestCase):
        test_generator_method = (lambda self: None for _ in range(10))

      del GeneratorTests 
开发者ID:abseil,项目名称:abseil-py,代码行数:10,代码来源:parameterized_test.py

示例11: test_duplicate_named_test_fails

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def test_duplicate_named_test_fails(self):
    with self.assertRaises(parameterized.DuplicateTestNameError):

      class _(parameterized.TestCase):

        @parameterized.named_parameters(
            ('Interesting', 0),
            ('Interesting', 1),
        )
        def test_something(self, unused_obj):
          pass 
开发者ID:abseil,项目名称:abseil-py,代码行数:13,代码来源:parameterized_test.py

示例12: test_duplicate_dict_named_test_fails

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def test_duplicate_dict_named_test_fails(self):
    with self.assertRaises(parameterized.DuplicateTestNameError):

      class _(parameterized.TestCase):

        @parameterized.named_parameters(
            {'testcase_name': 'Interesting', 'unused_obj': 0},
            {'testcase_name': 'Interesting', 'unused_obj': 1},
        )
        def test_dict_something(self, unused_obj):
          pass 
开发者ID:abseil,项目名称:abseil-py,代码行数:13,代码来源:parameterized_test.py

示例13: test_named_test_with_no_name_fails

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def test_named_test_with_no_name_fails(self):
    with self.assertRaises(RuntimeError):

      class _(parameterized.TestCase):

        @parameterized.named_parameters(
            (0,),
        )
        def test_something(self, unused_obj):
          pass 
开发者ID:abseil,项目名称:abseil-py,代码行数:12,代码来源:parameterized_test.py

示例14: test_named_test_dict_with_no_name_fails

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def test_named_test_dict_with_no_name_fails(self):
    with self.assertRaises(RuntimeError):

      class _(parameterized.TestCase):

        @parameterized.named_parameters(
            {'unused_obj': 0},
        )
        def test_something(self, unused_obj):
          pass 
开发者ID:abseil,项目名称:abseil-py,代码行数:12,代码来源:parameterized_test.py

示例15: test_no_duplicate_decorations

# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import TestCase [as 别名]
def test_no_duplicate_decorations(self):
    with self.assertRaises(AssertionError):

      @parameterized.parameters(1, 2, 3, 4)
      class _(parameterized.TestCase):

        @parameterized.parameters(5, 6, 7, 8)
        def test_something(self, unused_obj):
          pass 
开发者ID:abseil,项目名称:abseil-py,代码行数:11,代码来源:parameterized_test.py


注:本文中的absl.testing.parameterized.TestCase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。