Skip to content

Commit

Permalink
Add tests for error
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Jan 17, 2025
1 parent 01ea6e8 commit be5b863
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion datafusion/core/tests/dataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use datafusion::datasource::MemTable;
use datafusion::error::Result;
use datafusion::execution::context::SessionContext;
use datafusion::execution::session_state::SessionStateBuilder;
use datafusion::prelude::JoinType;
use datafusion::prelude::{AvroReadOptions, JoinType, NdJsonReadOptions};
use datafusion::prelude::{CsvReadOptions, ParquetReadOptions};
use datafusion::test_util::{parquet_test_data, populate_csv_partitions};
use datafusion::{assert_batches_eq, assert_batches_sorted_eq};
Expand Down Expand Up @@ -2778,3 +2778,67 @@ async fn test_alias_nested() -> Result<()> {
);
Ok(())
}

#[tokio::test]
async fn register_non_json_file() {
let ctx = SessionContext::new();
let err = ctx
.register_json(
"data",
"tests/data/test_binary.parquet",
NdJsonReadOptions::default(),
)
.await;
assert_contains!(
err.unwrap_err().to_string(),
"test_binary.parquet' does not match the expected extension '.json'"
);
}

#[tokio::test]
async fn register_non_csv_file() {
let ctx = SessionContext::new();
let err = ctx
.register_csv(
"data",
"tests/data/test_binary.parquet",
CsvReadOptions::default(),
)
.await;
assert_contains!(
err.unwrap_err().to_string(),
"test_binary.parquet' does not match the expected extension '.csv'"
);
}

#[tokio::test]
async fn register_non_avro_file() {
let ctx = SessionContext::new();
let err = ctx
.register_avro(
"data",
"tests/data/test_binary.parquet",
AvroReadOptions::default(),
)
.await;
assert_contains!(
err.unwrap_err().to_string(),
"test_binary.parquet' does not match the expected extension '.avro'"
);
}

#[tokio::test]
async fn register_non_parquet_file() {
let ctx = SessionContext::new();
let err = ctx
.register_parquet(
"data",
"tests/data/1.parquet",
ParquetReadOptions::default(),
)
.await;
assert_contains!(
err.unwrap_err().to_string(),
"1.json' does not match the expected extension '.parquet'"
);
}

0 comments on commit be5b863

Please sign in to comment.