Skip to content

Commit 74d3603

Browse files
committed
tests
1 parent a0fcd9e commit 74d3603

File tree

4 files changed

+42
-34
lines changed

4 files changed

+42
-34
lines changed

datafusion/common/src/column.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ mod tests {
428428
)
429429
.expect_err("should've failed to find field");
430430
let expected = r#"Schema error: No field named z. Valid fields are t1.a, t1.b, t2.c, t2.d, t3.a, t3.b, t3.c, t3.d, t3.e."#;
431-
assert_eq!(err.to_string(), expected);
431+
assert!(err.to_string().start_with(expected));
432432

433433
// ambiguous column reference
434434
let col = Column::from_name("a");
@@ -439,7 +439,7 @@ mod tests {
439439
)
440440
.expect_err("should've found ambiguous field");
441441
let expected = "Schema error: Ambiguous reference to unqualified field a";
442-
assert_eq!(err.to_string(), expected);
442+
assert!(err.to_string().start_with(expected));
443443

444444
Ok(())
445445
}

datafusion/common/src/dfschema.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,9 @@ mod tests {
811811
let schema = DFSchema::try_from_qualified_schema("t1", &test_schema_1())?;
812812
// lookup with unqualified name "t1.c0"
813813
let err = schema.index_of_column(&col).unwrap_err();
814-
assert_eq!(
815-
err.to_string(),
816-
"Schema error: No field named \"t1.c0\". Valid fields are t1.c0, t1.c1.",
817-
);
814+
assert!(err.to_string().starts_with(
815+
"Schema error: No field named \"t1.c0\". Valid fields are t1.c0, t1.c1."
816+
));
818817
Ok(())
819818
}
820819

@@ -831,9 +830,9 @@ mod tests {
831830

832831
// lookup with unqualified name "t1.c0"
833832
let err = schema.index_of_column(&col).unwrap_err();
834-
assert_eq!(
835-
err.to_string(),
836-
"Schema error: No field named \"t1.c0\". Valid fields are t1.\"CapitalColumn\", t1.\"field.with.period\".",
833+
assert!(
834+
err.to_string().starts_with(
835+
"Schema error: No field named \"t1.c0\". Valid fields are t1.\"CapitalColumn\", t1.\"field.with.period\".")
837836
);
838837
Ok(())
839838
}
@@ -915,9 +914,9 @@ mod tests {
915914
let left = DFSchema::try_from(test_schema_1())?;
916915
let right = DFSchema::try_from(test_schema_1())?;
917916
let join = left.join(&right);
918-
assert_eq!(
919-
join.unwrap_err().to_string(),
920-
"Schema error: Schema contains duplicate unqualified field name c0",
917+
assert!(
918+
join.unwrap_err().to_string().starts_with(,
919+
"Schema error: Schema contains duplicate unqualified field name c0")
921920
);
922921
Ok(())
923922
}
@@ -993,12 +992,16 @@ mod tests {
993992

994993
let col = Column::from_qualified_name("t1.c0");
995994
let err = schema.index_of_column(&col).unwrap_err();
996-
assert_eq!(err.to_string(), "Schema error: No field named t1.c0.");
995+
assert!(err
996+
.to_string()
997+
.starts_with("Schema error: No field named t1.c0."));
997998

998999
// the same check without qualifier
9991000
let col = Column::from_name("c0");
10001001
let err = schema.index_of_column(&col).err().unwrap();
1001-
assert_eq!("Schema error: No field named c0.", err.to_string());
1002+
assert!(err
1003+
.to_string()
1004+
.starts_with("Schema error: No field named c0."));
10021005
}
10031006

10041007
#[test]

datafusion/common/src/error.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -507,16 +507,19 @@ mod test {
507507
#[test]
508508
fn arrow_error_to_datafusion() {
509509
let res = return_arrow_error().unwrap_err();
510-
assert_eq!(
511-
res.to_string(),
512-
"External error: Error during planning: foo"
510+
assert!(
511+
res.to_string().starts_with(,
512+
"External error: Error during planning: foo")
513513
);
514514
}
515515

516516
#[test]
517517
fn datafusion_error_to_arrow() {
518518
let res = return_datafusion_error().unwrap_err();
519-
assert_eq!(res.to_string(), "Arrow error: Schema error: bar");
519+
assert_eq!(res
520+
.to_string()
521+
.to_string()
522+
.starts_with("Arrow error: Schema error: bar"));
520523
}
521524

522525
#[test]
@@ -579,33 +582,35 @@ mod test {
579582
fn test_make_error_parse_input() {
580583
let res: Result<(), DataFusionError> = plan_err!("Err");
581584
let res = res.unwrap_err();
582-
assert_eq!(res.to_string(), "Error during planning: Err");
585+
assert!(res.to_string().starts_with("Error during planning: Err"));
583586

584587
let extra1 = "extra1";
585588
let extra2 = "extra2";
586589

587590
let res: Result<(), DataFusionError> = plan_err!("Err {} {}", extra1, extra2);
588591
let res = res.unwrap_err();
589-
assert_eq!(res.to_string(), "Error during planning: Err extra1 extra2");
592+
assert!(res
593+
.to_string()
594+
.starts_with("Error during planning: Err extra1 extra2"));
590595

591596
let res: Result<(), DataFusionError> =
592597
plan_err!("Err {:?} {:#?}", extra1, extra2);
593598
let res = res.unwrap_err();
594-
assert_eq!(
595-
res.to_string(),
596-
"Error during planning: Err \"extra1\" \"extra2\""
597-
);
599+
assert!(res
600+
.to_string()
601+
.starts_with("Error during planning: Err \"extra1\" \"extra2\""));
598602

599603
let res: Result<(), DataFusionError> = plan_err!("Err {extra1} {extra2}");
600604
let res = res.unwrap_err();
601-
assert_eq!(res.to_string(), "Error during planning: Err extra1 extra2");
605+
assert!(res
606+
.to_string()
607+
.starts_with("Error during planning: Err extra1 extra2"));
602608

603609
let res: Result<(), DataFusionError> = plan_err!("Err {extra1:?} {extra2:#?}");
604610
let res = res.unwrap_err();
605-
assert_eq!(
606-
res.to_string(),
607-
"Error during planning: Err \"extra1\" \"extra2\""
608-
);
611+
assert!(res
612+
.to_string()
613+
.starts_with("Error during planning: Err \"extra1\" \"extra2\""));
609614
}
610615

611616
/// Model what happens when implementing SendableRecordBatchStream:
@@ -626,7 +631,7 @@ mod test {
626631
let e = e.find_root();
627632

628633
// DataFusionError does not implement Eq, so we use a string comparison + some cheap "same variant" test instead
629-
assert_eq!(e.to_string(), exp.to_string(),);
634+
assert!(e.to_string().starts_with(exp.to_string()));
630635
assert_eq!(std::mem::discriminant(e), std::mem::discriminant(&exp),)
631636
}
632637
}

datafusion/common/src/scalar.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,9 +3239,9 @@ mod tests {
32393239
let int_value = ScalarValue::Int32(Some(i32::MAX));
32403240
let int_value_2 = ScalarValue::Int32(Some(i32::MIN));
32413241
let err = int_value.sub_checked(&int_value_2).unwrap_err().to_string();
3242-
assert_eq!(
3243-
err,
3244-
"Arrow error: Compute error: Overflow happened on: 2147483647 - -2147483648"
3242+
assert!(
3243+
err.starts_with(,
3244+
"Arrow error: Compute error: Overflow happened on: 2147483647 - -2147483648")
32453245
)
32463246
}
32473247

@@ -3259,7 +3259,7 @@ mod tests {
32593259
let int_value = ScalarValue::Int64(Some(i64::MAX));
32603260
let int_value_2 = ScalarValue::Int64(Some(i64::MIN));
32613261
let err = int_value.sub_checked(&int_value_2).unwrap_err().to_string();
3262-
assert_eq!(err, "Arrow error: Compute error: Overflow happened on: 9223372036854775807 - -9223372036854775808")
3262+
assert!(err.starts_with("Arrow error: Compute error: Overflow happened on: 9223372036854775807 - -9223372036854775808"))
32633263
}
32643264

32653265
#[test]

0 commit comments

Comments
 (0)