csv-validation 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -95,7 +95,7 @@ dependencies = [
95
95
 
96
96
  [[package]]
97
97
  name = "csv_validation"
98
- version = "0.1.2"
98
+ version = "0.1.3"
99
99
  dependencies = [
100
100
  "csv",
101
101
  "flate2",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "csv_validation"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  edition = "2021"
5
5
  readme = "README.md"
6
6
 
@@ -14,14 +14,14 @@ csv = "1.3.1"
14
14
  flate2 = "1.1.0"
15
15
  log = "0.4.26"
16
16
  # abi3-py310 makes the wheels forward-compatible with 3.11, 3.12 ...
17
- pyo3 = { version = "0.23.3", features = ["abi3-py310"] }
17
+ pyo3 = { version = "0.23.5", features = ["abi3-py310"] }
18
18
  pyo3-log = "0.12.1"
19
19
  regex = "1.11.1"
20
20
  simple_logger = "5.0.0"
21
21
  yaml-rust2 = "0.10.0"
22
22
  serde = { version = "1.0.218", features = ["derive"] }
23
23
  redb = "3.1.0"
24
- tempfile = "3.10.1"
24
+ tempfile = "3.25.0"
25
25
 
26
26
  [features]
27
27
  extension-module = ["pyo3/extension-module"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: csv_validation
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -350,18 +350,29 @@ fn validate_column_names(reader: &mut Reader<Box<dyn Read>>, validations: &Vec<C
350
350
  debug!("Actual Column Names: {:?}", headers);
351
351
 
352
352
  if expected_column_names != headers {
353
+ info!("");
354
+ info!("COLUMNS VALIDATION");
355
+ info!("--------------------------------------------------");
353
356
  if expected_column_names.len() != headers.len() {
354
- info!("The number of columns in the CSV file doesn't match the validations:");
357
+ info!("[✖] The number of columns in the CSV file ({}) doesn't match the expected validations ({}):", headers.len(), expected_column_names.len());
355
358
  let expected_columns_set: HashSet<String> = expected_column_names.iter().cloned().collect();
356
359
  let headers_set: HashSet<String> = headers.iter().cloned().collect();
357
- info!("These column names in the CSV file were not expected: {:?}", headers_set.difference(&expected_columns_set));
358
- info!("These expected column names were missing in the CSV file: {:?}", expected_columns_set.difference(&headers_set));
360
+
361
+ let unexpected: Vec<_> = headers_set.difference(&expected_columns_set).collect();
362
+ if !unexpected.is_empty() {
363
+ info!(" - Unexpected columns in CSV: {:?}", unexpected);
364
+ }
365
+
366
+ let missing: Vec<_> = expected_columns_set.difference(&headers_set).collect();
367
+ if !missing.is_empty() {
368
+ info!(" - Missing expected columns: {:?}", missing);
369
+ }
359
370
  }
360
371
  else {
361
- info!("The CSV file has the same number of columns than the validations but some names are different:");
362
- for (expected_column, header) in zip(expected_column_names, headers) {
372
+ info!("[✖] The CSV file has the same number of columns but some names or order are different:");
373
+ for (i, (expected_column, header)) in expected_column_names.iter().zip(headers.iter()).enumerate() {
363
374
  if expected_column != header {
364
- info!("{:?} != {:?}", expected_column, header);
375
+ info!(" - Column {}: Expected {:?} but found {:?}", i + 1, expected_column, header);
365
376
  }
366
377
  }
367
378
  }
@@ -510,13 +521,17 @@ impl CSVValidator {
510
521
  let mut rdr = get_reader_from(file_path, self.separator)?;
511
522
 
512
523
  // First validation: Ensure column names and order are exactly as expected
513
- if validate_column_names(&mut rdr, &self.validations)? {
514
- info!("Columns names and order are correct");
515
- }
516
- else {
524
+ if !validate_column_names(&mut rdr, &self.validations)? {
517
525
  error!("Expected columns != File columns. Cannot continue with rest of the validations");
526
+
527
+ info!("");
528
+ info!("VALIDATION RESULT");
529
+ info!("--------------------------------------------------");
530
+ info!("[✖] FAIL: File {} DOESN'T match all validations", file_path);
531
+ info!("");
518
532
  return Ok(false);
519
533
  }
534
+ info!("Columns names and order are correct");
520
535
 
521
536
  // Second validation: If column names match, check if also the values match the validations
522
537
  let mut validation_summaries_map = build_validation_summaries_map(&self.validations);
@@ -817,6 +832,18 @@ mod tests {
817
832
  SimpleLogger::new().init().unwrap();
818
833
  }
819
834
 
835
+ #[test]
836
+ fn test_wrong_headers_same_count() {
837
+ let definition = String::from("
838
+ columns:
839
+ - name: First Column
840
+ - name: WRONG Second Column
841
+ - name: Third Column
842
+ ");
843
+ let validator = CSVValidator::from_string(&definition).unwrap();
844
+ assert!(!validator.validate("test/test_file.csv").unwrap());
845
+ }
846
+
820
847
  #[test]
821
848
  fn test_wrong_headers() {
822
849
  let definition = String::from("
File without changes
File without changes
File without changes