
    Vh                     r    d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	 ddl
mZ  G d dej                        Zy)	z#
Tests for L{twisted.names.cache}.
    N)verifyClass)
interfacestask)cachedns)unittestc                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	CachingTestsz+
    Tests for L{cache.CacheResolver}.
    c                 T    t        t        j                  t        j                         y)zK
        L{cache.CacheResolver} implements L{interfaces.IResolver}
        N)r   r   	IResolverr   CacheResolver)selfs    M/home/dcms/DCMS/lib/python3.12/site-packages/twisted/names/test/test_cache.pytest_interfacezCachingTests.test_interface   s     	J((%*=*=>    c                    t        j                  t        j                  dt        j                  t        j
                        t        j                         g g g ffi      }|j                  d      j                  | j                  g g g f      S )N   example.comnametypecls)
r   r   r   QueryMXINtimelookupMailExchangeaddCallbackassertEqual)r   cs     r   test_lookupzCachingTests.test_lookup   sx    		~CFFGIIKRLJ
 ##N3??r2rl
 	
r   c                 V   t        j                  dt         j                  t         j                  dt        j                  dd            gt        j                  dt         j                  t         j                  dt        j                  dd            gt        j                  dt         j                  t         j                  dt        j                  dd            gf}t        j                         }t        j                  dt         j                  t         j                        }t        j                  ||j                         |fi|      }|j                  d       | j                  ||j                         | j                  |j                  d      t         j                        S )z
        Cache entries passed into L{cache.CacheResolver.__init__} get
        cancelled just like entries added with cacheResult
        r   <   	127.0.0.12   (   r   reactor)r   RRHeaderAr   Record_Ar   Clockr   r   r   secondsadvanceassertNotInassertFailurelookupAddressDomainError)r   rclockqueryr   s        r   test_constructorExpiresz$CachingTests.test_constructorExpires*   s*    "CEE3662s||KQS7T "CEE3662s||KQS7T "CEE3662s||KQS7T
$ 

		~CEEsvvF!(< =uM 	b(!!!//."A3??SSr   c                     t        j                  dt         j                  t         j                  dt        j                  dd            gt        j                  dt         j                  t         j                  dt        j                  dd            gt        j                  dt         j                  t         j                  dt        j                  dd            gf}t        j                         }t        j                  |      }|j                  t        j                  dt         j                  t         j                        |       |j                  d        fd	}|j                  d      j                  |      S )
z
        When a cache lookup finds a cached entry from 1 second ago, it is
        returned with a TTL of original TTL minus the elapsed 1 second.
        r   r"   r#   r$   r%   r&   r      c                 *   j                  | d   d   j                  d       j                  | d   d   j                  d       j                  | d   d   j                  d       j                  | d   d   j                  j                  d       y )Nr   ;   r7   1      '   r   )r   ttlr   )resultr   s    r   cbLookupz0CachingTests.test_normalLookup.<locals>.cbLookupl   s    VAYq\--r2VAYq\--r2VAYq\--r2VAYq\..33^Dr   )r   r(   r)   r   r*   r   r+   r   r   cacheResultr   r-   r0   r   )r   r2   r3   r   r?   s   `    r   test_normalLookupzCachingTests.test_normalLookupN   s    "CEE3662s||KQS7T "CEE3662s||KQS7T "CEE3662s||KQS7T
$ 

.	cii^#%%SVVLaPa	E ~.::8DDr   c                 T   t        j                  dt         j                  t         j                  dt        j                  dd            gt        j                  dt         j                  t         j                  dt        j                  dd            gt        j                  dt         j                  t         j                  dt        j                  dd            gf}t        j                         }t        j                  |      }t        j                  dt         j                  t         j                        }|j                  ||       |j                  d       | j                  ||j                         | j                  |j                  d      t         j                        S )zW
        Once the TTL has been exceeded, the result is removed from the cache.
        r   r"   r#   r$   r%   r&   r   )r   r(   r)   r   r*   r   r+   r   r   r   r@   r-   r.   r/   r0   r1   )r   r2   r3   r   r4   s        r   test_cachedResultExpiresz%CachingTests.test_cachedResultExpirest   s$    "CEE3662s||KQS7T "CEE3662s||KQS7T "CEE3662s||KQS7T
$ 

.		~CEEsvvF	eQb(!!!//."A3??SSr   c                 *   t        j                  dt         j                  t         j                  dt        j                  dd            gt        j                  dt         j                  t         j                  dt        j                  dd            gt        j                  dt         j                  t         j                  dt        j                  dd            gf}t        j                         }d |_        t        j                  t        j                  dt         j                  t         j                        |j                         |fi|      }|j                  d	       | j                  |j                  d      t         j                        S )
z
        When the cache is queried exactly as the cached entry should expire but
        before it has actually been cleared, the cache does not return the
        expired entry.
        r   r"   r#   r$   r%   c                       y )N )argskwargss     r   <lambda>z4CachingTests.test_expiredTTLLookup.<locals>.<lambda>   s    r   r   r&   gN@)r   r(   r)   r   r*   r   r+   	callLaterr   r   r   r,   r-   r/   r0   r1   )r   r2   r3   r   s       r   test_expiredTTLLookupz"CachingTests.test_expiredTTLLookup   s%    "CEE3662s||KQS7T "CEE3662s||KQS7T "CEE3662s||KQS7T
$ 

6		~CEEsvvFMMOI 
 	d!!!//."A3??SSr   N)
__name__
__module____qualname____doc__r   r    r5   rA   rC   rK   rF   r   r   r
   r
      s,    ?
"TH$EL TD(Tr   r
   )rO   r   zope.interface.verifyr   twisted.internetr   r   twisted.namesr   r   twisted.trialr   TestCaser
   rF   r   r   <module>rU      s1   
  - - $ "lT8$$ lTr   