Skip to main content
Glama
test_ui_endpoints.cpython-312-pytest-8.4.0.pyc48.1 kB
� PiEh�H� �X�dZddlZddlmcmZddlZddlm Z m Z m Z ddl Z ddl Z e jjde jj!e jj!e jj!e����Gd�d�ZGd�d�ZGd�d �Zy) z-UI endpoint smoke tests for Gradio interface.�N)�Mock�patch� MagicMockc�X�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z d�Z d �Z d �Z d �Z d �Zd �Zy)�TestUIEndpointsz&Test Gradio UI endpoints and wrappers.c ��td�5td�5td�5ddlm}td�5}ddd d d gd �d f|j_|d�}t |�}d}||k(}|s�t jd|fd||f�dtj�vst jt �rt jt �nddtj�vst j|�rt j|�ndt j|�t j|�d�z}dd|iz}tt j|���dx}x}}|dd} d} | | k(}|slt jd|fd| | f�t j| �t j| �d�z} dd| iz}tt j|���dx} x}} d} |d} | | v}|slt jd|fd| | f�t j| �t j| �d�z} dd| iz}tt j|���dx} x}} |jj�ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw) z-Test the agent_orchestrator wrapper function.� modal.App� modal.Image�tavily.TavilyClientr��agent_orchestrator�app.orchestrator�successz Test researchz print('test')�testz Test citation��status�research_summary�generated_code�execution_result� citationsz Test summaryzCreate a test script���==�z0%(py3)s {%(py3)s = %(py0)s(%(py1)s) } == %(py6)s�len�result��py0�py1�py3�py6�assert %(py8)s�py8Nr�z%(py1)s == %(py4)s�r�py4�assert %(py6)sr!r��in�z%(py1)s in %(py4)s)r�appr � orchestrate� return_valuer� @pytest_ar�_call_reprcompare� @py_builtins�locals�_should_repr_global_name� _saferepr�AssertionError�_format_explanation�assert_called_once) �selfr �mock_orchestratorr� @py_assert2� @py_assert5� @py_assert4� @py_format7� @py_format9� @py_assert0� @py_assert3� @py_format5s �SC:\Users\User\PythonProjects\mcp_hub_project\tests\integration\test_ui_endpoints.py�test_agent_orchestrator_wrapperz/TestUIEndpoints.test_agent_orchestrator_wrappers�� �;� � C� �=� !� C� �(� )� C� /��)�*� C�.?�#,�,;�*9�,2�&5�%6� �#� >�!�-�-�:�,�,B�C���6�{�'�a�'�{�a�'�'�'�'�{�a�'�'�'�'�'�'�s�'�'�'�s�'�'�'�'�'�'�6�'�'�'�6�'�'�'�{�'�'�'�a�'�'�'�'�'�'�'��a�y��*�7�i�7�*�i�7�7�7�7�*�i�7�7�7�*�7�7�7�i�7�7�7�7�7�7�7�)�6�V�A�Y�6�)�Y�6�6�6�6�)�Y�6�6�6�)�6�6�6�Y�6�6�6�6�6�6�6�!�-�-�@�@�B�) C�  C� C� C� C�  C� C��  C� C�� C� C�� C� C�sQ� K � J>�J2�IJ& �J2� J>�K �&J/ �+J2�2J; �7J>�>K �K � Kc ��td�5td�5td�5ddlm}td�5}dgd�i|j_|d d �}d}||v}|s�t j d |fd ||f�t j|�d tj�vst j|�rt j|�nd d�z}dd|iz}tt j|���dx}}|d}t|�} d } | | k(} | s�t j d| fd| | f�dtj�vst jt�rt jt�ndt j|�t j| �t j| �d�z} dd| iz} tt j| ���dx}x} x} } |jjd d �ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)z2Test the agent_question_enhancer wrapper function.r r r r)�agent_question_enhancer�app.question_enhancer� sub_questions)zHow to create a script?zWhat libraries to use?zHow to test the code?zCreate a Python script�r(�z%(py1)s in %(py3)sr�rr �assert %(py5)s�py5Nr�z0%(py4)s {%(py4)s = %(py0)s(%(py2)s) } == %(py7)sr�r�py2r&�py7�assert %(py9)s�py9)rr+rD�enhance_questionr-r.r/r3r0r1r2r4r5r�assert_called_once_with)r7rD� mock_agentrr>r9� @py_format4� @py_format6� @py_assert1r?� @py_assert6r:� @py_format8� @py_format10s rA�$test_agent_question_enhancer_wrapperz4TestUIEndpoints.test_agent_question_enhancer_wrapper-s��� �;� � a� �=� !� a� �(� )� a� 4��.�/� a�:�$�&�<� �+�+�8�1�1I�1�M��'�0��&�0�0�0�0��&�0�0�0��0�0�0�0�0�0�&�0�0�0�&�0�0�0�0�0�0�0�!�/�2�8�s�2�3�8�q�8�3�q�8�8�8�8�3�q�8�8�8�8�8�8�s�8�8�8�s�8�8�8�2�8�8�8�3�8�8�8�q�8�8�8�8�8�8�8��+�+�C�C�D\�^_�`�! a�  a� a� a� a�  a� a��  a� a�� a� a�� a� a�sQ� I� H9�H-�G H! �H-�H9�I�!H* �&H-�-H6 �2H9�9I �>I�Ic ��td�5td�5td�5ddlm}td�5}ddd d �gd d �|j_|d �}|d}d}||k(}|slt j d|fd||f�t j|�t j|�d�z}dd|iz}tt j|���dx}x}}d}||v}|s�t j d|fd||f�t j|�dtj�vst j|�rt j|�ndd�z} dd| iz} tt j| ���dx}}d}||v}|s�t j d|fd||f�t j|�dtj�vst j|�rt j|�ndd�z} dd| iz} tt j| ���dx}}|jj�ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)z+Test the agent_web_search wrapper function.r r r r)�agent_web_search�app.web_searchr�Tutorialzhttps://example.com)�title�urlzTest search result)r�results� tavily_answerzPython tutorialsrrr$r%r'r!Nrbr(rHrrIrJrKrc)rr+r]�searchr-r.r/r3r4r5r0r1r2r6) r7r]rTrr>r?r9r@r<rUrVs rA�test_agent_web_search_wrapperz-TestUIEndpoints.test_agent_web_search_wrapperGs��� �;� � 7� �=� !� 7� �(� )� 7� -��'�(� 7�J�(�",�5J�K� �&:� 2� �!�!�.�*�*<�=���h�'�4�9�4�'�9�4�4�4�4�'�9�4�4�4�'�4�4�4�9�4�4�4�4�4�4�4� �*�y�F�*�*�*�*�y�F�*�*�*�y�*�*�*�*�*�*�F�*�*�*�F�*�*�*�*�*�*�*�&�0��&�0�0�0�0��&�0�0�0��0�0�0�0�0�0�&�0�0�0�&�0�0�0�0�0�0�0��!�!�4�4�6�# 7�  7� 7� 7� 7�  7� 7��  7� 7�� 7� 7�� 7� 7�sQ� J� I5�I)�HI �<I)�I5� J�I& �"I)�)I2 �.I5�5I> �:J�J c ���td�5td�5td�5ddlm}td�5}ddd �|j_|d d d �}|d }d}||k(}|slt j d|fd||f�t j|�t j|�d�z}dd|iz}tt j|���dx}x}}d}||v}|s�t j d|fd||f�t j|�dtj�vst j|�rt j|�ndd�z} dd| iz} tt j| ���dx}}|jjd d d �ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)z.Test the agent_llm_processor wrapper function.r r r r)�agent_llm_processor�app.llm_processorrzProcessed text content)r�llm_processed_outputz Input text� summarize�Contextrrr$r%r'r!Nrir(rHrrIrJrK)rr+rg�processr-r.r/r3r4r5r0r1r2rS) r7rgrTrr>r?r9r@r<rUrVs rA� test_agent_llm_processor_wrapperz0TestUIEndpoints.test_agent_llm_processor_wrapperbs��� �;� � a� �=� !� a� �(� )� a� 0��*�+� a�z�(�,D�3� �"�"�/� -�\�;� �R���h�'�4�9�4�'�9�4�4�4�4�'�9�4�4�4�'�4�4�4�9�4�4�4�4�4�4�4�-�7�-��7�7�7�7�-��7�7�7�-�7�7�7�7�7�7��7�7�7��7�7�7�7�7�7�7��"�"�:�:�<��V_�`� a�  a� a� a� a� a� a��  a� a�� a� a�� a� a�sQ� G� G�G�E!F8 �G�G�'G�8G �=G�G � G�G �G�G%c ��td�5td�5td�5ddlm}td�5}ddgd d �|j_|d �}d }||v}|s�t j d |fd||f�t j|�dtj�vst j|�rt j|�ndd�z}dd|iz}tt j|���d x}}|d }t|�} d} | | k(} | s�t j d| fd| | f�dtj�vst jt�rt jt�ndt j|�t j| �t j| �d�z} dd| iz} tt j| ���d x}x} x} } |jj�d d d �d d d �d d d �d d d �y #1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYy xYw)z3Test the agent_citation_formatter wrapper function.r r r r)�agent_citation_formatter�app.citation_formatterz Citation 1z Citation 2N)�formatted_citations�errorzText with URLsrqr(rHrrIrJrKrrrLrrMrPrQ)rr+ro�format_citationsr-r.r/r3r0r1r2r4r5rr6)r7rorTrr>r9rUrVrWr?rXr:rYrZs rA�%test_agent_citation_formatter_wrapperz5TestUIEndpoints.test_agent_citation_formatter_wrapperys��� �;� � A� �=� !� A� �(� )� A� 5��/�0� A�J�-9�,�+G�!�<� �+�+�8� 2�2B�C��-�6�,��6�6�6�6�,��6�6�6�,�6�6�6�6�6�6��6�6�6��6�6�6�6�6�6�6�!�"7�8�>�s�8�9�>�Q�>�9�Q�>�>�>�>�9�Q�>�>�>�>�>�>�s�>�>�>�s�>�>�>�8�>�>�>�9�>�>�>�Q�>�>�>�>�>�>�>��+�+�>�>�@� A�  A� A� A� A� A� A��  A� A�� A� A�� A� A�sQ� I� H7�H+�GH �>H+�H7�I�H( �$H+�+H4 �0H7�7I �<I�I c ��td�5td�5td�5ddlm}td�5}ddd d �d g|j_|d d �}t |�}d}||k(}|s�t jd|fd||f�dtj�vst jt �rt jt �nddtj�vst j|�rt j|�ndt j|�t j|�d�z}dd|iz}tt j|���dx}x}}|dd} d} | | k(}|slt jd|fd| | f�t j| �t j| �d�z} dd| iz}tt j|���dx} x}} d} |d} | | v}|slt jd|fd| | f�t j| �t j| �d�z} dd| iz}tt j|���dx} x}} |jj�ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)z/Test the agent_code_generator wrapper function.r r r r)�agent_code_generator�app.code_generatorrz#import pandas as pd\nprint('Hello')z Simple script)r�code� explanationzGenerated code explanationzCreate a scriptrkrrrrrrr"r#Nrr$r%r'r!rxr(r*)rr+rv� generate_coder-rr.r/r0r1r2r3r4r5r6) r7rvrTrr9r:r;r<r=r>r?r@s rA�!test_agent_code_generator_wrapperz1TestUIEndpoints.test_agent_code_generator_wrapper�s��� �;� � >� �=� !� >� �(� )� >� 1��+�,� >� �#,� F�'6�� 1� 9� �(�(�5�.�.?��K���6�{�'�a�'�{�a�'�'�'�'�{�a�'�'�'�'�'�'�s�'�'�'�s�'�'�'�'�'�'�6�'�'�'�6�'�'�'�{�'�'�'�a�'�'�'�'�'�'�'��a�y��*�7�i�7�*�i�7�7�7�7�*�i�7�7�7�*�7�7�7�i�7�7�7�7�7�7�7��*����*�v��*�*�*�*�v��*�*�*�v�*�*�*��*�*�*�*�*�*�*��(�(�;�;�=�% >�  >� >� >� >�  >� >��  >� >�� >� >�� >� >�sQ� K� J<�J0�I J$ �J0� J<�K�$J- �)J0�0J9 �5J<�<K �K�Kc � �td�5td�5td�5ddlm}td�5}d|j_|d�}d }||v}|s�t j d |fd ||f�t j|�d tj�vst j|�rt j|�nd d �z}dd|iz}tt j|���dx}}d}||v}|s�t j d |fd ||f�t j|�d tj�vst j|�rt j|�nd d �z}dd|iz}tt j|���dx}}|jj�ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)z&Test the code_runner_wrapper function.r r r r)�code_runner_wrapper�app.code_runnerz/Code executed successfully\nOutput: Hello Worldzprint('Hello World')zCode executed successfullyr(rHrrIrJrKNz Hello World)rr+r}�run_coder-r.r/r3r0r1r2r4r5r6)r7r}rTrr>r9rUrVs rA�test_code_runner_wrapperz(TestUIEndpoints.test_code_runner_wrapper�sh�� �;� � 9� �=� !� 9� �(� )� 9� 0��(�)� 9�Z�3e� �#�#�0�-�-C�D��4�=�3�v�=�=�=�=�3�v�=�=�=�3�=�=�=�=�=�=�v�=�=�=�v�=�=�=�=�=�=�=�$�.�}��.�.�.�.�}��.�.�.�}�.�.�.�.�.�.��.�.�.��.�.�.�.�.�.�.��#�#�6�6�8� 9�  9� 9� 9� 9� 9� 9��  9� 9�� 9� 9�� 9� 9�sQ� G9� G-�G!�E>G �4G!�<G-�G9�G �G!�!G* �&G-�-G6 �2G9�9Hc ��td�5td�5td�5ddlm}|�}t|t�}|�s ddt j �vstjt�rtjt�nddt j �vstj|�rtj|�ndd t j �vstjt�rtjt�nd tj|�d �z}ttj|���d }d }||v}|s�tjd |fd||f�tj|�dt j �vstj|�rtj|�ndd�z}dd|iz}ttj|���d x}}d}||v}|s�tjd |fd||f�tj|�dt j �vstj|�rtj|�ndd�z}dd|iz}ttj|���d x}}d d d �d d d �d d d �y #1swY�xYw#1swY�xYw#1swYy xYw)zTest health status endpoint.r r r r)�get_health_status�5assert %(py4)s {%(py4)s = %(py0)s(%(py1)s, %(py2)s) }� isinstancer�dict�rrrNr&Nrr(rHrIrJrK� timestamp) rr+r�r�r�r0r1r.r2r3r4r5r/) r7r�rr?r@r>r9rUrVs rA�test_health_status_endpointz+TestUIEndpoints.test_health_status_endpoint�s��� �;� � )� �=� !� )� �(� )� )� .�'�(�F��f�d�+� +�+� +� +� +� +� +�:� +� +� +�:� +� +� +� +� +� +�f� +� +� +�f� +� +� +� +� +� +�d� +� +� +�d� +� +� +�+� +� +� +� +� +� +�� %�8�v�%� %� %� %�8�v� %� %� %�8� %� %� %� %� %� %�v� %� %� %�v� %� %� %� %� %� %� %�� (�;�&�(� (� (� (�;�&� (� (� (�;� (� (� (� (� (� (�&� (� (� (�&� (� (� (� (� (� (� (� )� )� )� )� )�� )� )�� )� )�s:� K � K�I8J5�K�$K �5J> �:K�K �K � Kc ��td�5td�5td�5ddlm}|�}t|t�}|�s ddt j �vstjt�rtjt�nddt j �vstj|�rtj|�ndd t j �vstjt�rtjt�nd tj|�d �z}ttj|���d }d d d �d d d �d d d �y #1swY�xYw#1swY�xYw#1swYy xYw) z"Test performance metrics endpoint.r r r r)�get_performance_metricsr�r�rr�r�N) rr+r�r�r�r0r1r.r2r3r4r5)r7r�rr?r@s rA�!test_performance_metrics_endpointz1TestUIEndpoints.test_performance_metrics_endpoint�s��� �;� � ,� �=� !� ,� �(� )� ,� 4�-�.�F��f�d�+� +�+� +� +� +� +� +�:� +� +� +�:� +� +� +� +� +� +�f� +� +� +�f� +� +� +� +� +� +�d� +� +� +�d� +� +� +�+� +� +� +� +� +� +� ,� ,� ,� ,� ,�� ,� ,�� ,� ,��:� F� E7�D.E+�E7�F�+E4 �0E7�7F �<F�F c ��td�5td�5td�5ddlm}|�}t|t�}|�s ddt j �vstjt�rtjt�nddt j �vstj|�rtj|�ndd t j �vstjt�rtjt�nd tj|�d �z}ttj|���d }d d d �d d d �d d d �y #1swY�xYw#1swY�xYw#1swYy xYw) zTest cache status endpoint.r r r r)�get_cache_statusr�r�rr�r�N) rr+r�r�r�r0r1r.r2r3r4r5)r7r�rr?r@s rA�test_cache_status_endpointz*TestUIEndpoints.test_cache_status_endpoint�s��� �;� � ,� �=� !� ,� �(� )� ,� -�&�'�F��f�d�+� +�+� +� +� +� +� +�:� +� +� +�:� +� +� +� +� +� +�f� +� +� +�f� +� +� +� +� +� +�d� +� +� +�d� +� +� +�+� +� +� +� +� +� +� ,� ,� ,� ,� ,�� ,� ,�� ,� ,�r�c ��td�5td�5td�5ddlm}|�}t|t�}|�s ddt j �vstjt�rtjt�nddt j �vstj|�rtj|�ndd t j �vstjt�rtjt�nd tj|�d �z}ttj|���d }d d d �d d d �d d d �y #1swY�xYw#1swY�xYw#1swYy xYw) z"Test sandbox pool status endpoint.r r r r)�get_sandbox_pool_status_syncr�r�rr�r�N) rr+r�r�r�r0r1r.r2r3r4r5)r7r�rr?r@s rA�!test_sandbox_pool_status_endpointz1TestUIEndpoints.test_sandbox_pool_status_endpoint�s��� �;� � ,� �=� !� ,� �(� )� ,� 9�2�3�F��f�d�+� +�+� +� +� +� +� +�:� +� +� +�:� +� +� +� +� +� +�f� +� +� +�f� +� +� +� +� +� +�d� +� +� +�d� +� +� +�+� +� +� +� +� +� +� ,� ,� ,� ,� ,�� ,� ,�� ,� ,�r�c ���td�5td�5td�5ddlm}td�5}ddd d gd �d f|j_|d �}t |t �}|�s ddtj�vstjt �rtjt �nddtj�vstj|�rtj|�nddtj�vstjt �rtjt �ndtj|�d�z}ttj|���d}|d}d}||k(}|sltjd|fd||f�tj|�tj|�d�z}dd|iz}ttj|���dx}x}}|jj�ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)z;Test process_orchestrator_request endpoint (MCP interface).r r r r��process_orchestrator_requestrrzMCP test researchz# MCP test codezMCP execution resultrzMCP test summaryzCreate an MCP test scriptr�r�rr�r�Nrrr$r%r'r!)rr+r�r,r-r�r�r0r1r.r2r3r4r5r/r6) r7r�r8rr?r@r>r9r<s rA�*test_process_orchestrator_request_endpointz:TestUIEndpoints.test_process_orchestrator_request_endpoint�s��� �;� � C� �=� !� C� �(� )� C� 9��)�*� C�.?�#,�,?�*;�,B�%'� �'� >�!�-�-�:�6�6Q�R��"�&�$�/�/�/�/�/�/�/�/�z�/�/�/�z�/�/�/�/�/�/�&�/�/�/�&�/�/�/�/�/�/�$�/�/�/�$�/�/�/�/�/�/�/�/�/�/��h�'�4�9�4�'�9�4�4�4�4�'�9�4�4�4�'�4�4�4�9�4�4�4�4�4�4�4�!�-�-�@�@�B�' C�  C� C� C� C�  C� C��  C� C�� C� C�� C� C�sQ� I� I �H?�GH3 �H?�I �"I�3H< �8H?�?I �I � I �I�I N)�__name__� __module__� __qualname__�__doc__rBr[rermrtr{r�r�r�r�r�r���rArr sF��0�C�<a�47�6a�.A�.>�89�()�" ,� ,� ,�Cr�rc�(�eZdZdZd�Zd�Zd�Zd�Zy)�TestUIErrorHandlingz&Test UI error handling and edge cases.c ��td�5td�5td�5ddlm}td�5}td�|j_|d�}t |t�}|�s d d tj�vstjt �rtjt �nd d tj�vstj|�rtj|�nd d tj�vstjt�rtjt�nd tj|�d �z}ttj|���d}ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)z8Test orchestrator wrapper with various error conditions.r r r rr rzOrchestrator failed� Test requestr�r�r�tupler�N)rr+r � Exceptionr,� side_effectr�r�r0r1r.r2r3r4r5)r7r r8rr?r@s rA�%test_orchestrator_wrapper_with_errorsz9TestUIErrorHandling.test_orchestrator_wrapper_with_errorss0�� �;� � 1� �=� !� 1� �(� )� 1� /��)�*� 1�.?�<E�F[�<\�!�-�-�9�,�N�;��"�&�%�0�0�0�0�0�0�0�0�z�0�0�0�z�0�0�0�0�0�0�&�0�0�0�&�0�0�0�0�0�0�%�0�0�0�%�0�0�0�0�0�0�0�0�0�0� 1�  1� 1� 1� 1�  1� 1��  1� 1�� 1� 1�� 1� 1��Q� F>� F2�F&�EF �9F&�F2� F>�F# �F&�&F/ �+F2�2F; �7F>�>Gc � �td�5td�5td�5ddlm}m}m}m}|dd�}|d�}|dd�}|d�}t |t�} | �s d d tj�vstjt �rtjt �nd d tj�vstj|�rtj|�nd d tj�vstjt�rtjt�nd tj| �d �z} ttj| ���d} t |t�} | �s d d tj�vstjt �rtjt �nd dtj�vstj|�rtj|�ndd tj�vstjt�rtjt�nd tj| �d �z} ttj| ���d} t |t�} | �s d d tj�vstjt �rtjt �nd dtj�vstj|�rtj|�ndd tj�vstjt�rtjt�nd tj| �d �z} ttj| ���d} t |t�} | �s d d tj�vstjt �rtjt �nd dtj�vstj|�rtj|�nddtj�vstjt�rtjt�ndtj| �d �z} ttj| ���d} ddd�ddd�ddd�y#1swY�xYw#1swY�xYw#1swYyxYw)z4Test wrapper functions with empty or invalid inputs.r r r r)rDr]rgr}�rGrjr�r��result1r�r�N�result2�result3�result4�str)rr+rDr]rgr}r�r�r0r1r.r2r3r4r5r�) r7rDr]rgr}r�r�r�r�r?r@s rA�(test_wrapper_functions_with_empty_inputsz<TestUIErrorHandling.test_wrapper_functions_with_empty_inputs2s��� �;� � ,� �=� !� ,� �(� )� ,� � �.�b�!�4�G�&�r�*�G�)�"�k�:�G�)�"�-�G��g�t�,� ,�,� ,� ,� ,� ,� ,�:� ,� ,� ,�:� ,� ,� ,� ,� ,� ,�g� ,� ,� ,�g� ,� ,� ,� ,� ,� ,�t� ,� ,� ,�t� ,� ,� ,�,� ,� ,� ,� ,� ,� ,��g�t�,� ,�,� ,� ,� ,� ,� ,�:� ,� ,� ,�:� ,� ,� ,� ,� ,� ,�g� ,� ,� ,�g� ,� ,� ,� ,� ,� ,�t� ,� ,� ,�t� ,� ,� ,�,� ,� ,� ,� ,� ,� ,��g�t�,� ,�,� ,� ,� ,� ,� ,�:� ,� ,� ,�:� ,� ,� ,� ,� ,� ,�g� ,� ,� ,�g� ,� ,� ,� ,� ,� ,�t� ,� ,� ,�t� ,� ,� ,�,� ,� ,� ,� ,� ,� ,��g�s�+� +�+� +� +� +� +� +�:� +� +� +�:� +� +� +� +� +� +�g� +� +� +�g� +� +� +� +� +� +�s� +� +� +�s� +� +� +�+� +� +� +� +� +� +�+ ,� ,� ,� ,� ,�� ,� ,�� ,� ,�s:� T� S8�R/S,�S8�T�,S5 �1S8�8T �=T�T c � �td�5td�5td�5ddlm}m}m}m}|�}|�}|�}|�}t |t�} | �s ddtj�vstjt �rtjt �nddtj�vstj|�rtj|�ndd tj�vstjt�rtjt�nd tj| �d �z} ttj| ���d } t |t�} | �s ddtj�vstjt �rtjt �ndd tj�vstj|�rtj|�nd d tj�vstjt�rtjt�nd tj| �d �z} ttj| ���d } t |t�} | �s ddtj�vstjt �rtjt �ndd tj�vstj|�rtj|�nd d tj�vstjt�rtjt�nd tj| �d �z} ttj| ���d } t |t�} | �s ddtj�vstjt �rtjt �nddtj�vstj|�rtj|�ndd tj�vstjt�rtjt�nd tj| �d �z} ttj| ���d } d d d �d d d �d d d �y #1swY�xYw#1swY�xYw#1swYy xYw)z7Test that all endpoints return proper response formats.r r r r)r�r�r�r�r�r��healthr�r�N� performance�cache�sandbox)rr+r�r�r�r�r�r�r0r1r.r2r3r4r5) r7r�r�r�r�r�r�r�r�r?r@s rA�test_endpoint_response_formatsz2TestUIErrorHandling.test_endpoint_response_formatsKs��� �;� � -� �=� !� -� �(� )� -� � �'�(�F�1�3�K�$�&�E�2�4�G��f�d�+� +�+� +� +� +� +� +�:� +� +� +�:� +� +� +� +� +� +�f� +� +� +�f� +� +� +� +� +� +�d� +� +� +�d� +� +� +�+� +� +� +� +� +� +��k�4�0� 0�0� 0� 0� 0� 0� 0�:� 0� 0� 0�:� 0� 0� 0� 0� 0� 0�k� 0� 0� 0�k� 0� 0� 0� 0� 0� 0�4� 0� 0� 0�4� 0� 0� 0�0� 0� 0� 0� 0� 0� 0��e�T�*� *�*� *� *� *� *� *�:� *� *� *�:� *� *� *� *� *� *�e� *� *� *�e� *� *� *� *� *� *�T� *� *� *�T� *� *� *�*� *� *� *� *� *� *��g�t�,� ,�,� ,� ,� ,� ,� ,�:� ,� ,� ,�:� ,� ,� ,� ,� ,� ,�g� ,� ,� ,�g� ,� ,� ,� ,� ,� ,�t� ,� ,� ,�t� ,� ,� ,�,� ,� ,� ,� ,� ,� ,�) -� -� -� -� -�� -� -�� -� -�s:� S>� S2�R)S&� S2�S>�&S/ �+S2�2S; �7S>�>Tc��td�5td�5td�5ddlm}m}m}m}m}m}m}td�5td�5td�5td �5td �5td �5td �5t|�}|s�d dtj�vstjt�rtjt�nddtj�vstj|�rtj|�ndtj|�d�z} ttj | ���d}t|�}|s�d dtj�vstjt�rtjt�nddtj�vstj|�rtj|�ndtj|�d�z} ttj | ���d}t|�}|s�d dtj�vstjt�rtjt�nddtj�vstj|�rtj|�ndtj|�d�z} ttj | ���d}t|�}|s�d dtj�vstjt�rtjt�nddtj�vstj|�rtj|�ndtj|�d�z} ttj | ���d}t|�}|s�d dtj�vstjt�rtjt�nddtj�vstj|�rtj|�ndtj|�d�z} ttj | ���d}t|�}|s�d dtj�vstjt�rtjt�nddtj�vstj|�rtj|�ndtj|�d�z} ttj | ���d}t|�}|s�d dtj�vstjt�rtjt�nddtj�vstj|�rtj|�ndtj|�d�z} ttj | ���d}ddd�ddd�ddd�ddd�ddd�ddd�ddd�ddd�ddd�ddd�y#1swY�RxYw#1swY�VxYw#1swY�ZxYw#1swY�^xYw#1swY�bxYw#1swY�fxYw#1swY�jxYw#1swY�nxYw#1swY�rxYw#1swYyxYw)zBTest that wrapper functions are compatible with Gradio interfaces.r r r r)r rDr]rgrorvr}rrEr^rhrprwr~�,assert %(py3)s {%(py3)s = %(py0)s(%(py1)s) }�callabler �rrr NrDr]rgrorvr})rr+r rDr]rgrorvr}r�r0r1r.r2r3r4r5) r7r rDr]rgrorvr}r9rUs rA�#test_gradio_interface_compatibilityz7TestUIErrorHandling.test_gradio_interface_compatibilitycs2�� �;� � 5� �=� !� 5� �(� )� 5�  � � ��)�*� 5��.�/� 5��'�(� 5��*�+� 5��/�0�  5� �+�,�  5� �(�)�  5� � 2�3�3�3�3�3�3�3�3�x�3�3�3�x�3�3�3�3�3�3� 2�3�3�3� 2�3�3�3�3�3�3�3�3�3�3�� 7�8�8�8�8�8�8�8�8�x�8�8�8�x�8�8�8�8�8�8� 7�8�8�8� 7�8�8�8�8�8�8�8�8�8�8�� 0�1�1�1�1�1�1�1�1�x�1�1�1�x�1�1�1�1�1�1� 0�1�1�1� 0�1�1�1�1�1�1�1�1�1�1�� 3�4�4�4�4�4�4�4�4�x�4�4�4�x�4�4�4�4�4�4� 3�4�4�4� 3�4�4�4�4�4�4�4�4�4�4�� 8�9�9�9�9�9�9�9�9�x�9�9�9�x�9�9�9�9�9�9� 8�9�9�9� 8�9�9�9�9�9�9�9�9�9�9�� 4�5�5�5�5�5�5�5�5�x�5�5�5�x�5�5�5�5�5�5� 4�5�5�5� 4�5�5�5�5�5�5�5�5�5�5�� 3�4�4�4�4�4�4�4�4�x�4�4�4�x�4�4�4�4�4�4� 3�4�4�4� 3�4�4�4�4�4�4�4�4�4�4� 5� 5� 5� 5� 5� 5� 5�# 5� 5� 5� 5�" 5� 5�� 5� 5�� 5� 5�� 5� 5�� 5� 5�� 5� 5�� 5� 5��# 5� 5�� 5� 5�� 5� 5�s�� [?� [3�['� [ � [ � [ �& Z7�2 Z+�> Z� V8Z�Z� Z+�Z7�[ �"[ �*[ �2['�:[3�[?�Z�Z�Z(�$Z+�+Z4�0Z7�7[�<[ �[ �[ �[�[ �[$ � ['�'[0 �,[3�3[< �8[?�?\N)r�r�r�r�r�r�r�r�r�r�rAr�r�s��0�1�&,�2-�0"5r�r�c�"�eZdZdZd�Zd�Zd�Zy)�TestMCPServerEndpointsz#Test MCP server specific endpoints.c �@�td�5td�5td�5ddlm}m}m}m}m}|j}d}||u}|s�tjd|fd||f�d tj�vstj|�rtj|�nd tj|�tj|�d �z} d d | iz} ttj| ���dx}x}}|j}d}||u}|s�tjd|fd||f�d tj�vstj|�rtj|�nd tj|�tj|�d �z} d d | iz} ttj| ���dx}x}}t!|�} | s�ddtj�vstjt �rtjt �ndd tj�vstj|�rtj|�nd tj| �d�z} ttj| ���d} t!|�} | s�ddtj�vstjt �rtjt �ndd tj�vstj|�rtj|�nd tj| �d�z} ttj| ���d} ddd�ddd�ddd�y#1swY�xYw#1swY�xYw#1swYyxYw)z/Test that MCP functions have proper signatures.r r r r)r�r�r�r�r�N)�is not)z3%(py2)s {%(py2)s = %(py0)s.__doc__ } is not %(py5)sr�)rrNrKzassert %(py7)srOr�r�r�r�)rr+r�r�r�r�r�r�r.r/r0r1r2r3r4r5r�) r7r�r�r�r�r�rWr;r?rVrYr9rUs rA�test_mcp_function_signaturesz3TestMCPServerEndpoints.test_mcp_function_signatures�s$�� �;� � /� �=� !� /� �(� )� /�  � �0�7�7� C�t� C�7�t�C� C� C� C�7�t� C� C� C� C� C� C�/� C� C� C�/� C� C� C�7� C� C� C�t� C� C� C� C� C� C� C�$�,�,� 8�D� 8�,�D�8� 8� 8� 8�,�D� 8� 8� 8� 8� 8� 8�$� 8� 8� 8�$� 8� 8� 8�,� 8� 8� 8�D� 8� 8� 8� 8� 8� 8� 8��8�9� 9�9� 9� 9� 9� 9� 9�8� 9� 9� 9�8� 9� 9� 9� 9� 9� 9�8� 9� 9� 9�8� 9� 9� 9�9� 9� 9� 9� 9� 9� 9��-�.� .�.� .� .� .� .� .�8� .� .� .�8� .� .� .� .� .� .�-� .� .� .�-� .� .� .�.� .� .� .� .� .� .�) /� /� /� /� /�� /� /�� /� /�s:� N� N�L?M<�#N�+N�<N �N�N � N�Nc���td�5td�5td�5ddlm}m}m}ddl}|�}|�}|�} |j |�|j |�|j |�ddd�ddd�ddd�y#ttf$r"}tjd|���Yd}~�Ed}~wwxYw#1swY�NxYw#1swY�RxYw#1swYyxYw)z;Test that MCP endpoints return JSON-serializable responses.r r r r)r�r�r�Nz6MCP endpoint returned non-JSON-serializable response: ) rr+r�r�r��json�dumps� TypeError� ValueError�pytest�fail) r7r�r�r�r�r�r�r��es rA�test_mcp_response_formatsz0TestMCPServerEndpoints.test_mcp_response_formats�s��� �;� � Z� �=� !� Z� �(� )� Z� � � �'�(�F�1�3�K�$�&�E� Z�� � �6�"�� � �;�'�� � �5�!�+ Z� Z� Z� Z��,�z�*� Z�� � �T�UV�TW�X�Y�Y�� Z��- Z� Z�� Z� Z�� Z� Z�s]� C!� C�$C � 3B�<C�C!�C �$C �<C �C �C � C �C�C �C!�!C*c ��td�5td�5td�5ddlm}td�5}td�|j_|d�}t |t�}|�s d d tj�vstjt �rtjt �nd d tj�vstj|�rtj|�nd d tj�vstjt�rtjt�nd tj|�d �z}ttj|���d}ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)z!Test MCP error response handling.r r r rr�rzMCP test errorr�r�r�rr�r�N)rr+r�r�r,r�r�r�r0r1r.r2r3r4r5)r7r�r8rr?r@s rA�test_mcp_error_responsesz/TestMCPServerEndpoints.test_mcp_error_responses�s0�� �;� � 0� �=� !� 0� �(� )� 0� 9��)�*� 0�.?�<E�FV�<W�!�-�-�9�6�n�E��"�&�$�/�/�/�/�/�/�/�/�z�/�/�/�z�/�/�/�/�/�/�&�/�/�/�&�/�/�/�/�/�/�$�/�/�/�$�/�/�/�/�/�/�/�/�/�/� 0�  0� 0� 0� 0�  0� 0��  0� 0�� 0� 0�� 0� 0�r�N)r�r�r�r�r�r�r�r�r�rAr�r��s��-�/�0Z�60r�r�)r��builtinsr0�_pytest.assertion.rewrite� assertion�rewriter.r�� unittest.mockrrr�sys�os�path�insert�dirname�__file__rr�r�r�r�rA�<module>r�s~��3��� �0�0� � �������2�7�7�?�?�2�7�7�?�?�2�7�7�?�?�8�3L�#M�N�O�MC�MC�`i5�i5�XF0�F0r�

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/CodeHalwell/gradio-mcp-agent-hack'

If you have feedback or need assistance with the MCP directory API, please join our Discord server