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,21 +21,16 @@ def tweak_assignments_sequence_of_options(state_obj):
1921 else :
2022 items [i ] = {"some" : items [i ]}
2123
22-
2324def tweak_callback (json_obj ):
2425 tweak_assignments_sequence_of_options (json_obj ['pre_state' ])
2526 tweak_assignments_sequence_of_options (json_obj ['post_state' ])
2627 return json_obj
2728
29+ def validate_spec (spec_name ):
30+ print (f"[Validating '{ spec_name } ' spec]" )
31+ schema = asn1tools .compile_files (get_schema_files (spec_name == "full" ) + ["assurances.asn" ], codec = "jer" )
32+ for json_file in glob .glob (f"{ spec_name } /*.json" ):
33+ validate (schema , json_file , "TestCase" , tweak_callback )
2834
29- # Validate tiny
30- schema = asn1tools .compile_files (get_schema_files (False ) + ["assurances.asn" ], codec = "jer" )
31- for path in Path ("tiny" ).iterdir ():
32- if path .is_file () and path .suffix == ".json" :
33- validate (schema , path , "TestCase" , tweak_callback )
34-
35- # Validate full
36- schema = asn1tools .compile_files (get_schema_files (True ) + ["assurances.asn" ], codec = "jer" )
37- for path in Path ("full" ).iterdir ():
38- if path .is_file () and path .suffix == ".json" :
39- validate (schema , path , "TestCase" , tweak_callback )
35+ validate_spec ("tiny" )
36+ validate_spec ("full" )
0 commit comments