當前位置: 首頁>>代碼示例>>Python>>正文


Python util.assert_that方法代碼示例

本文整理匯總了Python中apache_beam.testing.util.assert_that方法的典型用法代碼示例。如果您正苦於以下問題:Python util.assert_that方法的具體用法?Python util.assert_that怎麽用?Python util.assert_that使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在apache_beam.testing.util的用法示例。


在下文中一共展示了util.assert_that方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_stats_pipeline_with_zero_examples

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def test_stats_pipeline_with_zero_examples(self):
    expected_result = text_format.Parse(
        """
        datasets {
          num_examples: 0
        }
        """, statistics_pb2.DatasetFeatureStatisticsList())
    with beam.Pipeline() as p:
      options = stats_options.StatsOptions(
          num_top_values=1,
          num_rank_histogram_buckets=1,
          num_values_histogram_buckets=2,
          num_histogram_buckets=1,
          num_quantiles_histogram_buckets=1,
          epsilon=0.001)
      result = (p | beam.Create([]) | stats_api.GenerateStatistics(options))
      util.assert_that(
          result,
          test_util.make_dataset_feature_stats_list_proto_equal_fn(
              self, expected_result)) 
開發者ID:tensorflow,項目名稱:data-validation,代碼行數:22,代碼來源:stats_api_test.py

示例2: test_stats_pipeline_with_sample_rate

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def test_stats_pipeline_with_sample_rate(self):
    record_batches = [
        pa.RecordBatch.from_arrays(
            [pa.array([np.linspace(1, 3000, 3000, dtype=np.int32)])], ['c']),
    ]

    with beam.Pipeline() as p:
      options = stats_options.StatsOptions(
          sample_rate=1.0,
          num_top_values=2,
          num_rank_histogram_buckets=2,
          num_values_histogram_buckets=2,
          num_histogram_buckets=2,
          num_quantiles_histogram_buckets=2,
          epsilon=0.001)
      result = (
          p | beam.Create(record_batches)
          | stats_api.GenerateStatistics(options))
      util.assert_that(
          result,
          test_util.make_dataset_feature_stats_list_proto_equal_fn(
              self, self._sampling_test_expected_result)) 
開發者ID:tensorflow,項目名稱:data-validation,代碼行數:24,代碼來源:stats_api_test.py

示例3: test_stats_impl

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def test_stats_impl(self,
                      record_batches,
                      options,
                      expected_result_proto_text,
                      schema=None):
    expected_result = text_format.Parse(
        expected_result_proto_text,
        statistics_pb2.DatasetFeatureStatisticsList())
    if schema is not None:
      options.schema = schema
    with beam.Pipeline() as p:
      result = (
          p | beam.Create(record_batches, reshuffle=False)
          | stats_impl.GenerateStatisticsImpl(options))
      util.assert_that(
          result,
          test_util.make_dataset_feature_stats_list_proto_equal_fn(
              self, expected_result)) 
開發者ID:tensorflow,項目名稱:data-validation,代碼行數:20,代碼來源:stats_impl_test.py

示例4: test_csv_decoder

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def test_csv_decoder(self,
                       input_lines,
                       expected_result,
                       column_names,
                       delimiter=',',
                       skip_blank_lines=True,
                       schema=None,
                       multivalent_columns=None,
                       secondary_delimiter=None):
    with beam.Pipeline() as p:
      result = (
          p | beam.Create(input_lines, reshuffle=False)
          | csv_decoder.DecodeCSV(
              column_names=column_names,
              delimiter=delimiter,
              skip_blank_lines=skip_blank_lines,
              schema=schema,
              multivalent_columns=multivalent_columns,
              secondary_delimiter=secondary_delimiter))
      util.assert_that(
          result,
          test_util.make_arrow_record_batches_equal_fn(self, expected_result)) 
開發者ID:tensorflow,項目名稱:data-validation,代碼行數:24,代碼來源:csv_decoder_test.py

示例5: testReadTransformFn

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def testReadTransformFn(self):
    path = self.get_temp_dir()
    # NOTE: we don't need to create or write to the transform_fn directory since
    # ReadTransformFn never inspects this directory.
    transform_fn_dir = os.path.join(
        path, tft.TFTransformOutput.TRANSFORM_FN_DIR)
    transformed_metadata_dir = os.path.join(
        path, tft.TFTransformOutput.TRANSFORMED_METADATA_DIR)
    metadata_io.write_metadata(test_metadata.COMPLETE_METADATA,
                               transformed_metadata_dir)

    with beam.Pipeline() as pipeline:
      saved_model_dir_pcoll, metadata = (
          pipeline | transform_fn_io.ReadTransformFn(path))
      beam_test_util.assert_that(
          saved_model_dir_pcoll,
          beam_test_util.equal_to([transform_fn_dir]),
          label='AssertSavedModelDir')
      # NOTE: metadata is currently read in a non-deferred manner.
      self.assertEqual(metadata, test_metadata.COMPLETE_METADATA) 
開發者ID:tensorflow,項目名稱:transform,代碼行數:22,代碼來源:transform_fn_io_test.py

示例6: testPrestoToExample

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def testPrestoToExample(self):
    with beam.Pipeline() as pipeline:
      examples = (
          pipeline | 'ToTFExample' >> executor._PrestoToExample(
              exec_properties={
                  'input_config':
                      json_format.MessageToJson(
                          example_gen_pb2.Input(),
                          preserving_proto_field_name=True),
                  'custom_config':
                      json_format.MessageToJson(
                          example_gen_pb2.CustomConfig(),
                          preserving_proto_field_name=True)
              },
              split_pattern='SELECT i, f, s FROM `fake`'))

      feature = {}
      feature['i'] = tf.train.Feature(int64_list=tf.train.Int64List(value=[1]))
      feature['f'] = tf.train.Feature(
          float_list=tf.train.FloatList(value=[2.0]))
      feature['s'] = tf.train.Feature(
          bytes_list=tf.train.BytesList(value=[tf.compat.as_bytes('abc')]))
      example_proto = tf.train.Example(
          features=tf.train.Features(feature=feature))
      util.assert_that(examples, util.equal_to([example_proto])) 
開發者ID:tensorflow,項目名稱:tfx,代碼行數:27,代碼來源:executor_test.py

示例7: testE2E

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def testE2E(self, attach_raw_records):
    raw_column_name = "raw_records" if attach_raw_records else None
    tfxio = self._MakeTFXIO(_SCHEMA, raw_column_name)

    def _AssertFn(record_batch_list):
      self.assertLen(record_batch_list, 1)
      record_batch = record_batch_list[0]
      self._ValidateRecordBatch(tfxio, record_batch, raw_column_name)
      self.assertTrue(record_batch.schema.equals(tfxio.ArrowSchema()))
      tensor_adapter = tfxio.TensorAdapter()
      dict_of_tensors = tensor_adapter.ToBatchTensors(record_batch)
      self.assertLen(dict_of_tensors, 4)
      self.assertIn("int_feature", dict_of_tensors)
      self.assertIn("float_feature", dict_of_tensors)
      self.assertIn("seq_string_feature", dict_of_tensors)
      self.assertIn("seq_int_feature", dict_of_tensors)

    p = beam.Pipeline()
    record_batch_pcoll = p | tfxio.BeamSource(batch_size=1000)
    beam_testing_util.assert_that(record_batch_pcoll, _AssertFn)
    pipeline_result = p.run()
    pipeline_result.wait_until_finish()
    telemetry_test_util.ValidateMetrics(
        self, pipeline_result, _TELEMETRY_DESCRIPTORS,
        "tf_sequence_example", "tfrecords_gzip") 
開發者ID:tensorflow,項目名稱:tfx-bsl,代碼行數:27,代碼來源:tf_sequence_example_record_test.py

示例8: testProjectionNoSequenceFeature

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def testProjectionNoSequenceFeature(self):
    tfxio = self._MakeTFXIO(_SCHEMA).Project(["int_feature"])
    arrow_schema = tfxio.ArrowSchema()
    self.assertLen(arrow_schema, 1)
    self.assertIn("int_feature", arrow_schema.names)
    def _AssertFn(record_batch_list):
      self.assertLen(record_batch_list, 1)
      record_batch = record_batch_list[0]
      self._ValidateRecordBatch(tfxio, record_batch)
      tensor_adapter = tfxio.TensorAdapter()
      dict_of_tensors = tensor_adapter.ToBatchTensors(record_batch)
      self.assertLen(dict_of_tensors, 1)
      self.assertIn("int_feature", dict_of_tensors)

    with beam.Pipeline() as p:
      # Setting the betch_size to make sure only one batch is generated.
      record_batch_pcoll = p | tfxio.BeamSource(
          batch_size=len(_EXAMPLES))
      beam_testing_util.assert_that(record_batch_pcoll, _AssertFn) 
開發者ID:tensorflow,項目名稱:tfx-bsl,代碼行數:21,代碼來源:tf_sequence_example_record_test.py

示例9: test_invalid_schema_type

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def test_invalid_schema_type(self):
    input_lines = ['1']
    column_names = ['f1']
    schema = text_format.Parse(
        """
              feature {
                name: "struct_feature"
                type: STRUCT
              }
              """, schema_pb2.Schema())
    with self.assertRaisesRegex(  # pylint: disable=g-error-prone-assert-raises
        ValueError, '.*Schema contains invalid type: STRUCT.*'):
      with beam.Pipeline() as p:
        result = (
            p | beam.Create(input_lines, reshuffle=False)
            | 'CSVToRecordBatch' >> csv_decoder.CSVToRecordBatch(
                column_names=column_names,
                schema=schema,
                desired_batch_size=1000))
        beam_test_util.assert_that(result, lambda _: None) 
開發者ID:tensorflow,項目名稱:tfx-bsl,代碼行數:22,代碼來源:csv_decoder_test.py

示例10: test_invalid_schema_missing_column

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def test_invalid_schema_missing_column(self):
    input_lines = ['1,2']
    column_names = ['f1', 'f2']
    schema = text_format.Parse(
        """
              feature {
                name: "f1"
                type: INT
                value_count {
                  min: 0
                  max: 2
                }
              }
              """, schema_pb2.Schema())
    with self.assertRaisesRegex(  # pylint: disable=g-error-prone-assert-raises
        ValueError, '.*Schema does not contain column.*'):
      with beam.Pipeline() as p:
        result = (
            p | beam.Create(input_lines, reshuffle=False)
            | 'CSVToRecordBatch' >> csv_decoder.CSVToRecordBatch(
                column_names=column_names,
                schema=schema,
                desired_batch_size=1000))
        beam_test_util.assert_that(result, lambda _: None) 
開發者ID:tensorflow,項目名稱:tfx-bsl,代碼行數:26,代碼來源:csv_decoder_test.py

示例11: testIncludeFilter

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def testIncludeFilter(self):
    with beam.Pipeline() as pipeline:
      got = (
          pipeline
          | 'Create' >> beam.Create([{
              'a': 1,
              'b': 2
          }])
          | 'EvaluateExtracts' >>
          analysis_table_evaluator.EvaluateExtracts(include=['a']))

      def check_result(got):
        try:
          self.assertEqual(got, [{'a': 1}])
        except AssertionError as err:
          raise util.BeamAssertException(err)

      util.assert_that(got[constants.ANALYSIS_KEY], check_result) 
開發者ID:tensorflow,項目名稱:model-analysis,代碼行數:20,代碼來源:analysis_table_evaluator_test.py

示例12: testExcludeFilter

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def testExcludeFilter(self):
    with beam.Pipeline() as pipeline:
      got = (
          pipeline
          | 'Create' >> beam.Create([{
              'a': 1,
              'b': 2
          }])
          | 'EvaluateExtracts' >>
          analysis_table_evaluator.EvaluateExtracts(exclude=['a']))

      def check_result(got):
        try:
          self.assertEqual(got, [{'b': 2}])
        except AssertionError as err:
          raise util.BeamAssertException(err)

      util.assert_that(got[constants.ANALYSIS_KEY], check_result) 
開發者ID:tensorflow,項目名稱:model-analysis,代碼行數:20,代碼來源:analysis_table_evaluator_test.py

示例13: testNoIncludeOrExcludeFilters

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def testNoIncludeOrExcludeFilters(self):
    with beam.Pipeline() as pipeline:
      got = (
          pipeline
          | 'Create' >> beam.Create([{
              constants.INPUT_KEY: 'input',
              'other': 2
          }])
          | 'EvaluateExtracts' >> analysis_table_evaluator.EvaluateExtracts())

      def check_result(got):
        try:
          self.assertEqual(got, [{'other': 2}])
        except AssertionError as err:
          raise util.BeamAssertException(err)

      util.assert_that(got[constants.ANALYSIS_KEY], check_result) 
開發者ID:tensorflow,項目名稱:model-analysis,代碼行數:19,代碼來源:analysis_table_evaluator_test.py

示例14: testIncludeFilter

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def testIncludeFilter(self):
    with beam.Pipeline() as pipeline:
      got = (
          pipeline
          | 'Create' >> beam.Create([{
              'a': 1,
              'b': 2,
              'c': 3,
              'd': 4
          }])
          | 'Filter' >> extractor.Filter(include=['a', 'c']))

      def check_result(got):
        try:
          self.assertEqual(got, [{'a': 1, 'c': 3}])
        except AssertionError as err:
          raise util.BeamAssertException(err)

      util.assert_that(got, check_result) 
開發者ID:tensorflow,項目名稱:model-analysis,代碼行數:21,代碼來源:extractor_test.py

示例15: testExludeFilter

# 需要導入模塊: from apache_beam.testing import util [as 別名]
# 或者: from apache_beam.testing.util import assert_that [as 別名]
def testExludeFilter(self):
    with beam.Pipeline() as pipeline:
      got = (
          pipeline
          | 'Create' >> beam.Create([{
              'a': 1,
              'b': 2,
              'c': 3,
              'd': 4
          }])
          | 'Filter' >> extractor.Filter(exclude=['b', 'd']))

      def check_result(got):
        try:
          self.assertEqual(got, [{'a': 1, 'c': 3}])
        except AssertionError as err:
          raise util.BeamAssertException(err)

      util.assert_that(got, check_result) 
開發者ID:tensorflow,項目名稱:model-analysis,代碼行數:21,代碼來源:extractor_test.py


注:本文中的apache_beam.testing.util.assert_that方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。