@@ -109,61 +109,67 @@ def test_initial_state(self):
109109
110110
111111class TestRunChat :
112- @patch ("asyncio.run" )
113- @patch .object (chat_module , "LLMRails" )
114- @patch .object (chat_module , "RailsConfig" )
115- def test_run_chat_v1_0 (self , mock_rails_config , mock_llm_rails , mock_asyncio_run ):
116- mock_config = MagicMock ()
117- mock_config .colang_version = "1.0"
118- mock_rails_config .from_path .return_value = mock_config
112+ def test_run_chat_v1_0 (self ):
113+ with patch .object (
114+ chat_module , "RailsConfig"
115+ ) as mock_rails_config , patch .object (
116+ chat_module , "LLMRails"
117+ ) as mock_llm_rails , patch (
118+ "asyncio.run"
119+ ) as mock_asyncio_run :
120+ mock_config = MagicMock ()
121+ mock_config .colang_version = "1.0"
122+ mock_rails_config .from_path .return_value = mock_config
119123
120- run_chat (config_path = "test_config" )
124+ run_chat (config_path = "test_config" )
121125
122- mock_rails_config .from_path .assert_called_once_with ("test_config" )
123- mock_asyncio_run .assert_called_once ()
126+ mock_rails_config .from_path .assert_called_once_with ("test_config" )
127+ mock_asyncio_run .assert_called_once ()
124128
125- @patch .object (chat_module , "get_or_create_event_loop" )
126- @patch .object (chat_module , "LLMRails" )
127- @patch .object (chat_module , "RailsConfig" )
128- def test_run_chat_v2_x (self , mock_rails_config , mock_llm_rails , mock_get_loop ):
129- mock_config = MagicMock ()
130- mock_config .colang_version = "2.x"
131- mock_rails_config .from_path .return_value = mock_config
129+ def test_run_chat_v2_x (self ):
130+ with patch .object (
131+ chat_module , "RailsConfig"
132+ ) as mock_rails_config , patch .object (
133+ chat_module , "LLMRails"
134+ ) as mock_llm_rails , patch .object (
135+ chat_module , "get_or_create_event_loop"
136+ ) as mock_get_loop :
137+ mock_config = MagicMock ()
138+ mock_config .colang_version = "2.x"
139+ mock_rails_config .from_path .return_value = mock_config
132140
133- mock_loop = MagicMock ()
134- mock_get_loop .return_value = mock_loop
141+ mock_loop = MagicMock ()
142+ mock_get_loop .return_value = mock_loop
135143
136- run_chat (config_path = "test_config" )
144+ run_chat (config_path = "test_config" )
137145
138- mock_rails_config .from_path .assert_called_once_with ("test_config" )
139- mock_llm_rails .assert_called_once_with (mock_config , verbose = False )
140- mock_loop .run_until_complete .assert_called_once ()
146+ mock_rails_config .from_path .assert_called_once_with ("test_config" )
147+ mock_llm_rails .assert_called_once_with (mock_config , verbose = False )
148+ mock_loop .run_until_complete .assert_called_once ()
141149
142- @ patch . object ( chat_module , "RailsConfig" )
143- def test_run_chat_invalid_version ( self , mock_rails_config ) :
144- mock_config = MagicMock ()
145- mock_config .colang_version = "3.0"
146- mock_rails_config .from_path .return_value = mock_config
150+ def test_run_chat_invalid_version ( self ):
151+ with patch . object ( chat_module , "RailsConfig" ) as mock_rails_config :
152+ mock_config = MagicMock ()
153+ mock_config .colang_version = "3.0"
154+ mock_rails_config .from_path .return_value = mock_config
147155
148- with pytest .raises (Exception , match = "Invalid colang version" ):
149- run_chat (config_path = "test_config" )
156+ with pytest .raises (Exception , match = "Invalid colang version" ):
157+ run_chat (config_path = "test_config" )
150158
151- @patch .object (chat_module , "console" )
152- @patch ("asyncio.run" )
153- @patch .object (chat_module , "RailsConfig" )
154- def test_run_chat_verbose_with_llm_calls (
155- self , mock_rails_config , mock_asyncio_run , mock_console
156- ):
157- mock_config = MagicMock ()
158- mock_config .colang_version = "1.0"
159- mock_rails_config .from_path .return_value = mock_config
159+ def test_run_chat_verbose_with_llm_calls (self ):
160+ with patch .object (chat_module , "RailsConfig" ) as mock_rails_config , patch (
161+ "asyncio.run"
162+ ) as mock_asyncio_run , patch .object (chat_module , "console" ) as mock_console :
163+ mock_config = MagicMock ()
164+ mock_config .colang_version = "1.0"
165+ mock_rails_config .from_path .return_value = mock_config
160166
161- run_chat (config_path = "test_config" , verbose = True , verbose_llm_calls = True )
167+ run_chat (config_path = "test_config" , verbose = True , verbose_llm_calls = True )
162168
163- mock_console .print .assert_any_call (
164- "NOTE: use the `--verbose-no-llm` option to exclude the LLM prompts "
165- "and completions from the log.\n "
166- )
169+ mock_console .print .assert_any_call (
170+ "NOTE: use the `--verbose-no-llm` option to exclude the LLM prompts "
171+ "and completions from the log.\n "
172+ )
167173
168174
169175class TestRunChatV1Async :
0 commit comments