def test_write_load_anomalies_text(self): anomalies = text_format.Parse( """ anomaly_info { key: "feature_1" value { description: "Examples contain values missing from the " "schema." severity: ERROR short_description: "Unexpected string values" reason { type: ENUM_TYPE_UNEXPECTED_STRING_VALUES short_description: "Unexpected string values" description: "Examples contain values missing from the " "schema." } } }""", anomalies_pb2.Anomalies()) anomalies_path = os.path.join(FLAGS.test_tmpdir, 'anomalies.pbtxt') anomalies_util.write_anomalies_text(anomalies=anomalies, output_path=anomalies_path) loaded_anomalies = anomalies_util.load_anomalies_text( input_path=anomalies_path) self.assertEqual(anomalies, loaded_anomalies)
def test_write_anomalies_text_invalid_anomalies_input(self): with self.assertRaisesRegexp(TypeError, 'should be an Anomalies proto'): anomalies_util.write_anomalies_text({}, 'anomalies.pbtxt')