ó
ù`]c           @   s¦   d  Z  d d l Z d d l Z d d l m Z y d d l Z Wn e k
 r_ Z e d ƒ ‚ n Xd d l m	 Z	 d e j
 f d „  ƒ  YZ e d k r¢ e j ƒ  n  d S(	   s+   
Tests for static parts of Twitter package
iÿÿÿÿN(   t   SkipTests+   The twython library has not been installed.(   t   Authenticatet   TestCredentialsc           B   sƒ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   sT   
    Tests that Twitter credentials information from file is handled correctly.
    c         C   sA   t  j j t  j j t ƒ d ƒ |  _ t ƒ  |  _ d t  j d <d  S(   Nt   filess   twitter-filest   TWITTER(	   t   ost   patht   joint   dirnamet   __file__t   subdirR   t   autht   environ(   t   self(    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   setUp   s    $c         C   s3   t  j j |  j j ƒ } |  j | t  j d ƒ d S(   sI   
        Test that environment variable has been read correctly.
        R   N(   R   R   t   basenameR   t   creds_subdirt   assertEqualR   (   R   t   fn(    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_environment   s    c         C   so   y |  j  j d d ƒ WnD t k
 r* nA t k
 r: n1 t k
 r] } |  j d | ƒ n X|  j d ƒ d S(   sE   
        Setting subdir to empty path should raise an error.
        R
   t    s   Unexpected exception thrown: %ss   OSError exception not thrown.N(   R   t
   load_credst   OSErrort
   ValueErrort	   Exceptiont   fail(   R   t   e(    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_empty_subdir1#   s    c         C   se   d |  j _ y |  j j ƒ  Wn4 t k
 r0 n1 t k
 rS } |  j d | ƒ n X|  j d ƒ d S(   sA   
        Setting subdir to `None` should raise an error.
        s   Unexpected exception thrown: %ss    ValueError exception not thrown.N(   t   NoneR   R   R   R   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_empty_subdir24   s    c         C   so   y |  j  j d d ƒ WnD t k
 r* nA t k
 r: n1 t k
 r] } |  j d | ƒ n X|  j d ƒ d S(   sP   
        Setting subdir to nonexistent directory should raise an error.
        R
   s
   /nosuchdirs   Unexpected exception thrown: %ss   OSError exception not thrown.N(   R   R   R   R   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_missingdirB   s    c         C   si   y |  j  j ƒ  WnD t k
 r$ nA t k
 r4 n1 t k
 rW } |  j d | ƒ n X|  j d ƒ d S(   sœ   
        Defaults for authentication will fail since 'credentials.txt' not
        present in default subdir, as read from `os.environ['TWITTER']`.
        s   Unexpected exception thrown: %ss   OSError exception not thrown.N(   R   R   R   R   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_missingfile1S   s    c         C   so   y |  j  j d d ƒ WnD t k
 r* nA t k
 r: n1 t k
 r] } |  j d | ƒ n X|  j d ƒ d S(   sN   
        Credentials file 'foobar' cannot be found in default subdir.
        t
   creds_filet   foobars   Unexpected exception thrown: %ss   OSError exception not thrown.N(   R   R   R   R   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_missingfile2e   s    c         C   sh   y  |  j  j d d d |  j ƒ Wn4 t k
 r3 n1 t k
 rV } |  j d | ƒ n X|  j d ƒ d S(   sC   
        Credentials file 'bad_oauth1-1.txt' is incomplete
        R    s   bad_oauth1-1.txtR
   s   Unexpected exception thrown: %ss    ValueError exception not thrown.N(   R   R   R
   R   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_incomplete_filev   s     c         C   sh   y  |  j  j d d d |  j ƒ Wn4 t k
 r3 n1 t k
 rV } |  j d | ƒ n X|  j d ƒ d S(   sP   
        First key in credentials file 'bad_oauth1-2.txt' is ill-formed
        R    s   bad_oauth1-2.txtR
   s   Unexpected exception thrown: %ss    ValueError exception not thrown.N(   R   R   R
   R   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_malformed_file1ƒ   s     c         C   sh   y  |  j  j d d d |  j ƒ Wn4 t k
 r3 n1 t k
 rV } |  j d | ƒ n X|  j d ƒ d S(   sP   
        First key in credentials file 'bad_oauth1-2.txt' is ill-formed
        R    s   bad_oauth1-3.txtR
   s   Unexpected exception thrown: %ss    ValueError exception not thrown.N(   R   R   R
   R   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_malformed_file2   s     c         C   s>   |  j  j d |  j ƒ t j j |  j |  j  j ƒ |  j  _ d S(   sb   
        Path to default credentials file is well-formed, given specified
        subdir.
        R
   N(   R   R   R
   R   R   R   R    t   creds_fullpath(   R   (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_correct_path   s    c         C   s0   |  j  j d |  j ƒ |  j |  j  j d ƒ d S(   s8   
        Default credentials file is identified
        R
   s   credentials.txtN(   R   R   R
   R   R    (   R   (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_correct_file1¥   s    c         C   s0   |  j  j d |  j ƒ } |  j | d d ƒ d S(   sC   
        Default credentials file has been read correctluy
        R
   t   app_keyt   aN(   R   R   R
   R   (   R   t   oauth(    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   test_correct_file2¬   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R"   R#   R$   R%   R'   R(   R,   (    (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyR      s   												t   __main__(   R/   R   t   unittestt   noseR    t   twythont   ImportErrorR   t   nltk.twitterR   t   TestCaseR   R-   t   main(    (    (    s?   lib/python2.7/site-packages/nltk/test/unit/test_twitter_auth.pyt   <module>   s   ¢