U
    
W[¢  ã                   @   s¨   d Z ddlmZmZ ddlZddlmZ ddlmZ dZ	dZ
G dd	„ d	eƒZG d
d„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ deƒZG dd„ deeƒZdS )z"
Tests for positioning sentences.
é    )Úabsolute_importÚdivisionN)Ú	_sentence)ÚTestCaseZsomeStringValueZsomeOtherStringValuec                   @   s   e Zd ZdZedd„ ƒZdS )ÚDummyProtocolz"
    A simple, fake protocol.
    c                   C   s
   dt tgS )NÚtype)ÚsentinelValueOneÚsentinelValueTwo© r
   r
   úH/usr/lib/python3/dist-packages/twisted/positioning/test/test_sentence.pyÚgetSentenceAttributes   s    z#DummyProtocol.getSentenceAttributesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r
   r
   r
   r   r      s   r   c                   @   s   e Zd ZdZe ¡ ZdS )ÚDummySentencez*
    A sentence for L{DummyProtocol}.
    N)r   r   r   r   r   r   ÚALLOWED_ATTRIBUTESr
   r
   r
   r   r      s   r   c                   @   s   e Zd ZdZdeedgiZdS )ÚMixinProtocolzŒ
    A simple, fake protocol that declaratively tells you the sentences
    it produces using L{base.PositioningSentenceProducerMixin}.
    N)r   r   r   r   r   r	   Ú_SENTENCE_CONTENTSr
   r
   r
   r   r   &   s   ýÿr   c                   @   s   e Zd ZdZe ¡ ZdS )ÚMixinSentencez*
    A sentence for L{MixinProtocol}.
    N)r   r   r   r   r   r   r   r
   r
   r
   r   r   5   s   r   c                   @   sJ   e Zd ZdZdd„ Zdd„ Zdd„ ZdZd	Zddd„Z	dd„ Z
dd„ ZdS )ÚSentenceTestsMixinzI
    Tests for positioning protocols and their respective sentences.
    c                 C   s:   t ƒ }|  t|i¡}|  t|tƒ|¡ |  t|tƒ¡ dS )z¶
        A sentence attribute gets the correct value, and accessing an
        unset attribute (which is specified as being a valid sentence
        attribute) gets L{None}.
        N)ÚobjectÚsentenceClassr   ÚassertEqualÚgetattrZassertIsNoner	   )ÚselfZthisSentinelÚsentencer
   r
   r   Útest_attributeAccessA   s    z'SentenceTestsMixin.test_attributeAccessc                 C   s   |   i ¡}|  tt|d¡ dS )zM
        Accessing a nonexistent attribute raises C{AttributeError}.
        ÚBOGUSN©r   ZassertRaisesÚAttributeErrorr   ©r   r   r
   r
   r   Ú"test_raiseOnMissingAttributeAccessM   s    
z5SentenceTestsMixin.test_raiseOnMissingAttributeAccessc                 C   s"   |   ddi¡}|  tt|d¡ dS )z‹
        Accessing bogus attributes raises C{AttributeError}, *even*
        when that attribute actually is in the sentence data.
        r   Nr    r"   r
   r
   r   Útest_raiseOnBadAttributeAccessU   s    z1SentenceTestsMixin.test_raiseOnBadAttributeAccessZtummiesz<%s (%s) {%s}>úunknown typeÚ c                 C   s   | j j}| j|||f S )aQ  
        Builds the expected repr for a sentence.

        @param sentenceType: The name of the sentence type (e.g "GPGGA").
        @type sentenceType: C{str}
        @param dataRepr: The repr of the data in the sentence.
        @type dataRepr: C{str}
        @return: The expected repr of the sentence.
        @rtype: C{str}
        )r   r   ÚreprTemplate)r   ÚsentenceTypeZdataReprZclsNamer
   r
   r   Ú_expectedReprb   s    z SentenceTestsMixin._expectedReprc                 C   s&   |   i ¡}|  ¡ }|  t|ƒ|¡ dS )zE
        Test the repr of an empty sentence of unknown type.
        N)r   r)   r   Úrepr©r   r   ZexpectedReprr
   r
   r   Útest_unknownTypeReprq   s    
z'SentenceTestsMixin.test_unknownTypeReprc                 C   s0   |   d| ji¡}|  | j¡}|  t|ƒ|¡ dS )zC
        Test the repr of an empty sentence of known type.
        r   N)r   r(   r)   r   r*   r+   r
   r
   r   Útest_knownTypeReprz   s    z%SentenceTestsMixin.test_knownTypeReprN)r%   r&   )r   r   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S )Ú
MixinTestszm
    Tests for protocols deriving from L{base.PositioningSentenceProducerMixin}
    and their sentences.
    c                 C   s   t ƒ | _t| _d S )N)r   Úprotocolr   r   )r   r
   r
   r   ÚsetUp‰   s    zMixinTests.setUpc                 C   s<   | j  ¡ }|  d|¡ | j j}tj| ¡ Ž }|  d|¡ dS )aò  
        L{None} does not appear in the sentence attributes of the
        protocol, even though it's in the specification.

        This is because L{None} is a placeholder for parts of the sentence you
        don't really need or want, but there are some bits later on in the
        sentence that you do want. The alternative would be to have to specify
        things like "_UNUSED0", "_UNUSED1"... which would end up cluttering
        the sentence data and eventually adapter state.
        N)r/   r   ZassertNotInr   Ú	itertoolsÚchainÚvaluesZassertIn)r   ZsentenceAttributesZsentenceContentsZsentenceSpecAttributesr
   r
   r   Útest_noNoneInSentenceAttributesŽ   s
    
z*MixinTests.test_noNoneInSentenceAttributesN)r   r   r   r   r0   r4   r
   r
   r
   r   r.   „   s   r.   )r   Z
__future__r   r   r1   Ztwisted.positioningr   Ztwisted.trial.unittestr   r   r	   r   r   Z_BaseSentencer   Z!_PositioningSentenceProducerMixinr   r   r   r.   r
   r
   r
   r   Ú<module>   s   
G