From f01e52124f96fcb4c895c7c89f379a87b1e9d208 Mon Sep 17 00:00:00 2001 From: Tomas Kacur Date: Wed, 26 Apr 2023 16:07:17 +0200 Subject: [PATCH 1/2] build test.check only for tests --- build.boot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.boot b/build.boot index 0e15b03..e796df3 100755 --- a/build.boot +++ b/build.boot @@ -10,7 +10,7 @@ [semantic-csv "0.2.0"] [org.clojure/data.csv "1.0.0"] [org.clojure/data.json "2.4.0"] - [org.clojure/test.check "0.9.0"] + [org.clojure/test.check "0.9.0" :scope "test"] [org.clojure/core.async "1.5.648"] [adzerk/boot-test "1.2.0" :scope "test"] [clj-http-fake "1.0.3"] From eb3c75bd0ba18a215f0c26a649dfbe3aae66dec2 Mon Sep 17 00:00:00 2001 From: Tomas Kacur Date: Wed, 26 Apr 2023 16:39:39 +0200 Subject: [PATCH 2/2] remove unnecessary tests --- build.boot | 2 +- src/keboola/facebook/api/parser.clj | 43 +++-------------- src/keboola/facebook/api/specs.clj | 57 ----------------------- test/keboola/facebook/api/parser_test.clj | 38 --------------- 4 files changed, 7 insertions(+), 133 deletions(-) delete mode 100644 src/keboola/facebook/api/specs.clj delete mode 100644 test/keboola/facebook/api/parser_test.clj diff --git a/build.boot b/build.boot index e796df3..4dcacc6 100755 --- a/build.boot +++ b/build.boot @@ -10,7 +10,7 @@ [semantic-csv "0.2.0"] [org.clojure/data.csv "1.0.0"] [org.clojure/data.json "2.4.0"] - [org.clojure/test.check "0.9.0" :scope "test"] + [org.clojure/test.check "1.1.0" :scope "test"] [org.clojure/core.async "1.5.648"] [adzerk/boot-test "1.2.0" :scope "test"] [clj-http-fake "1.0.3"] diff --git a/src/keboola/facebook/api/parser.clj b/src/keboola/facebook/api/parser.clj index f6875aa..190f5ae 100644 --- a/src/keboola/facebook/api/parser.clj +++ b/src/keboola/facebook/api/parser.clj @@ -1,11 +1,10 @@ (ns keboola.facebook.api.parser - (:require [clojure.spec.alpha :as s] - [keboola.facebook.api.specs :as ds] - [keboola.docker.runtime :refer [app-error]] - [clj-time.core :as t] - [clojure.data.json :as json] - [clj-time.format :refer [formatter unparse]] - [clojure.string :as string])) + (:require + [keboola.docker.runtime :refer [app-error]] + [clj-time.core :as t] + [clojure.data.json :as json] + [clj-time.format :refer [formatter unparse]] + [clojure.string :as string])) (defn relative-days-timestamp [days] (unparse (formatter "YYYY-MM-dd") (t/plus (t/now) (t/days (Integer/parseInt days))))) @@ -14,14 +13,6 @@ (string/replace fields-str #"%%days:-?\d+%%" #(relative-days-timestamp (re-find #"-?\d+" %)))) -(s/fdef nested-object? - :args (s/cat :object (s/or :nested (s/keys :req-un [::ds/data]) - :simple ::ds/fb-object)) - :ret boolean? - :fn (fn [val] - (if (= :simple (-> val :args :object first)) - (= false (-> val :ret)) - (= true (-> val :ret))))) (defn nested-object? "Returns true if objet is map and contains :data keyword" [object] @@ -34,10 +25,6 @@ :parent-id (or (:id row) (:parent-id params)) :fb-graph-node (str (:fb-graph-node params) "_" object-name)})) -(s/fdef get-nested-objects - :args (s/cat :body-data ::ds/data - :params ::ds/keboola) - :ret (s/coll-of map? :into [])) (defn get-nested-objects "Traverse body-data array and take out nested-object like structures. Return array of objects with keys :name :data :parent-id :fb-graph-node " @@ -58,11 +45,6 @@ memo)) [] body-data)) -(s/fdef flatten-value-object - :args (s/cat :key1 string? - :object-value (s/or :scalar ::ds/table-value :object ::ds/simple-object)) - :ret (s/* ::ds/key1-key2-value)) - (defn flatten-value-object "flattens object values and prepends and prepend key1" [key1 object-value] @@ -71,11 +53,6 @@ object-value) :else (list {:key1 key1 :key2 "" :value object-value}))) -(s/fdef flatten-array-value - :args (s/cat :item (s/or :scalar ::ds/table-value :object ::ds/complex-object) - :end_time ::ds/end_time) - :ret (s/* (s/merge (s/keys :req-un [::ds/end_time]) ::ds/key1-key2-value))) - (defn flatten-array-value [item end_time] (map #(assoc % :end_time end_time) @@ -109,19 +86,11 @@ (and (= array-name :media) (empty? array)) '() :else (app-error (str "unsuported array:" array-name array)))) -(s/fdef filter-scalars - :args (s/cat :row (s/map-of keyword? (s/or :scalar ::ds/table-value - :object map? - :seq sequential?))) - :ret (s/map-of keyword? ::ds/table-value)) (defn filter-scalars [row] (into {} (filter (fn [[k v]] (and (-> v map? not) (-> v sequential? not))) row))) -(s/fdef filter-flatten-objects - :args (s/cat :row ::ds/complex-object) - :ret (s/map-of keyword? ::ds/table-value)) (defn filter-flatten-objects [row] (let [simple-objects (filter (fn [[k v]] (and (-> v map?) (-> v nested-object? not))) row)] diff --git a/src/keboola/facebook/api/specs.clj b/src/keboola/facebook/api/specs.clj deleted file mode 100644 index 9e641c0..0000000 --- a/src/keboola/facebook/api/specs.clj +++ /dev/null @@ -1,57 +0,0 @@ -(ns keboola.facebook.api.specs - (:require [clojure.spec.alpha :as s] - [clojure.string :refer [blank?]] - [clojure.test.check.generators :as gen])) - -(defn not-blank? [s] ((complement blank?) s)) -(s/def ::key (s/and string? not-blank?)) - -(s/def ::table-value (s/or :int int? :string string?)) -(s/def ::id (s/and string? (complement blank?))) -(s/def ::fb-graph-node string?) -(s/def ::parent-id ::id) -(s/def ::table-name string?) - -(s/def ::keboola (s/keys :req-un [::parent-id ::fb-graph-node ::table-name])) -(s/def ::fb-table-row-core (s/keys :req-un [::id ::keboola])) - -(s/def ::fb-scalars (s/every-kv keyword? ::table-value :max-count 5)) - -(s/def ::fb-table-row - (s/with-gen - (s/or ::fb-scalars ::fb-table-row-core) - #(gen/fmap (partial apply into) (gen/tuple (s/gen ::fb-table-row-core) (s/gen ::fb-scalars))))) - -(s/def ::simple-object (s/map-of keyword? ::table-value :max-count 5)) -(s/def ::complex-object (s/map-of keyword? (s/or :scalar ::table-value :object ::simple-object ) :min-count 1 :max-count 5)) -(s/def ::multi-complex-object (s/map-of keyword? (s/or :scalar ::table-value :object ::complex-object))) - -(s/def :metric/key1 string?) -(s/def :metric/key2 string?) -(s/def :metric/value ::table-value) -(s/def ::key1-key2-value (s/keys :req-un [:metric/key1 :metric/key2 :metric/value])) -(s/def ::end_time string?) - -(s/def :insights/value ::complex-object) -(s/def ::insights (s/keys :req-un [:insights/value ::end_time])) - -(s/def ::nested-object (s/tuple keyword? (s/keys :req-un [::data]))) -(s/def ::fb-value (s/or :scalar (s/tuple keyword? ::table-value) - :nested ::nested-object - :key-values-object ::simple-object)) - -(s/def ::fb-object (s/coll-of ::fb-value :into {} :max-count 3 :min-count 1)) -(s/def ::data (s/coll-of ::fb-object - :min-count 1 - :max-count 6)) - - - -(s/def ::columns (s/every-kv string? - (s/coll-of (s/or :string string? :keyword keyword?) :distinct true))) - -(s/def parent-types (s/coll-of ::fb-graph-node :kind set? :distinct true)) - -(s/def ::cnt pos-int?) - -#_(s/exercise (s/coll-of (s/or :fb-scalar (s/tuple keyword? int?) :other (s/keys :req-un [::data])) :into {}) 5) diff --git a/test/keboola/facebook/api/parser_test.clj b/test/keboola/facebook/api/parser_test.clj deleted file mode 100644 index 5e5582e..0000000 --- a/test/keboola/facebook/api/parser_test.clj +++ /dev/null @@ -1,38 +0,0 @@ -(ns keboola.facebook.api.parser-test - (:require [keboola.facebook.api.parser :as sut] - [clojure.test :refer :all] - [clojure.spec.alpha :as s] - [keboola.test-utils.core :refer [test-and-check]] - [clojure.test.check.clojure-test :refer [defspec]] - [clojure.test.check.properties :as prop])) - -(deftest test-nested-object? - (is (test-and-check `sut/nested-object? 10))) - -(deftest test-get-nested-object - (is (test-and-check `sut/get-nested-objects 10))) - -(deftest test-flatten-value-object - (is (test-and-check `sut/flatten-value-object 20))) - -(deftest test-flatten-array-value - (is (test-and-check `sut/flatten-array-value 20))) - -(deftest test-filter-scalars - (is (test-and-check `sut/filter-scalars 20))) - -(deftest test-filter-flatten-objects - (is (test-and-check `sut/filter-flatten-objects 20))) - -#_(deftest test-flatten-array - (is (test-and-check `sut/flatten-array 10))) - -#_(defspec test-unfold-nested-sequence 4 - (prop/for-all [coll table-data-gen] - (let [test-value (sut/unfold-nested-sequence coll)] - (and - (not (reduced? test-value)) - (every? map? test-value))))) - -#_(defn foo-test [x] x) -#_(s/fdef foo-test :args (s/cat :x some?) :ret some?)