-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test and refactor incremental results
- Loading branch information
1 parent
72e60f4
commit 9d4bc83
Showing
3 changed files
with
138 additions
and
46 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,102 @@ | ||
from spectacles.runner import Runner | ||
|
||
|
||
def build_validation(validator): | ||
return { | ||
"validator": validator, | ||
"status": "failed", | ||
"tested": [ | ||
dict(model="ecommerce", explore="orders", passed=True), | ||
dict(model="ecommerce", explore="sessions", passed=True), | ||
dict(model="ecommerce", explore="users", passed=False), | ||
], | ||
"errors": [ | ||
dict( | ||
model="ecommerce", | ||
explore="users", | ||
test=None, | ||
message="An error occurred", | ||
metadata={}, | ||
) | ||
], | ||
} | ||
|
||
|
||
def test_incremental_same_results_should_not_have_errors(): | ||
main = build_validation("content") | ||
additional = build_validation("content") | ||
incremental = Runner._incremental_results(main, additional) | ||
assert incremental["status"] == "passed" | ||
assert incremental["errors"] == [] | ||
assert incremental["tested"] == [ | ||
dict(model="ecommerce", explore="orders", passed=True), | ||
dict(model="ecommerce", explore="sessions", passed=True), | ||
dict(model="ecommerce", explore="users", passed=True), | ||
] | ||
|
||
|
||
def test_incremental_with_fewer_errors_than_main(): | ||
main = build_validation("content") | ||
additional = build_validation("content") | ||
additional["tested"][2]["passed"] = True | ||
additional["errors"] = [] | ||
incremental = Runner._incremental_results(main, additional) | ||
assert incremental["status"] == "passed" | ||
assert incremental["errors"] == [] | ||
assert incremental["tested"] == [ | ||
dict(model="ecommerce", explore="orders", passed=True), | ||
dict(model="ecommerce", explore="sessions", passed=True), | ||
dict(model="ecommerce", explore="users", passed=True), | ||
] | ||
|
||
|
||
def test_incremental_with_more_errors_than_main(): | ||
main = build_validation("content") | ||
additional = build_validation("content") | ||
additional["tested"][1]["passed"] = False | ||
extra_errors = [ | ||
dict( | ||
model="ecommerce", | ||
explore="users", | ||
test=None, | ||
message="Another error occurred", | ||
metadata={}, | ||
), | ||
dict( | ||
model="ecommerce", | ||
explore="sessions", | ||
test=None, | ||
message="An error occurred", | ||
metadata={}, | ||
), | ||
] | ||
additional["errors"].extend(extra_errors) | ||
incremental = Runner._incremental_results(main, additional) | ||
assert incremental["status"] == "failed" | ||
assert incremental["errors"] == extra_errors | ||
assert incremental["tested"] == [ | ||
dict(model="ecommerce", explore="orders", passed=True), | ||
dict(model="ecommerce", explore="sessions", passed=False), | ||
dict(model="ecommerce", explore="users", passed=False), | ||
] | ||
|
||
|
||
def test_incremental_with_fewer_tested_explores_than_main(): | ||
main = build_validation("content") | ||
additional = build_validation("content") | ||
_ = additional["tested"].pop(0) | ||
extra_error = dict( | ||
model="ecommerce", | ||
explore="users", | ||
test=None, | ||
message="Another error occurred", | ||
metadata={}, | ||
) | ||
additional["errors"].append(extra_error) | ||
incremental = Runner._incremental_results(main, additional) | ||
assert incremental["status"] == "failed" | ||
assert incremental["errors"] == [extra_error] | ||
assert incremental["tested"] == [ | ||
dict(model="ecommerce", explore="sessions", passed=True), | ||
dict(model="ecommerce", explore="users", passed=False), | ||
] |