o
    tfF                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZ d dlmZ d dlmZ er;ejddd d d	lmZ d
Ze jdd Zdd Zejje	obe obee
edk obejdv dddd Zdd Zdd ZdS )    N)parse)PYSIDE2PYSIDE6PYSIDE_VERSION	QtWidgets)	QComboBox)using_condaZ
pyside2uiczpyside2uic not installed)reason)uiczT
from qtpy.QtWidgets import QComboBox
class _QComboBoxSubclass(QComboBox):
    pass
c                 c   sf    t | d ddd}|t W d   n1 sw   Y  tjdt|  dV  tjd dS )z}
    Context manager that sets up a temporary module with a QComboBox subclass
    and then removes it once we are done.
    zqcombobox_subclass.pywzutf-8)modeencodingNr   )openwriteQCOMBOBOX_SUBCLASSsyspathinsertstrpop)Ztemp_dir_pathf r   \/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/qtpy/tests/test_uic.pyenabled_qcombobox_subclass   s   r   c                 C   sz   t   t jdtdd ttjtj	t
d}W d   n1 s%w   Y  t|jtjs3J t|jts;J dS )zd
    Make sure that the patched loadUi function behaves as expected with a
    simple .ui file.
    ignore.*mode.*categorymessagetest.uiN)warningscatch_warningsfilterwarningsDeprecationWarningr
   loadUiosr   joindirname__file__
isinstance
pushButtonr   QPushButtoncomboBoxr   )qtbotuir   r   r   test_load_ui.   s   
r/   z6.5)darwinlinuxz>pyside6-uic command not contained in all conda-forge packages.c                 C   s   t    t jdtdd ttjtj	t
d\}}W d   n1 s'w   Y  |jdks3J G dd d||}| }t|tjsGJ t|jtjsPJ t|jtsXJ dS )	zh
    Make sure that the patched loadUiType function behaves as expected with a
    simple .ui file.
    r   r   r   r   NZUi_Formc                       s   e Zd Z fddZ  ZS )z!test_load_ui_type.<locals>.Widgetc                    s   t    | |  d S N)super__init__ZsetupUi)self	__class__r   r   r4   W   s   
z*test_load_ui_type.<locals>.Widget.__init__)__name__
__module____qualname__r4   __classcell__r   r   r6   r   WidgetV   s    r<   )r    r!   r"   r#   r
   
loadUiTyper%   r   r&   r'   r(   r8   r)   r   ZQWidgetr*   r+   r,   r   )r-   Zui_typeZui_base_typer<   r.   r   r   r   test_load_ui_type?   s    

	r>   c              	   C   s   t |8 ddlm} t  tjdtdd tt	j
t	j
td}W d   n1 s0w   Y  W d   n1 s?w   Y  t|jtjsMJ t|j|sUJ dS )z
    Test that we can load a .ui file with custom widgets without having to
    explicitly specify a dictionary of custom widgets, even in the case of
    PySide.
    r   )_QComboBoxSubclassr   r   r   ztest_custom.uiN)r   Zqcombobox_subclassr?   r    r!   r"   r#   r
   r$   r%   r   r&   r'   r(   r)   r*   r   r+   r,   )r-   Ztmp_pathr?   r.   r   r   r   test_load_ui_custom_autoa   s    

r@   c                  C   s^   t jdd } | drttdsJ ttdsJ d	S g d}tdd |D s-J d	S )
z'Test that we load the full uic objects.QT_API Zpysider$   r=   )Z	compileUiZcompileUiDirr$   r=   ZwidgetPluginPathc                 s   s    | ]}t t|V  qd S r2   )hasattrr
   ).0or   r   r   	<genexpr>   s    z%test_load_full_uic.<locals>.<genexpr>N)r%   environgetlower
startswithrC   r
   all)rA   objectsr   r   r   test_load_full_uicx   s   
rM   )
contextlibr%   r   r    ZpytestZpackaging.versionr   Zqtpyr   r   r   r   Zqtpy.QtWidgetsr   Zqtpy.tests.utilsr   Zimportorskipr
   r   contextmanagerr   r/   markZskipifplatformr>   r@   rM   r   r   r   r   <module>   s8    

