B
    W\	                 @   s   d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZ dZejdd Zdd	d
Zejjeoe jdddk	dddd Zejjeoe jdddk	dddd Zdd ZdS )    N)PYSIDE2	QtWidgets)	QComboBox)uic)loadUizT
from qtpy.QtWidgets import QComboBox
class _QComboBoxSubclass(QComboBox):
    pass
c          	   c   sN   t | djd}|t W dQ R X tjd| j 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wNr   )	openjoinZstrpathwriteQCOMBOBOX_SUBCLASSsyspathinsertpop)tmpdirf r   2lib/python3.7/site-packages/qtpy/tests/test_uic.pyenabled_qcombobox_subclass   s
    r   c             C   s"   t j }|dkrt dg}|S )z;
    Helper function to return a QApplication instance
    N )r   ZQApplicationinstance)Z	icon_pathZqappr   r   r   get_qapp#   s    
r   ZCIz$It segfaults in our CIs with PYSIDE2)reasonc              C   sF   t  } ttjtjtd}t|jt	j
s2tt|jtsBtdS )zd
    Make sure that the patched loadUi function behaves as expected with a
    simple .ui file.
    ztest.uiN)r   r   osr   r	   dirname__file__
isinstance
pushButtonr   QPushButtonAssertionErrorcomboBoxr   )appuir   r   r   test_load_ui-   s    r#   c          	   C   sf   t  }t| , ddlm} ttjtjt	d}W dQ R X t
|jtjsRtt
|j|sbt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   )_QComboBoxSubclassztest_custom.uiN)r   r   Zqcombobox_subclassr$   r   r   r   r	   r   r   r   r   r   r   r   r    )r   r!   r$   r"   r   r   r   test_load_ui_custom_auto:   s    	
$r%   c              C   sb   t jdd } | dr:ttds*tttdr^tn$dddddg}td	d
 |D s^tdS )z;Test that we load the full uic objects for PyQt5 and PyQt4.QT_APIr   Zpysider   Z
loadUiTypeZ	compileUiZcompileUiDirZwidgetPluginPathc             S   s   g | ]}t t|qS r   )hasattrr   ).0or   r   r   
<listcomp>V   s    z&test_load_full_uic.<locals>.<listcomp>N)	r   environgetlower
startswithr'   r   r   all)r&   Zobjectsr   r   r   test_load_full_uicM   s    
r0   )N)r   r   
contextlibZpytestZqtpyr   r   Zqtpy.QtWidgetsr   r   Zqtpy.uicr   r   contextmanagerr   r   ZmarkZskipifr+   r,   r#   r%   r0   r   r   r   r   <module>   s   

