csv-validation 0.0.2__tar.gz → 0.0.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.
- {csv_validation-0.0.2 → csv_validation-0.0.3}/Cargo.lock +1 -1
- {csv_validation-0.0.2 → csv_validation-0.0.3}/Cargo.toml +1 -1
- {csv_validation-0.0.2 → csv_validation-0.0.3}/PKG-INFO +1 -1
- {csv_validation-0.0.2 → csv_validation-0.0.3}/src/lib.rs +26 -4
- csv_validation-0.0.3/test/test_validations_wrong_headers.yml +5 -0
- {csv_validation-0.0.2 → csv_validation-0.0.3}/.github/workflows/CI.yml +0 -0
- {csv_validation-0.0.2 → csv_validation-0.0.3}/.gitignore +0 -0
- {csv_validation-0.0.2 → csv_validation-0.0.3}/build.sh +0 -0
- {csv_validation-0.0.2 → csv_validation-0.0.3}/pyproject.toml +0 -0
- {csv_validation-0.0.2 → csv_validation-0.0.3}/test/test_file.csv +0 -0
- {csv_validation-0.0.2 → csv_validation-0.0.3}/test/test_file.csv.gz +0 -0
- {csv_validation-0.0.2 → csv_validation-0.0.3}/test/test_validations.yml +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
use std::collections::HashSet;
|
|
1
2
|
use std::fs;
|
|
2
3
|
use std::fs::File;
|
|
3
4
|
use std::io::{BufReader, Read};
|
|
@@ -140,15 +141,31 @@ fn get_validations(definition_path: &str) -> Vec<ColumnValidations> {
|
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
fn validate_column_names(reader: &mut Reader<Box<dyn Read>>, validations: &Vec<ColumnValidations>) -> bool {
|
|
143
|
-
let
|
|
144
|
+
let expected_column_names = validations.iter()
|
|
144
145
|
.map(|v| v.column_name.clone())
|
|
145
146
|
.collect::<Vec<String>>();
|
|
146
|
-
debug!("Expected Column Names: {:?}",
|
|
147
|
+
debug!("Expected Column Names: {:?}", expected_column_names);
|
|
147
148
|
|
|
148
|
-
let headers: Vec
|
|
149
|
+
let headers: Vec<String> = reader.headers().unwrap().iter().map(|s| String::from(s) ).collect();
|
|
149
150
|
debug!("Actual Column Names: {:?}", headers);
|
|
150
151
|
|
|
151
|
-
|
|
152
|
+
if expected_column_names != headers {
|
|
153
|
+
if expected_column_names.len() != headers.len() {
|
|
154
|
+
let expected_columns_set: HashSet<String> = expected_column_names.iter().cloned().collect();
|
|
155
|
+
let headers_set: HashSet<String> = headers.iter().cloned().collect();
|
|
156
|
+
debug!("File headers not in expected columns: {:?}", headers_set.difference(&expected_columns_set));
|
|
157
|
+
debug!("Columns in expected columns not in file headers: {:?}", expected_columns_set.difference(&headers_set));
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
for (expected_column, header) in zip(expected_column_names, headers) {
|
|
161
|
+
if expected_column != header {
|
|
162
|
+
debug!("{:?} != {:?}", expected_column, header);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
168
|
+
true
|
|
152
169
|
}
|
|
153
170
|
|
|
154
171
|
/// A Python module implemented in Rust.
|
|
@@ -178,4 +195,9 @@ mod tests {
|
|
|
178
195
|
fn test_validate_csv_gz() {
|
|
179
196
|
assert!(validate("test/test_file.csv.gz", "test/test_validations.yml").unwrap());
|
|
180
197
|
}
|
|
198
|
+
|
|
199
|
+
#[test]
|
|
200
|
+
fn test_wrong_headers() {
|
|
201
|
+
assert!(!validate("test/test_file.csv", "test/test_validations_wrong_headers.yml").unwrap());
|
|
202
|
+
}
|
|
181
203
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|