-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extra context to the validation error logging
Also: * ensure it is only printed once * add a couple of extra test cases
- Loading branch information
1 parent
5dc1bf3
commit 393e1eb
Showing
8 changed files
with
116 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,58 @@ | ||
(ns csv2rdf.main-test | ||
(:require [csv2rdf.main :as sut] | ||
(:require [csv2rdf.logging :as logging] | ||
[csv2rdf.main :as sut] | ||
[clojure.test :as t])) | ||
|
||
;; See issue 47 | ||
;; Resolving template property URIs with values containing spaces should work | ||
|
||
(defmacro capture | ||
"Capture return value of body and stdout, and return a hashmap | ||
of :return-value and :stdout." | ||
[body] | ||
`(let [s# (new java.io.StringWriter)] | ||
(binding [*out* s#] | ||
(let [ret# ~body] | ||
{:return-value ret# | ||
:stdout (str s#)})))) | ||
|
||
(defn test-validate-data [tabular-file | ||
metadata-file | ||
failures] | ||
(let [is-valid? (empty? failures) | ||
warnings (atom []) | ||
errors (atom [])] | ||
(logging/with-logger | ||
(logging/memory-logger warnings errors) | ||
(t/is (= (sut/inner-main ["-t" tabular-file | ||
"-u" metadata-file | ||
"--validate-data"]) | ||
{:data-validation-errors? is-valid?})) | ||
(t/is (= @warnings failures)) | ||
(t/is (= @errors []))))) | ||
|
||
(t/deftest inner-main-test-validate-data | ||
(t/testing "--validate-data") | ||
(let [{:keys [return-value stdout]} | ||
(capture (sut/inner-main ["-t" "./test/examples/validation/success.csv" | ||
"-u" "./test/examples/validation/named-numbers.json" | ||
"--validate-data"]))] | ||
(t/is (= {:data-validation-errors? false} return-value)) | ||
(t/is (= "" stdout))) | ||
(t/testing "--validate-data" | ||
|
||
(let [{:keys [return-value stdout]} | ||
(capture (sut/inner-main ["-t" "./test/examples/validation/fail-1.csv" | ||
"-u" "./test/examples/validation/named-numbers.json" | ||
"--validate-data"]))] | ||
(t/is (= {:data-validation-errors? true} return-value)) | ||
(t/is (= "Row #3 col #2 (column 'number') has error: Cannot parse 'two' as type 'int': For input string: \"two\"\n" | ||
stdout))) | ||
(test-validate-data | ||
"./test/examples/validation/success.csv" | ||
"./test/examples/validation/named-numbers.json" | ||
[]) | ||
(test-validate-data | ||
"./test/examples/validation/fail-1.csv" | ||
"./test/examples/validation/named-numbers.json" | ||
["Row #3 col #2 (column 'number') in file: fail-1.csv has error: Cannot parse 'two' as type 'int': For input string: \"two\""]) | ||
(test-validate-data | ||
"./test/examples/validation/fail-2.csv" | ||
"./test/examples/validation/named-numbers.json" | ||
["Row #3 col #2 (column 'number') in file: fail-2.csv has error: Cannot parse 'three' as type 'int': For input string: \"three\""]) | ||
(test-validate-data | ||
"./test/examples/validation/fail-3.csv" | ||
"./test/examples/validation/named-numbers.json" | ||
["Row #3 col #2 (column 'number') in file: fail-3.csv has error: Cannot parse 'three' as type 'int': For input string: \"three\"" | ||
"Row #4 col #2 (column 'number') in file: fail-3.csv has error: Cannot parse 'four' as type 'int': For input string: \"four\"" | ||
"Row #5 col #2 (column 'number') in file: fail-3.csv has error: Cannot parse 'five' as type 'int': For input string: \"five\""]) | ||
|
||
(let [{:keys [return-value stdout]} | ||
(capture (sut/inner-main ["-t" "./test/examples/validation/fail-2.csv" | ||
"-u" "./test/examples/validation/named-numbers.json" | ||
"--validate-data"]))] | ||
(t/is (= {:data-validation-errors? true} return-value)) | ||
(t/is (= "Row #3 col #2 (column 'number') has error: Cannot parse 'three' as type 'int': For input string: \"three\"\n" | ||
stdout)))) | ||
(test-validate-data | ||
"./test/examples/validation/fail-4.csv" | ||
"./test/examples/validation/named-numbers.json" | ||
["Row #3 col #2 (column 'number') in file: fail-4.csv has error: Column value required"]) | ||
(test-validate-data | ||
"./test/examples/validation/success.csv" | ||
"./test/examples/validation/named-numbers-incorrect-schema.json" | ||
["Row #2 col #1 (column 'name') in file: success.csv has error: Cannot parse 'one' as type 'int': For input string: \"one\"" | ||
"Row #3 col #1 (column 'name') in file: success.csv has error: Cannot parse 'two' as type 'int': For input string: \"two\"" | ||
"Row #4 col #1 (column 'name') in file: success.csv has error: Cannot parse 'three' as type 'int': For input string: \"three\"" | ||
"Row #5 col #1 (column 'name') in file: success.csv has error: Cannot parse 'four' as type 'int': For input string: \"four\"" | ||
"Row #6 col #1 (column 'name') in file: success.csv has error: Cannot parse 'five' as type 'int': For input string: \"five\""]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name,number | ||
one,1 | ||
3,three | ||
four,four | ||
five,five |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name,number | ||
one,1 | ||
2, |
17 changes: 17 additions & 0 deletions
17
test/examples/validation/named-numbers-incorrect-schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"@context": "http://www.w3.org/ns/csvw", | ||
"tableSchema": { | ||
"columns": [ | ||
{ | ||
"name": "name", | ||
"datatype": "int", | ||
"required": true | ||
}, | ||
{ | ||
"name": "number", | ||
"required": true, | ||
"datatype": "int" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
{ | ||
"@context": "http://www.w3.org/ns/csvw", | ||
"url": "fail-2.csv", | ||
"tableSchema": { | ||
"columns": [ | ||
{ | ||
|