-
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 --validate-data flag to run in validation mode
In this mode we validate the data against the table schema and report any errors. No RDFization is done, and a return code is propogated upon a failure to the shell.
- Loading branch information
1 parent
9fcfa8c
commit ea2e101
Showing
7 changed files
with
140 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(ns csv2rdf.main-test | ||
(:require [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#)})))) | ||
|
||
(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))) | ||
|
||
(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))) | ||
|
||
(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)))) |
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,6 @@ | ||
name,number | ||
one,1 | ||
two,two | ||
three,3 | ||
four,4 | ||
five,5 |
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,4 | ||
five,5 |
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,18 @@ | ||
{ | ||
"@context": "http://www.w3.org/ns/csvw", | ||
"url": "fail-2.csv", | ||
"tableSchema": { | ||
"columns": [ | ||
{ | ||
"name": "name", | ||
"datatype": "string", | ||
"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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name,number | ||
one,1 | ||
two,2 | ||
three,3 | ||
four,4 | ||
five,5 |