|
1 | 1 | (ns csv2rdf.main-test |
2 | | - (:require [csv2rdf.main :as sut] |
| 2 | + (:require [csv2rdf.logging :as logging] |
| 3 | + [csv2rdf.main :as sut] |
3 | 4 | [clojure.test :as t])) |
4 | 5 |
|
5 | 6 | ;; See issue 47 |
6 | 7 | ;; Resolving template property URIs with values containing spaces should work |
7 | 8 |
|
8 | | -(defmacro capture |
9 | | - "Capture return value of body and stdout, and return a hashmap |
10 | | - of :return-value and :stdout." |
11 | | - [body] |
12 | | - `(let [s# (new java.io.StringWriter)] |
13 | | - (binding [*out* s#] |
14 | | - (let [ret# ~body] |
15 | | - {:return-value ret# |
16 | | - :stdout (str s#)})))) |
| 9 | + |
| 10 | +(defn test-validate-data [tabular-file |
| 11 | + metadata-file |
| 12 | + failures] |
| 13 | + (let [is-valid? (empty? failures) |
| 14 | + warnings (atom []) |
| 15 | + errors (atom [])] |
| 16 | + (logging/with-logger |
| 17 | + (logging/memory-logger warnings errors) |
| 18 | + (t/is (= (sut/inner-main ["-t" tabular-file |
| 19 | + "-u" metadata-file |
| 20 | + "--validate-data"]) |
| 21 | + {:data-validation-errors? is-valid?})) |
| 22 | + (t/is (= @warnings failures)) |
| 23 | + (t/is (= @errors []))))) |
17 | 24 |
|
18 | 25 | (t/deftest inner-main-test-validate-data |
19 | | - (t/testing "--validate-data") |
20 | | - (let [{:keys [return-value stdout]} |
21 | | - (capture (sut/inner-main ["-t" "./test/examples/validation/success.csv" |
22 | | - "-u" "./test/examples/validation/named-numbers.json" |
23 | | - "--validate-data"]))] |
24 | | - (t/is (= {:data-validation-errors? false} return-value)) |
25 | | - (t/is (= "" stdout))) |
| 26 | + (t/testing "--validate-data" |
26 | 27 |
|
27 | | - (let [{:keys [return-value stdout]} |
28 | | - (capture (sut/inner-main ["-t" "./test/examples/validation/fail-1.csv" |
29 | | - "-u" "./test/examples/validation/named-numbers.json" |
30 | | - "--validate-data"]))] |
31 | | - (t/is (= {:data-validation-errors? true} return-value)) |
32 | | - (t/is (= "Row #3 col #2 (column 'number') has error: Cannot parse 'two' as type 'int': For input string: \"two\"\n" |
33 | | - stdout))) |
| 28 | + (test-validate-data |
| 29 | + "./test/examples/validation/success.csv" |
| 30 | + "./test/examples/validation/named-numbers.json" |
| 31 | + []) |
| 32 | + (test-validate-data |
| 33 | + "./test/examples/validation/fail-1.csv" |
| 34 | + "./test/examples/validation/named-numbers.json" |
| 35 | + ["Row #3 col #2 (column 'number') in file: fail-1.csv has error: Cannot parse 'two' as type 'int': For input string: \"two\""]) |
| 36 | + (test-validate-data |
| 37 | + "./test/examples/validation/fail-2.csv" |
| 38 | + "./test/examples/validation/named-numbers.json" |
| 39 | + ["Row #3 col #2 (column 'number') in file: fail-2.csv has error: Cannot parse 'three' as type 'int': For input string: \"three\""]) |
| 40 | + (test-validate-data |
| 41 | + "./test/examples/validation/fail-3.csv" |
| 42 | + "./test/examples/validation/named-numbers.json" |
| 43 | + ["Row #3 col #2 (column 'number') in file: fail-3.csv has error: Cannot parse 'three' as type 'int': For input string: \"three\"" |
| 44 | + "Row #4 col #2 (column 'number') in file: fail-3.csv has error: Cannot parse 'four' as type 'int': For input string: \"four\"" |
| 45 | + "Row #5 col #2 (column 'number') in file: fail-3.csv has error: Cannot parse 'five' as type 'int': For input string: \"five\""]) |
34 | 46 |
|
35 | | - (let [{:keys [return-value stdout]} |
36 | | - (capture (sut/inner-main ["-t" "./test/examples/validation/fail-2.csv" |
37 | | - "-u" "./test/examples/validation/named-numbers.json" |
38 | | - "--validate-data"]))] |
39 | | - (t/is (= {:data-validation-errors? true} return-value)) |
40 | | - (t/is (= "Row #3 col #2 (column 'number') has error: Cannot parse 'three' as type 'int': For input string: \"three\"\n" |
41 | | - stdout)))) |
| 47 | + (test-validate-data |
| 48 | + "./test/examples/validation/fail-4.csv" |
| 49 | + "./test/examples/validation/named-numbers.json" |
| 50 | + ["Row #3 col #2 (column 'number') in file: fail-4.csv has error: Column value required"]) |
| 51 | + (test-validate-data |
| 52 | + "./test/examples/validation/success.csv" |
| 53 | + "./test/examples/validation/named-numbers-incorrect-schema.json" |
| 54 | + ["Row #2 col #1 (column 'name') in file: success.csv has error: Cannot parse 'one' as type 'int': For input string: \"one\"" |
| 55 | + "Row #3 col #1 (column 'name') in file: success.csv has error: Cannot parse 'two' as type 'int': For input string: \"two\"" |
| 56 | + "Row #4 col #1 (column 'name') in file: success.csv has error: Cannot parse 'three' as type 'int': For input string: \"three\"" |
| 57 | + "Row #5 col #1 (column 'name') in file: success.csv has error: Cannot parse 'four' as type 'int': For input string: \"four\"" |
| 58 | + "Row #6 col #1 (column 'name') in file: success.csv has error: Cannot parse 'five' as type 'int': For input string: \"five\""]))) |
0 commit comments