Beispiel #1
0
    def assertFeatureEagerOnly(
        self,
        feature,
        shape,
        dtype,
        tests,
        serialized_info=None,
        test_tensor_spec=True,
        skip_feature_tests=False,
        test_attributes=None,
    ):
        """Test the given feature against the predicates."""

        with self._subTest('feature'):
            self._assert_feature(
                feature=feature,
                shape=shape,
                dtype=dtype,
                tests=tests,
                serialized_info=serialized_info,
                test_tensor_spec=test_tensor_spec,
                skip_feature_tests=skip_feature_tests,
                test_attributes=test_attributes,
            )
        # TODO(tfds): Remove `skip_feature_tests` after text encoders are removed
        if not skip_feature_tests:
            # Test the feature again to make sure that feature restored from config
            # behave similarly.
            with self._subTest('feature_roundtrip'):
                with test_utils.tmp_dir() as config_dir:
                    feature.save_config(config_dir)
                    new_feature = feature.from_config(config_dir)
                self._assert_feature(
                    feature=new_feature,
                    shape=shape,
                    dtype=dtype,
                    tests=tests,
                    serialized_info=serialized_info,
                    test_tensor_spec=test_tensor_spec,
                    skip_feature_tests=skip_feature_tests,
                    test_attributes=test_attributes,
                )
            with self._subTest('feature_proto_roundtrip'):
                with test_utils.tmp_dir() as config_dir:
                    feature_proto = feature.to_proto()
                    feature.save_metadata(config_dir, feature_name=None)
                    new_feature = feature_lib.FeatureConnector.from_proto(
                        feature_proto)
                    new_feature.load_metadata(config_dir, feature_name=None)
                    self._assert_feature(
                        feature=new_feature,
                        shape=shape,
                        dtype=dtype,
                        tests=tests,
                        serialized_info=serialized_info,
                        test_tensor_spec=test_tensor_spec,
                        skip_feature_tests=skip_feature_tests,
                        test_attributes=test_attributes,
                    )
    def assertFeature(self,
                      feature,
                      shape,
                      dtype,
                      tests,
                      serialized_info=None,
                      skip_feature_tests=False,
                      test_attributes=None):
        """Test the given feature against the predicates."""

        with self._subTest('feature'):
            self._assert_feature(
                feature=feature,
                shape=shape,
                dtype=dtype,
                tests=tests,
                serialized_info=serialized_info,
                skip_feature_tests=skip_feature_tests,
                test_attributes=test_attributes,
            )
        # TODO(tfds): Remove `skip_feature_tests` after text encoders are removed
        if not skip_feature_tests:
            # Test the feature again to make sure that feature restored from config
            # behave similarly.
            with self._subTest('feature_roundtrip'):
                with test_utils.tmp_dir() as config_dir:
                    feature.save_config(config_dir)
                    new_feature = feature.from_config(config_dir)
                self._assert_feature(
                    feature=new_feature,
                    shape=shape,
                    dtype=dtype,
                    tests=tests,
                    serialized_info=serialized_info,
                    skip_feature_tests=skip_feature_tests,
                    test_attributes=test_attributes,
                )
Beispiel #3
0
 def test_write_and_read(self, matrix):
     with test_utils.tmp_dir() as directory:
         path = os.path.join(directory, "matrix.mat")
         smallnorb_builder.write_binary_matrix(path, matrix)
         restored_matrix = smallnorb_tfds.read_binary_matrix(path)
         np.testing.assert_allclose(restored_matrix, matrix)