3
š(ƒh€  ã               @   s’   d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ G dd	„ d	eeƒƒZed
ƒG dd„ deeeƒƒƒZdS )é    )Úunicode_literalsN)Úcontextmanager)ÚLiveServerTestCaseÚtag)Úimport_string)Úwith_metaclass)Úcapfirstc                   s8   e Zd Zg ZdZ‡ fdd„Zedd„ ƒZdd„ Z‡  Z	S )ÚSeleniumTestCaseBaseNc       	         s¼   t t| ƒj| |||ƒ}|js4tdd„ |jƒ D ƒƒ r8|S |jr®|jd }||_tj|j	 }xN|jdd… D ]<}| j| t
dt|ƒ|f ƒ|f||j	dœƒ}t||j|ƒ qjW |S tjdƒ|ƒS )	z¤
        Dynamically create new classes and add them to the test module when
        multiple browsers specs are provided (e.g. --selenium=firefox,chrome).
        c             s   s$   | ]\}}|j d ƒot|ƒV  qdS )ÚtestN)Ú
startswithÚcallable)Ú.0ÚnameÚvalue© r   ú8/tmp/pip-install-q3hcpn_q/Django/django/test/selenium.pyú	<genexpr>   s    z/SeleniumTestCaseBase.__new__.<locals>.<genexpr>r   é   Nz%s%s)ÚbrowserÚ
__module__zNo browsers specified.)Úsuperr	   Ú__new__r   ÚanyÚitemsÚbrowsersÚsysÚmodulesr   Ústrr   ÚsetattrÚ__name__ÚunittestÚskip)	Úclsr   ÚbasesÚattrsZ
test_classZfirst_browserÚmoduler   Zbrowser_test_class)Ú	__class__r   r   r      s     
zSeleniumTestCaseBase.__new__c             C   s   t d| ƒS )Nz)selenium.webdriver.%s.webdriver.WebDriver)r   )r"   r   r   r   r   Úimport_webdriver2   s    z%SeleniumTestCaseBase.import_webdriverc             C   s   | j | jƒƒ S )N)r'   r   )Úselfr   r   r   Úcreate_webdriver6   s    z%SeleniumTestCaseBase.create_webdriver)
r   r   Ú__qualname__r   r   r   Úclassmethodr'   r)   Ú__classcell__r   r   )r&   r   r	      s
   r	   Úseleniumc                   s@   e Zd ZdZe‡ fdd„ƒZe‡ fdd„ƒZedd„ ƒZ‡  Z	S )ÚSeleniumTestCaseé
   c                s*   | j ƒ | _| jj| jƒ tt| ƒjƒ  d S )N)r)   r-   Úimplicitly_waitÚimplicit_waitr   r.   Ú
setUpClass)r"   )r&   r   r   r2   >   s    
zSeleniumTestCase.setUpClassc                s&   t | dƒr| jjƒ  tt| ƒjƒ  d S )Nr-   )Úhasattrr-   Úquitr   r.   Ú_tearDownClassInternal)r"   )r&   r   r   r5   D   s    

z'SeleniumTestCase._tearDownClassInternalc             c   s,   | j jdƒ z
dV  W d| j j| jƒ X dS )z8Context manager that disables the default implicit wait.r   N)r-   r0   r1   )r(   r   r   r   Údisable_implicit_waitM   s    
z&SeleniumTestCase.disable_implicit_wait)
r   r   r*   r1   r+   r2   r5   r   r6   r,   r   r   )r&   r   r.   :   s   	r.   )Ú
__future__r   r   r    Ú
contextlibr   Zdjango.testr   r   Zdjango.utils.module_loadingr   Zdjango.utils.sixr   Zdjango.utils.textr   Útyper	   r.   r   r   r   r   Ú<module>   s   -