當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。