Skip to content

Commit e183396

Browse files
committed
tests
1 parent 0d93192 commit e183396

File tree

12 files changed

+144
-150
lines changed

12 files changed

+144
-150
lines changed

datafusion/common/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl Display for DataFusionError {
303303
write!(f, "This feature is not implemented: {desc}")
304304
}
305305
DataFusionError::Internal(ref desc) => {
306-
write!(f, "Internal error: {desc}. This was likely caused by a bug in DataFusion's \
306+
write!(f, "Internal error: {desc}.\nThis was likely caused by a bug in DataFusion's \
307307
code and we would welcome that you file an bug report in our issue tracker")
308308
}
309309
DataFusionError::Plan(ref desc) => {

datafusion/core/src/datasource/memory.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,11 @@ mod tests {
435435
],
436436
)?;
437437

438-
match MemTable::try_new(schema2, vec![vec![batch]]) {
439-
Err(DataFusionError::Plan(e)) => {
440-
assert_eq!("\"Mismatch between schema and batches\"", format!("{e:?}"))
441-
}
442-
_ => panic!("MemTable::new should have failed due to schema mismatch"),
443-
}
438+
let e = MemTable::try_new(schema2, vec![vec![batch]]).unwrap_err();
439+
assert_eq!(
440+
"Error during planning: Mismatch between schema and batches",
441+
e.strip_backtrace()
442+
);
444443

445444
Ok(())
446445
}
@@ -466,12 +465,11 @@ mod tests {
466465
],
467466
)?;
468467

469-
match MemTable::try_new(schema2, vec![vec![batch]]) {
470-
Err(DataFusionError::Plan(e)) => {
471-
assert_eq!("\"Mismatch between schema and batches\"", format!("{e:?}"))
472-
}
473-
_ => panic!("MemTable::new should have failed due to schema mismatch"),
474-
}
468+
let e = MemTable::try_new(schema2, vec![vec![batch]]).unwrap_err();
469+
assert_eq!(
470+
"Error during planning: Mismatch between schema and batches",
471+
e.strip_backtrace()
472+
);
475473

476474
Ok(())
477475
}

datafusion/expr/src/logical_plan/plan.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -2222,14 +2222,11 @@ digraph {
22222222
..Default::default()
22232223
};
22242224
let plan = test_plan();
2225-
let res = plan.visit(&mut visitor);
2226-
2227-
if let Err(DataFusionError::NotImplemented(e)) = res {
2228-
assert_eq!("Error in pre_visit", e);
2229-
} else {
2230-
panic!("Expected an error");
2231-
}
2232-
2225+
let res = plan.visit(&mut visitor).unwrap_err();
2226+
assert_eq!(
2227+
"This feature is not implemented: Error in pre_visit",
2228+
res.strip_backtrace()
2229+
);
22332230
assert_eq!(
22342231
visitor.inner.strings,
22352232
vec!["pre_visit Projection", "pre_visit Filter"]
@@ -2243,13 +2240,11 @@ digraph {
22432240
..Default::default()
22442241
};
22452242
let plan = test_plan();
2246-
let res = plan.visit(&mut visitor);
2247-
if let Err(DataFusionError::NotImplemented(e)) = res {
2248-
assert_eq!("Error in post_visit", e);
2249-
} else {
2250-
panic!("Expected an error");
2251-
}
2252-
2243+
let res = plan.visit(&mut visitor).unwrap_err();
2244+
assert_eq!(
2245+
"This feature is not implemented: Error in post_visit",
2246+
res.strip_backtrace()
2247+
);
22532248
assert_eq!(
22542249
visitor.inner.strings,
22552250
vec![

datafusion/expr/src/type_coercion/binary.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ fn null_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
779779
mod tests {
780780
use arrow::datatypes::DataType;
781781

782+
use datafusion_common::assert_contains;
782783
use datafusion_common::Result;
783-
use datafusion_common::{assert_contains, internal_err, DataFusionError};
784784

785785
use crate::Operator;
786786

@@ -791,15 +791,9 @@ mod tests {
791791
let result_type =
792792
get_input_types(&DataType::Float32, &Operator::Plus, &DataType::Utf8);
793793

794-
if let Err(DataFusionError::Plan(e)) = result_type {
795-
assert_eq!(
796-
e,
797-
"Cannot coerce arithmetic expression Float32 + Utf8 to valid types"
798-
);
799-
Ok(())
800-
} else {
801-
internal_err!("Coercion should have returned an DataFusionError::Internal")
802-
}
794+
let e = result_type.unwrap_err();
795+
assert_eq!(e.strip_backtrace(), "Error during planning: Cannot coerce arithmetic expression Float32 + Utf8 to valid types");
796+
Ok(())
803797
}
804798

805799
#[test]

datafusion/optimizer/src/analyzer/type_coercion.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,8 @@ mod test {
874874
.err()
875875
.unwrap();
876876
assert_eq!(
877-
r#"Context("type_coercion", Plan("Coercion from [Utf8] to the signature Uniform(1, [Int32]) failed."))"#,
878-
&format!("{err:?}")
877+
"type_coercion\ncaused by\nError during planning: Coercion from [Utf8] to the signature Uniform(1, [Int32]) failed.",
878+
err.strip_backtrace()
879879
);
880880
Ok(())
881881
}
@@ -944,8 +944,8 @@ mod test {
944944
.err()
945945
.unwrap();
946946
assert_eq!(
947-
r#"Context("type_coercion", Plan("Coercion from [Utf8] to the signature Uniform(1, [Float64]) failed."))"#,
948-
&format!("{err:?}")
947+
"type_coercion\ncaused by\nError during planning: Coercion from [Utf8] to the signature Uniform(1, [Float64]) failed.",
948+
err.strip_backtrace()
949949
);
950950
Ok(())
951951
}

datafusion/optimizer/src/optimizer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ mod tests {
504504
DFField { qualifier: Some(Bare { table: \"test\" }), field: Field { name: \"a\", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} } }, \
505505
DFField { qualifier: Some(Bare { table: \"test\" }), field: Field { name: \"b\", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} } }, \
506506
DFField { qualifier: Some(Bare { table: \"test\" }), field: Field { name: \"c\", data_type: UInt32, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} } }], \
507-
metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }. \
508-
This was likely caused by a bug in DataFusion's code \
507+
metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }.\
508+
\nThis was likely caused by a bug in DataFusion's code \
509509
and we would welcome that you file an bug report in our issue tracker",
510510
err.strip_backtrace()
511511
);

datafusion/physical-expr/src/aggregate/min_max.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1148,14 +1148,14 @@ mod tests {
11481148

11491149
let right = ScalarValue::Decimal128(Some(124), 10, 3);
11501150
let result = max(&left, &right);
1151-
let expect = DataFusionError::Internal(format!(
1151+
let err_msg = format!(
11521152
"MIN/MAX is not expected to receive scalars of incompatible types {:?}",
11531153
(Decimal128(Some(123), 10, 2), Decimal128(Some(124), 10, 3))
1154-
));
1155-
assert_eq!(
1156-
expect.strip_backtrace(),
1157-
result.unwrap_err().strip_backtrace()
11581154
);
1155+
let expect = DataFusionError::Internal(err_msg);
1156+
assert!(expect
1157+
.strip_backtrace()
1158+
.starts_with(&result.unwrap_err().strip_backtrace()));
11591159

11601160
// max batch
11611161
let array: ArrayRef = Arc::new(

datafusion/physical-expr/src/expressions/column.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,19 @@ mod test {
227227
let schema = Schema::new(vec![Field::new("foo", DataType::Utf8, true)]);
228228
let col = Column::new("id", 9);
229229
let error = col.data_type(&schema).expect_err("error").strip_backtrace();
230-
assert_eq!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
230+
assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
231231
but input schema only has 1 columns: [\"foo\"]. This was likely caused by a bug in \
232-
DataFusion's code and we would welcome that you file an bug report in our issue tracker",
233-
error)
232+
DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error))
234233
}
235234

236235
#[test]
237236
fn out_of_bounds_nullable() {
238237
let schema = Schema::new(vec![Field::new("foo", DataType::Utf8, true)]);
239238
let col = Column::new("id", 9);
240239
let error = col.nullable(&schema).expect_err("error").strip_backtrace();
241-
assert_eq!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
240+
assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
242241
but input schema only has 1 columns: [\"foo\"]. This was likely caused by a bug in \
243-
DataFusion's code and we would welcome that you file an bug report in our issue tracker",
244-
error)
242+
DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error))
245243
}
246244

247245
#[test]
@@ -251,10 +249,9 @@ mod test {
251249
let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(data)])?;
252250
let col = Column::new("id", 9);
253251
let error = col.evaluate(&batch).expect_err("error").strip_backtrace();
254-
assert_eq!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
252+
assert!("Internal error: PhysicalExpr Column references column 'id' at index 9 (zero-based) \
255253
but input schema only has 1 columns: [\"foo\"]. This was likely caused by a bug in \
256-
DataFusion's code and we would welcome that you file an bug report in our issue tracker",
257-
error);
254+
DataFusion's code and we would welcome that you file an bug report in our issue tracker".starts_with(&error));
258255
Ok(())
259256
}
260257
}

datafusion/physical-expr/src/functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ mod tests {
939939
match expr.evaluate(&batch) {
940940
Ok(_) => assert!(false, "expected error"),
941941
Err(error) => {
942-
assert_eq!(error.to_string(), expected_error.to_string());
942+
assert!(expected_error.strip_backtrace().starts_with(&error.strip_backtrace()));
943943
}
944944
}
945945
}

datafusion/sql/src/expr/identifier.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ mod test {
432432
let expected = "Internal error: Incorrect number of identifiers: 0. \
433433
This was likely caused by a bug in DataFusion's code and we would \
434434
welcome that you file an bug report in our issue tracker";
435-
assert_eq!(err.strip_backtrace(), expected);
435+
assert!(expected.starts_with(&err.strip_backtrace()));
436436

437437
let ids = vec!["a".to_string()];
438438
let (qualifier, column) = form_identifier(&ids)?;
@@ -470,7 +470,7 @@ mod test {
470470
let expected = "Internal error: Incorrect number of identifiers: 5. \
471471
This was likely caused by a bug in DataFusion's code and we would \
472472
welcome that you file an bug report in our issue tracker";
473-
assert_eq!(err.strip_backtrace(), expected);
473+
assert!(expected.starts_with(&err.strip_backtrace()));
474474

475475
Ok(())
476476
}

0 commit comments

Comments
 (0)