-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checkDictionaryUpdate.py script and its tests
- Loading branch information
Showing
7 changed files
with
136 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import json | ||
import argparse | ||
|
||
# exit codes | ||
NO_CHANGES = 0 | ||
DATAFORMATS_CHANGED = 40 | ||
POLICY_VIOLATION = 41 | ||
|
||
def policyChecks(document): | ||
"""Check policies on dictionary definitions. Return True if checks are fine.""" | ||
# Contents to be added later | ||
return True | ||
|
||
def updatePolicyChecks(reference, update): | ||
"""Check policies on dictionary updates. Return True if checks are fine.""" | ||
# Contents to be added later | ||
return True | ||
|
||
def main(args): | ||
with open(args.baseline) as f: | ||
baseline = json.load(f) | ||
|
||
if args.pr is not None: | ||
with open(args.pr) as f: | ||
pr = json.load(f) | ||
pc1 = policyChecks(pr) | ||
if baseline != pr: | ||
pc2 = updatePolicyChecks(baseline, pr) | ||
if not (pc1 and pc2): | ||
return POLICY_VIOLATION | ||
|
||
print("Changes in persistable data formats") | ||
return DATAFORMATS_CHANGED | ||
if not pc1: | ||
return POLICY_VIOLATION | ||
else: | ||
if not policyChecks(baseline): | ||
return POLICY_VIOLATION | ||
|
||
return NO_CHANGES | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description=f"Check dictionary policies of the JSON output of edmDumpClassVersion. If one JSON document is given (--baseline; e.g. in IBs), only the dictionary definition policy checks are done. If two JSON documents are given (--baseline and --pr; e.g. in PR tests), the dictionary definition policy checks are done on the --pr document, and, in addition, if any persistable data formats are changed, additional checks are done to ensure the dictionary update is done properly. Exits with {NO_CHANGES} if there are no changes to persistent data formats. Exits with {DATAFORMATS_CHANGED} if persistent data formats are changed, and the update complies with data format policies. Exits with {POLICY_VIOLATION} if some data format policy is violated. Other exit codes (e.g. 1, 2) denote some failure in the script itself.") | ||
|
||
parser.add_argument("--baseline", required=True, type=str, help="JSON file for baseline") | ||
parser.add_argument("--pr", type=str, help="JSON file for baseline+PR") | ||
parser.add_argument("--transientDataFormatPackage", action="store_true", help="The JSON files are for a package that can have only transient data formats") | ||
|
||
args = parser.parse_args() | ||
sys.exit(main(args)) |
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
10 changes: 10 additions & 0 deletions
10
Utilities/ReleaseScripts/test/checkDictionaryUpdate/dumpClassVersion_baseline.json
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,10 @@ | ||
{ | ||
"edm::Wrapper<edmtest::reflection::IntObject>": { | ||
"checksum": 536952283, | ||
"version": 4 | ||
}, | ||
"edmtest::reflection::IntObject": { | ||
"checksum": 427917710, | ||
"version": 3 | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Utilities/ReleaseScripts/test/checkDictionaryUpdate/dumpClassVersion_newClass.json
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,14 @@ | ||
{ | ||
"edm::Wrapper<edmtest::reflection::IntObject>": { | ||
"checksum": 536952283, | ||
"version": 4 | ||
}, | ||
"edmtest::reflection::IntObject": { | ||
"checksum": 427917710, | ||
"version": 3 | ||
}, | ||
"edmtest::reflection::Another": { | ||
"checksum": 427917711, | ||
"version": 3 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Utilities/ReleaseScripts/test/checkDictionaryUpdate/dumpClassVersion_removeClass.json
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 @@ | ||
{ | ||
"edmtest::reflection::IntObject": { | ||
"checksum": 427917710, | ||
"version": 3 | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Utilities/ReleaseScripts/test/checkDictionaryUpdate/dumpClassVersion_versionUpdate.json
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,10 @@ | ||
{ | ||
"edm::Wrapper<edmtest::reflection::IntObject>": { | ||
"checksum": 536952283, | ||
"version": 4 | ||
}, | ||
"edmtest::reflection::IntObject": { | ||
"checksum": 3848242946, | ||
"version": 4 | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Utilities/ReleaseScripts/test/run_checkDictionaryUpdate.sh
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 @@ | ||
#!/bin/bash | ||
|
||
# possible exit codes | ||
SUCCESS=0 | ||
FAILURE="fail" | ||
DATAFORMATS_CHANGED=40 | ||
POLICY_VIOLATION=41 | ||
|
||
function die { echo Failure $1: status $2 ; exit $2 ; } | ||
function checkExitCode { | ||
if [ "$1" == "$FAILURE" ]; then | ||
if [[ "$2" = @("$SUCCESS"|"$DATAFORMATS_CHANGES"|"$POLICY_VIOLATIONS") ]]; then | ||
echo "checkDictionaryUpdate.py $3: expected failure exit code, got $2" | ||
exit 1 | ||
fi | ||
elif [ "$1" != "$2" ]; then | ||
echo "checkDictionaryUpdate.py $3: expected exit code $1, got $2" | ||
exit 1 | ||
fi | ||
} | ||
|
||
JSONPATH=${SCRAM_TEST_PATH}/checkDictionaryUpdate | ||
|
||
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json || die "checkDictionaryUpdate.py baseline" $? | ||
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_baseline.json || die "checkDictionaryUpdate.py baseline baseline" $? | ||
|
||
checkDictionaryUpdate.py | ||
RET=$? | ||
checkExitCode ${FAILURE} $RET "" | ||
|
||
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_versionUpdate.json | ||
RET=$? | ||
checkExitCode ${DATAFORMATS_CHANGED} $RET "baseline versionUpdate" | ||
|
||
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_newClass.json | ||
RET=$? | ||
checkExitCode ${DATAFORMATS_CHANGED} $RET "baseline newClass" | ||
|
||
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_removeClass.json | ||
RET=$? | ||
checkExitCode ${DATAFORMATS_CHANGED} $RET "baseline removeClass" |