Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
356d9bf8
Commit
356d9bf8
authored
9 years ago
by
Cam Saül
Browse files
Options
Downloads
Plain Diff
Merge branch 'more_unit_test_format_improvements' into annotation_2_0
parents
499d2de0
81c46667
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/metabase/test_setup.clj
+40
-18
40 additions, 18 deletions
test/metabase/test_setup.clj
with
40 additions
and
18 deletions
test/metabase/test_setup.clj
+
40
−
18
View file @
356d9bf8
(
ns
metabase.test-setup
"Functions that run before + after unit tests (setup DB, start web server, load test data)."
(
:require
[
clojure.java.io
:as
io
]
[
clojure.set
:as
set
]
[
clojure.tools.logging
:as
log
]
[
expectations
:refer
:all
]
(
metabase
[
core
:as
core
]
...
...
@@ -11,37 +12,58 @@
(
declare
clear-test-db
)
;; # SETTINGS
;; # ---------------------------------------- EXPECTAIONS FRAMEWORK SETTINGS ------------------------------
;; ## GENERAL SETTINGS
;; Don't run unit tests whenever JVM shuts down
;; it's pretty annoying to have our DB reset all the time
(
expectations/disable-run-on-shutdown
)
;; ## EXPECTATIONS FORMATTING OVERRIDES
;; Th
is
overrides the methods Expectations usually uses for printing
a
failed test
comparing two map
s.
;; Th
is is
basically the same as the original implementation, but colorize
s
and pretty-print
s
the
;; Th
ese
overrides the methods Expectations usually uses for printing failed tests.
;; Th
ese are
basically the same as the original implementation
s
, but
they
colorize and pretty-print the
;; output, which makes it an order of magnitude easier to read, especially for tests that compare a
;; lot of data, like Query Processor or API tests.
(
defn-
format-failure
[
e
a
str-e
str-a
]
{
:type
:fail
:expected-message
(
when-let
[
in-e
(
first
(
clojure.data/diff
e
a
))]
(
format
"\nin expected, not actual:\n%s"
(
u/pprint-to-str
'green
in-e
)))
:actual-message
(
when-let
[
in-a
(
first
(
clojure.data/diff
a
e
))]
(
format
"\nin actual, not expected:\n%s"
(
u/pprint-to-str
'red
in-a
)))
:raw
[
str-e
str-a
]
:result
[
"expected:\n"
(
u/pprint-to-str
'green
e
)
"was:\n"
(
u/pprint-to-str
'red
a
)]})
(
defmethod
compare-expr
:expectations/maps
[
e
a
str-e
str-a
]
(
let
[[
in-e
in-a
]
(
clojure.data/diff
e
a
)]
(
if
(
and
(
nil?
in-e
)
(
nil?
in-a
))
{
:type
:pass
}
{
:type
:fail
:expected-message
(
some->>
in-e
u/pprint-to-str
(
u/format-color
'green
"\nin expected, not actual:\n%s"
))
:actual-message
(
some->>
in-a
u/pprint-to-str
(
u/format-color
'red
"\nin actual, not expected:\n%s"
))
:raw
[
str-e
str-a
]
:result
[
"expected:\n"
(
u/pprint-to-str
'green
e
)
"\n was:\n"
(
u/pprint-to-str
'red
a
)]})))
;; # FUNCTIONS THAT GET RUN ON TEST SUITE START / STOP
(
format-failure
e
a
str-e
str-a
))))
(
defmethod
compare-expr
:expectations/sets
[
e
a
str-e
str-a
]
(
format-failure
e
a
str-e
str-a
))
(
defmethod
compare-expr
:expectations/sequentials
[
e
a
str-e
str-a
]
(
let
[
diff-fn
(
fn
[
e
a
]
(
seq
(
set/difference
(
set
e
)
(
set
a
))))]
(
assoc
(
format-failure
e
a
str-e
str-a
)
:message
(
cond
(
and
(
=
(
set
e
)
(
set
a
))
(
=
(
count
e
)
(
count
a
))
(
=
(
count
e
)
(
count
(
set
a
))))
"lists appear to contain the same items with different ordering"
(
and
(
=
(
set
e
)
(
set
a
))
(
<
(
count
e
)
(
count
a
)))
"some duplicate items in actual are not expected"
(
and
(
=
(
set
e
)
(
set
a
))
(
>
(
count
e
)
(
count
a
)))
"some duplicate items in expected are not actual"
(
<
(
count
e
)
(
count
a
))
"actual is larger than expected"
(
>
(
count
e
)
(
count
a
))
"expected is larger than actual"
))))
;; # ------------------------------ FUNCTIONS THAT GET RUN ON TEST SUITE START / STOP ------------------------------
(
defn
load-test-datasets
"Call `load-data!` on all the datasets we're testing against."
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment