o
    b/                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZ ddlmZ ee
G dd	 d	ZG d
d deZG dd deZdS )z+
Tests for L{twisted.application.service}.
    )implementer)BrokenImplementation)verifyObject)ApplicationIProcessIServiceIServiceCollectionService)IPersistable)TestCasec                   @   s`   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdS )AlmostServicea  
    Implement IService in a way that can fail.

    In general, classes should maintain invariants that adhere
    to the interfaces that they claim to implement --
    otherwise, it is a bug.

    This is a buggy class -- the IService implementation is fragile,
    and several methods will break it. These bugs are intentional,
    as the tests trigger them -- and then check that the class,
    indeed, no longer complies with the interface (IService)
    that it claims to comply with.

    Since the verification will, by definition, only fail on buggy classes --
    in other words, those which do not actually support the interface they
    claim to support, we have to write a buggy class to properly verify
    the interface.
    c                 C   s   || _ || _|| _d S )N)nameparentrunning)selfr   r   r    r   G/usr/lib/python3/dist-packages/twisted/application/test/test_service.py__init__-   s   
zAlmostService.__init__c                 C      | ` dS )z
        Probably not a wise method to call.

        This method removes the :code:`name` attribute,
        which has to exist in IService classes.
        N)r   r   r   r   r   makeInvalidByDeletingName2      z'AlmostService.makeInvalidByDeletingNamec                 C   r   )z
        Probably not a wise method to call.

        This method removes the :code:`parent` attribute,
        which has to exist in IService classes.
        N)r   r   r   r   r   makeInvalidByDeletingParent;   r   z)AlmostService.makeInvalidByDeletingParentc                 C   r   )z
        Probably not a wise method to call.

        This method removes the :code:`running` attribute,
        which has to exist in IService classes.
        N)r   r   r   r   r   makeInvalidByDeletingRunningD   r   z*AlmostService.makeInvalidByDeletingRunningc                 C      dS )z\
        See L{twisted.application.service.IService}.

        @param name: ignored
        Nr   )r   r   r   r   r   setNameM       zAlmostService.setNamec                 C   r   )z^
        See L{twisted.application.service.IService}.

        @param parent: ignored
        Nr   )r   r   r   r   r   setServiceParentT   r   zAlmostService.setServiceParentc                 C   r   z>
        See L{twisted.application.service.IService}.
        Nr   r   r   r   r   disownServiceParent[   r   z!AlmostService.disownServiceParentc                 C   r   r   r   r   r   r   r   privilegedStartService`   r   z$AlmostService.privilegedStartServicec                 C   r   r   r   r   r   r   r   startServicee   r   zAlmostService.startServicec                 C   r   r   r   r   r   r   r   stopServicej   r   zAlmostService.stopServiceN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r    r!   r"   r   r   r   r   r      s    			r   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )ServiceInterfaceTestszK
    Tests for L{twisted.application.service.IService} implementation.
    c                 C   s   t dddd| _dS )z;
        Build something that implements IService.
        NF)r   r   r   )r   almostServicer   r   r   r   setUpu   s   zServiceInterfaceTests.setUpc                 C   s   t  }tt| dS )z.
        Service implements IService.
        N)r	   r   r   )r   	myServicer   r   r   test_realService{   s   z&ServiceInterfaceTests.test_realServicec                 C   s   t t| j dS )z4
        AlmostService implements IService.
        N)r   r   r(   r   r   r   r   test_hasAll   s   z!ServiceInterfaceTests.test_hasAllc                 C   F   | j   | t tt| j  W d   dS 1 sw   Y  dS )zI
        AlmostService with no name does not implement IService.
        N)r(   r   assertRaisesr   r   r   r   r   r   r   test_noName      
"z!ServiceInterfaceTests.test_noNamec                 C   r-   )zK
        AlmostService with no parent does not implement IService.
        N)r(   r   r.   r   r   r   r   r   r   r   test_noParent   r0   z#ServiceInterfaceTests.test_noParentc                 C   r-   )zL
        AlmostService with no running does not implement IService.
        N)r(   r   r.   r   r   r   r   r   r   r   test_noRunning   r0   z$ServiceInterfaceTests.test_noRunningN)
r#   r$   r%   r&   r)   r+   r,   r/   r1   r2   r   r   r   r   r'   p   s    r'   c                   @   s   e Zd ZdZdd ZdS )ApplicationTestsz?
    Tests for L{twisted.application.service.Application}.
    c                 C   s\   t d}| ttt| | ttt| | ttt| | ttt| dS )zQ
        Check L{twisted.application.service.Application} instantiation.
        zapp-nameN)r   
assertTruer   r   r   r   r
   )r   appr   r   r   test_applicationComponents   s
   z+ApplicationTests.test_applicationComponentsN)r#   r$   r%   r&   r6   r   r   r   r   r3      s    r3   N)r&   zope.interfacer   zope.interface.exceptionsr   zope.interface.verifyr   twisted.application.servicer   r   r   r   r	   twisted.persisted.sobr
   twisted.trial.unittestr   r   r'   r3   r   r   r   r   <module>   s   W1