Skip to content

Commit 444d6a3

Browse files
committed
Add checkDictionaryUpdate.py script and its tests
1 parent cfe793c commit 444d6a3

File tree

7 files changed

+136
-0
lines changed

7 files changed

+136
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
import json
5+
import argparse
6+
7+
# exit codes
8+
NO_CHANGES = 0
9+
DATAFORMATS_CHANGED = 40
10+
POLICY_VIOLATION = 41
11+
12+
def policyChecks(document):
13+
"""Check policies on dictionary definitions. Return True if checks are fine."""
14+
# Contents to be added later
15+
return True
16+
17+
def updatePolicyChecks(reference, update):
18+
"""Check policies on dictionary updates. Return True if checks are fine."""
19+
# Contents to be added later
20+
return True
21+
22+
def main(args):
23+
with open(args.baseline) as f:
24+
baseline = json.load(f)
25+
26+
if args.pr is not None:
27+
with open(args.pr) as f:
28+
pr = json.load(f)
29+
pc1 = policyChecks(pr)
30+
if baseline != pr:
31+
pc2 = updatePolicyChecks(baseline, pr)
32+
if not (pc1 and pc2):
33+
return POLICY_VIOLATION
34+
35+
print("Changes in persistable data formats")
36+
return DATAFORMATS_CHANGED
37+
if not pc1:
38+
return POLICY_VIOLATION
39+
else:
40+
if not policyChecks(baseline):
41+
return POLICY_VIOLATION
42+
43+
return NO_CHANGES
44+
45+
if __name__ == "__main__":
46+
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.")
47+
48+
parser.add_argument("--baseline", required=True, type=str, help="JSON file for baseline")
49+
parser.add_argument("--pr", type=str, help="JSON file for baseline+PR")
50+
parser.add_argument("--transientDataFormatPackage", action="store_true", help="The JSON files are for a package that can have only transient data formats")
51+
52+
args = parser.parse_args()
53+
sys.exit(main(args))

Utilities/ReleaseScripts/test/BuildFile.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
</test>
1212
<bin name="test-valgrind-memleak" file="test-valgrind-memleak.cpp"/>
1313
</ifrelease>
14+
15+
<test name="TestUtilitiesReleaseScriptsCheckDictionaryUpdate" command="run_checkDictionaryUpdate.sh"/>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"edm::Wrapper<edmtest::reflection::IntObject>": {
3+
"checksum": 536952283,
4+
"version": 4
5+
},
6+
"edmtest::reflection::IntObject": {
7+
"checksum": 427917710,
8+
"version": 3
9+
}
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"edm::Wrapper<edmtest::reflection::IntObject>": {
3+
"checksum": 536952283,
4+
"version": 4
5+
},
6+
"edmtest::reflection::IntObject": {
7+
"checksum": 427917710,
8+
"version": 3
9+
},
10+
"edmtest::reflection::Another": {
11+
"checksum": 427917711,
12+
"version": 3
13+
}
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"edmtest::reflection::IntObject": {
3+
"checksum": 427917710,
4+
"version": 3
5+
}
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"edm::Wrapper<edmtest::reflection::IntObject>": {
3+
"checksum": 536952283,
4+
"version": 4
5+
},
6+
"edmtest::reflection::IntObject": {
7+
"checksum": 3848242946,
8+
"version": 4
9+
}
10+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# possible exit codes
4+
SUCCESS=0
5+
FAILURE="fail"
6+
DATAFORMATS_CHANGED=40
7+
POLICY_VIOLATION=41
8+
9+
function die { echo Failure $1: status $2 ; exit $2 ; }
10+
function checkExitCode {
11+
if [ "$1" == "$FAILURE" ]; then
12+
if [[ "$2" = @("$SUCCESS"|"$DATAFORMATS_CHANGES"|"$POLICY_VIOLATIONS") ]]; then
13+
echo "checkDictionaryUpdate.py $3: expected failure exit code, got $2"
14+
exit 1
15+
fi
16+
elif [ "$1" != "$2" ]; then
17+
echo "checkDictionaryUpdate.py $3: expected exit code $1, got $2"
18+
exit 1
19+
fi
20+
}
21+
22+
JSONPATH=${SCRAM_TEST_PATH}/checkDictionaryUpdate
23+
24+
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json || die "checkDictionaryUpdate.py baseline" $?
25+
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_baseline.json || die "checkDictionaryUpdate.py baseline baseline" $?
26+
27+
checkDictionaryUpdate.py
28+
RET=$?
29+
checkExitCode ${FAILURE} $RET ""
30+
31+
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_versionUpdate.json
32+
RET=$?
33+
checkExitCode ${DATAFORMATS_CHANGED} $RET "baseline versionUpdate"
34+
35+
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_newClass.json
36+
RET=$?
37+
checkExitCode ${DATAFORMATS_CHANGED} $RET "baseline newClass"
38+
39+
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_removeClass.json
40+
RET=$?
41+
checkExitCode ${DATAFORMATS_CHANGED} $RET "baseline removeClass"

0 commit comments

Comments
 (0)