11import pytest
22from unittest import mock
3+ from paths_cli .tests .parsing .utils import mock_parser
34import numpy as np
45
56import yaml
@@ -39,11 +40,13 @@ def test_mistis_trans_info(cv_and_states):
3940 }]
4041 }
4142 patch_base = 'paths_cli.parsing.networks'
42-
43- with mock .patch .dict (f"{ patch_base } .volume_parser.named_objs" ,
44- {"A" : state_A , "B" : state_B }), \
45- mock .patch .dict (f"{ patch_base } .cv_parser.named_objs" ,
46- {'cv' : cv }):
43+ parser = {
44+ 'cv' : mock_parser ('cv' , named_objs = {'cv' : cv }),
45+ 'volume' : mock_parser ('volume' , named_objs = {
46+ "A" : state_A , "B" : state_B
47+ }),
48+ }
49+ with mock .patch .dict ('paths_cli.parsing.root_parser.PARSERS' , parser ):
4750 results = mistis_trans_info (dct )
4851
4952 check_unidirectional_tis (results , state_A , state_B , cv )
@@ -62,11 +65,13 @@ def test_tis_trans_info(cv_and_states):
6265 }
6366 }
6467
65- patch_base = 'paths_cli.parsing.networks'
66- with mock .patch .dict (f"{ patch_base } .volume_parser.named_objs" ,
67- {"A" : state_A , "B" : state_B }), \
68- mock .patch .dict (f"{ patch_base } .cv_parser.named_objs" ,
69- {'cv' : cv }):
68+ parser = {
69+ 'cv' : mock_parser ('cv' , named_objs = {'cv' : cv }),
70+ 'volume' : mock_parser ('volume' , named_objs = {
71+ "A" : state_A , "B" : state_B
72+ }),
73+ }
74+ with mock .patch .dict ('paths_cli.parsing.root_parser.PARSERS' , parser ):
7075 results = tis_trans_info (dct )
7176
7277 check_unidirectional_tis (results , state_A , state_B , cv )
@@ -77,8 +82,11 @@ def test_build_tps_network(cv_and_states):
7782 _ , state_A , state_B = cv_and_states
7883 yml = "\n " .join (["initial_states:" , " - A" , "final_states:" , " - B" ])
7984 dct = yaml .load (yml , yaml .FullLoader )
80- patch_loc = 'paths_cli.parsing.networks.volume_parser.named_objs'
81- with mock .patch .dict (patch_loc , {"A" : state_A , "B" : state_B }):
85+ parser = {
86+ 'volume' : mock_parser ('volume' , named_objs = {"A" : state_A ,
87+ "B" : state_B }),
88+ }
89+ with mock .patch .dict ('paths_cli.parsing.root_parser.PARSERS' , parser ):
8290 network = build_tps_network (dct )
8391 assert isinstance (network , paths .TPSNetwork )
8492 assert len (network .initial_states ) == len (network .final_states ) == 1
0 commit comments