def METHOD_NAME(self):
    # Test that using the CSVLogger callback with the TerminateOnNaN
    # callback does not result in invalid CSVs.
    tmpdir = tempfile.TemporaryDirectory()
    csv_logfile = os.path.join(tmpdir.name, "csv_logger.csv")
    NUM_CLASSES = 2
    np.random.seed(1337)
    x_train = np.random.random((TRAIN_SAMPLES, INPUT_DIM))
    y_train = np.random.choice(np.arange(NUM_CLASSES), size=TRAIN_SAMPLES)
    x_test = np.random.random((TEST_SAMPLES, INPUT_DIM))
    y_test = np.random.choice(np.arange(NUM_CLASSES), size=TEST_SAMPLES)
    y_test = numerical_utils.to_categorical(y_test)
    y_train = numerical_utils.to_categorical(y_train)
    model = Sequential()
    initializer = initializers.Constant(value=1e5)
    for _ in range(5):
        model.add(
            layers.Dense(
                2,
                activation="relu",
                kernel_initializer=initializer,
            )
        )
    model.add(layers.Dense(NUM_CLASSES))
    model.compile(loss="mean_squared_error", optimizer="sgd")
    history = model.fit(
        x_train,
        y_train,
        batch_size=BATCH_SIZE,
        validation_data=(x_test, y_test),
        callbacks=[
            callbacks.TerminateOnNaN(),
            callbacks.CSVLogger(csv_logfile),
        ],
        epochs=20,
    )
    loss = history.history["loss"]
    self.assertEqual(len(loss), 1)
    self.assertTrue(np.isnan(loss[0]) or np.isinf(loss[0]))
    values = []
    with open(csv_logfile) as f:
        # On Windows, due to \r\n line ends, we may end up reading empty
        # lines after each line. Skip empty lines.
        values = [x for x in csv.reader(f) if x]
    self.assertIn("nan", values[-1], "NaN not logged in CSV Logger.")