def test_adapt_infinite_dataset_fails(self):
    'Test that preproc layers fail if an infinite dataset is passed.'
    input_dataset = tf.data.Dataset.from_tensor_slices(np.array([[1], [2], [3], [4], [5], [0]])).repeat()
    layer = AddingPreprocessingLayer()
    if tf.executing_eagerly():
        with self.assertRaisesRegex(ValueError, 'infinite dataset'):
            layer.adapt(input_dataset)
    else:
        with self.assertRaisesRegex(ValueError, '.*infinite number of elements.*'):
            layer.adapt(input_dataset)
Test that preproc layers fail if an infinite dataset is passed.
def test_adapt_infinite_dataset_fails(self):
    
    input_dataset = tf.data.Dataset.from_tensor_slices(np.array([[1], [2], [3], [4], [5], [0]])).repeat()
    layer = AddingPreprocessingLayer()
    if tf.executing_eagerly():
        with self.assertRaisesRegex(ValueError, 'infinite dataset'):
            layer.adapt(input_dataset)
    else:
        with self.assertRaisesRegex(ValueError, '.*infinite number of elements.*'):
            layer.adapt(input_dataset)