Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate: bug fixes #151

Merged
merged 5 commits into from
Jan 24, 2022
Merged

Conversation

mhuang74
Copy link
Contributor

@mhuang74 mhuang74 commented Jan 24, 2022

  • fix output count with --fail-fast
  • gracefully handle when csv input has no headers, or headers don't match what's in schema file
  • change suffix to validation-errors.jsonl since it only contains errors
  • removed 1 layer of If statement and shifted code left, and seems diff is quite confused and highlights huge blocks of code in red
  • add integration test coverage for validation-error.jsonl contents
  • add Adur Public Toilets example to Validate.md
mhuang@twisted-linen:~/Projects/rust/qsv (validate-bug-fixes)$ cargo test validate 
    Finished test [optimized + debuginfo] target(s) in 0.37s
     Running unittests (target/debug/deps/qsv-eb284739a6602195)

running 5 tests
test cmd::validate::tests_for_csv_to_json_conversion::test_to_json_instance_cast_integer_error ... ok
test cmd::validate::tests_for_csv_to_json_conversion::test_to_json_instance ... ok
test cmd::validate::tests_for_schema_validation::test_validate_with_error ... ok
test cmd::validate::tests_for_schema_validation::test_validate_with_no_errors ... ok
test cmd::validate::test_load_json_via_url ... ok

test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 7 filtered out; finished in 1.84s

     Running unittests (target/debug/deps/qsvlite-8b35491d819e71f9)

running 5 tests
test cmd::validate::tests_for_csv_to_json_conversion::test_to_json_instance ... ok
test cmd::validate::tests_for_csv_to_json_conversion::test_to_json_instance_cast_integer_error ... ok
test cmd::validate::tests_for_schema_validation::test_validate_with_no_errors ... ok
test cmd::validate::tests_for_schema_validation::test_validate_with_error ... ok
test cmd::validate::test_load_json_via_url ... ok

test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 7 filtered out; finished in 0.33s

     Running tests/tests.rs (target/debug/deps/tests-3f2bfc931ef0ab18)

running 3 tests
test test_validate::validate_bad_csv ... ok
test test_validate::validate_good_csv ... ok
test test_validate::validate_adur_public_toilets_dataset_with_json_schema ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 624 filtered out; finished in 0.04s

@mhuang74 mhuang74 mentioned this pull request Jan 24, 2022
@jqnatividad jqnatividad merged commit 7205418 into jqnatividad:master Jan 24, 2022
@jqnatividad
Copy link
Owner

jqnatividad commented Jan 24, 2022

@mhuang74 went ahead and merged the PR, rancargo fmt, and corrected a small typo.

I like how you tweaked the JSON schema test to exercise jsonschema's validation capabilities. 💯 😄

Ran cargo clippy but decided not to apply the recommendations this time. I typically run both rustfmt and clippy as SOP.

warning: unnecessary closure used to substitute value for `Option::None`
   --> src\cmd\validate.rs:297:25
    |
297 |           let field_def = schema_properties
    |  _________________________^
298 | |             .get(&header_string)
299 | |             .unwrap_or_else(|| &Value::Null);
    | |____________________________________________^
    |
    = note: `#[warn(clippy::unnecessary_lazy_evaluations)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
help: use `unwrap_or` instead
    |
297 ~         let field_def = schema_properties
298 ~             .get(&header_string).unwrap_or(&Value::Null);
    |

warning: unnecessary closure used to substitute value for `Option::None`
   --> src\cmd\validate.rs:301:30
    |
301 |         let field_type_def = field_def.get("type").unwrap_or_else(|| &Value::Null);
    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `field_def.get("type").unwrap_or(&Value::Null)`     
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations

warning: unnecessary closure used to substitute value for `Option::None`
   --> src\cmd\validate.rs:303:25
    |
303 |         let json_type = field_type_def.as_str().unwrap_or_else(|| "string");
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `field_type_def.as_str().unwrap_or("string")`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations

warning: `qsv` (bin "qsvlite") generated 3 warnings (3 duplicates)
warning: `qsv` (bin "qsv") generated 3 warnings
    Finished dev [unoptimized + debuginfo] target(s) in 7.94s

If you decide not to follow the clippy recommendations, can you add #[allow(clippy:unnecessary_lazy_evaluations)] before those lines?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants