@@ -503,20 +503,16 @@ def __init__(self, **inputs):
503
503
settings = example_data (example_data ('smri_ants_registration_settings.json' ))
504
504
with open (settings ) as setf :
505
505
data_dict = json .load (setf )
506
- tsthash = Registration (from_file = settings )
507
- yield assert_all_true , data_dict , tsthash .inputs .get_traitsfree ()
508
- hashed_inputs , hashvalue = tsthash .inputs .get_hashval (hash_method = 'timestamp' )
509
- # yield assert_equal, hashvalue, '9ab944cbccba61475becb9eac65052af'
510
506
511
- def assert_not_raises ( fn , * args , ** kwargs ):
512
- fn ( * args , ** kwargs )
513
- return True
507
+ tsthash = Registration ()
508
+ tsthash . load_inputs_from_json ( settings )
509
+ yield assert_equal , {}, check_dict ( data_dict , tsthash . inputs . get_traitsfree ())
514
510
515
- def assert_all_true ( ref_dict , tst_dict ):
516
- for key , value in list ( ref_dict . items ()):
517
- if tst_dict [ key ] != value :
518
- return False
519
- return True
511
+ tsthash2 = Registration ( from_file = settings )
512
+ yield assert_equal , {}, check_dict ( data_dict , tsthash2 . inputs . get_traitsfree ())
513
+
514
+ hashed_inputs , hashvalue = tsthash . inputs . get_hashval ( hash_method = 'timestamp' )
515
+ yield assert_equal , hashvalue , '9ab944cbccba61475becb9eac65052af'
520
516
521
517
def test_input_version ():
522
518
class InputSpec (nib .TraitedSpec ):
@@ -754,3 +750,27 @@ def test_global_CommandLine_output():
754
750
yield assert_equal , res .runtime .stdout , ''
755
751
os .chdir (pwd )
756
752
teardown_file (tmpd )
753
+
754
+ def assert_not_raises (fn , * args , ** kwargs ):
755
+ fn (* args , ** kwargs )
756
+ return True
757
+
758
+ def check_dict (ref_dict , tst_dict ):
759
+ """Compare dictionaries of inputs and and those loaded from json files"""
760
+ def to_list (x ):
761
+ if isinstance (x , tuple ):
762
+ x = list (x )
763
+
764
+ if isinstance (x , list ):
765
+ for i , xel in enumerate (x ):
766
+ x [i ] = to_list (xel )
767
+
768
+ return x
769
+
770
+ failed_dict = {}
771
+ for key , value in list (ref_dict .items ()):
772
+ newval = to_list (tst_dict [key ])
773
+ if newval != value :
774
+ failed_dict [key ] = (value , newval )
775
+ return failed_dict
776
+
0 commit comments