11#!/usr/bin/env python
22
3+ import asn1tools
4+ import glob
35import os
46import sys
5- from pathlib import Path
67
7- import asn1tools
8+ script_dir = os .path .dirname (os .path .abspath (__file__ ))
9+ sys .path .append (os .path .abspath (os .path .join (script_dir , '../jam-types-asn' )))
810
9- sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), '../jam-types-asn' )))
10- from utils import get_schema_files , validate
11+ from utils import get_schema_files , validate # noqa: E402
1112
13+ os .chdir (script_dir )
1214
1315# Makes the SEQUENCE of OPTIONAL values ASN.1 compliant (using CHOICE)
1416def tweak_assignments_sequence_of_options (state_obj ):
@@ -19,7 +21,6 @@ def tweak_assignments_sequence_of_options(state_obj):
1921 else :
2022 items [i ] = {"some" : items [i ]}
2123
22-
2324# Makes the SEQUENCE of OPTIONAL values ASN.1 compliant (using CHOICE)
2425def tweak_mmr_sequence_of_options (state_obj ):
2526 for entry in state_obj ['recent_blocks' ]:
@@ -31,23 +32,18 @@ def tweak_mmr_sequence_of_options(state_obj):
3132 peaks [i ] = {"some" : peaks [i ]}
3233 return state_obj
3334
34-
3535def tweak_callback (json_obj ):
3636 tweak_assignments_sequence_of_options (json_obj ['pre_state' ])
3737 tweak_mmr_sequence_of_options (json_obj ['pre_state' ])
3838 tweak_assignments_sequence_of_options (json_obj ['post_state' ])
3939 tweak_mmr_sequence_of_options (json_obj ['post_state' ])
4040 return json_obj
4141
42+ def validate_spec (spec_name ):
43+ print (f"[Validating Reports ({ spec_name } )]" )
44+ schema = asn1tools .compile_files (get_schema_files (spec_name == "full" ) + ["reports.asn" ], codec = "jer" )
45+ for json_file in glob .glob (f"{ spec_name } /*.json" ):
46+ validate (schema , json_file , "TestCase" , tweak_callback )
4247
43- # Validate tiny
44- schema = asn1tools .compile_files (get_schema_files (False ) + ["reports.asn" ], codec = "jer" )
45- for path in Path ("tiny" ).iterdir ():
46- if path .is_file () and path .suffix == ".json" :
47- validate (schema , path , "TestCase" , tweak_callback )
48-
49- # Validate full
50- schema = asn1tools .compile_files (get_schema_files (True ) + ["reports.asn" ], codec = "jer" )
51- for path in Path ("full" ).iterdir ():
52- if path .is_file () and path .suffix == ".json" :
53- validate (schema , path , "TestCase" , tweak_callback )
48+ validate_spec ("tiny" )
49+ validate_spec ("full" )
0 commit comments