<s> """<STR_LIT>""" <EOL> import os <EOL> from mock import patch <EOL> from . . dochelpers import single_or_plural , borrowdoc , borrowkwargs <EOL> from . . dochelpers import exc_str <EOL> from . utils import assert_equal , assert_true <EOL> from . utils import assert_re_in <EOL> def test_basic ( ) : <EOL> assert_equal ( single_or_plural ( '<STR_LIT:a>' , '<STR_LIT:b>' , <NUM_LIT:1> ) , '<STR_LIT:a>' ) <EOL> assert_equal ( single_or_plural ( '<STR_LIT:a>' , '<STR_LIT:b>' , <NUM_LIT:0> ) , '<STR_LIT:b>' ) <EOL> assert_equal ( single_or_plural ( '<STR_LIT:a>' , '<STR_LIT:b>' , <NUM_LIT> ) , '<STR_LIT:b>' ) <EOL> def test_borrow_doc ( ) : <EOL> class A ( object ) : <EOL> def met1 ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def met2 ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class B ( object ) : <EOL> @ borrowdoc ( A ) <EOL> def met1 ( self ) : <EOL> pass <EOL> @ borrowdoc ( A , '<STR_LIT>' ) <EOL> def met2 ( self ) : <EOL> pass <EOL> assert_equal ( B . met1 . __doc__ , A . met1 . __doc__ ) <EOL> assert_equal ( B . met2 . __doc__ , A . met1 . __doc__ ) <EOL> def test_borrow_kwargs ( ) : <EOL> class A ( object ) : <EOL> def met1 ( self , kp1 = None , kp2 = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def met2 ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class B ( object ) : <EOL> @ borrowkwargs ( A ) <EOL> def met1 ( self , bu , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ borrowkwargs ( A , '<STR_LIT>' ) <EOL> def met_nodoc ( self , ** kwargs ) : <EOL> pass <EOL> @ borrowkwargs ( A , '<STR_LIT>' ) <EOL> def met_nodockwargs ( self , bogus = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> if True : <EOL> @ borrowkwargs ( A , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> def met_excludes ( self , boguse = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> assert_true ( '<STR_LIT>' in B . met1 . __doc__ ) <EOL> for m in ( B . met1 , <EOL> B . met_nodoc , <EOL> B . met_nodockwargs , <EOL> B . met_excludes ) : <EOL> docstring = m . __doc__ <EOL> assert_true ( '<STR_LIT>' in docstring ) <EOL> assert_true ( not '<STR_LIT>' in docstring , <EOL> msg = "<STR_LIT>" <EOL> "<STR_LIT>" % ( docstring , m ) ) <EOL> assert_true ( '<STR_LIT>' in docstring ) <EOL> assert_true ( ( ( '<STR_LIT>' in docstring ) <EOL> ^ ( m == B . met_excludes ) ) ) <EOL> assert_true ( not '<STR_LIT:U+0020>' in docstring ) <EOL> assert_true ( '<STR_LIT>' in B . met1 . __doc__ ) <EOL> assert_true ( '<STR_LIT>' in B . met_nodockwargs . __doc__ ) <EOL> assert_true ( '<STR_LIT>' in B . met_excludes . __doc__ ) <EOL> def test_exc_str ( ) : <EOL> try : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> except Exception as e : <EOL> estr = exc_str ( e ) <EOL> assert_re_in ( "<STR_LIT>" , estr ) <EOL> def f ( ) : <EOL> def f2 ( ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> f2 ( ) <EOL> try : <EOL> f ( ) <EOL> except Exception as e : <EOL> estr2 = exc_str ( e , <NUM_LIT:2> ) <EOL> estr1 = exc_str ( e , <NUM_LIT:1> ) <EOL> with patch . dict ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:3>' } ) : <EOL> estr3 = exc_str ( e ) <EOL> with patch . dict ( '<STR_LIT>' , { } , clear = True ) : <EOL> estr_ = exc_str ( ) <EOL> assert_re_in ( "<STR_LIT>" , estr3 ) <EOL> assert_re_in ( "<STR_LIT>" , estr2 ) <EOL> assert_re_in ( "<STR_LIT>" , estr1 ) <EOL> assert_equal ( estr_ , estr1 ) </s>
