<s> import py <EOL> import svntestbase <EOL> from py . path import SvnAuth <EOL> import time <EOL> import sys <EOL> svnbin = py . path . local . sysfind ( '<STR_LIT>' ) <EOL> def make_repo_auth ( repo , userdata ) : <EOL> """<STR_LIT>""" <EOL> confdir = py . path . local ( repo ) . join ( '<STR_LIT>' ) <EOL> confdir . join ( '<STR_LIT>' ) . write ( '''<STR_LIT>''' ) <EOL> authzdata = '<STR_LIT>' <EOL> passwddata = '<STR_LIT>' <EOL> for user in userdata : <EOL> authzdata += '<STR_LIT>' % ( user , userdata [ user ] [ <NUM_LIT:1> ] ) <EOL> passwddata += '<STR_LIT>' % ( user , userdata [ user ] [ <NUM_LIT:0> ] ) <EOL> confdir . join ( '<STR_LIT>' ) . write ( authzdata ) <EOL> confdir . join ( '<STR_LIT>' ) . write ( passwddata ) <EOL> def serve_bg ( repopath ) : <EOL> pidfile = py . path . local ( repopath ) . join ( '<STR_LIT>' ) <EOL> port = <NUM_LIT> <EOL> e = None <EOL> while port < <NUM_LIT> : <EOL> cmd = '<STR_LIT>' % ( <EOL> port , pidfile , repopath ) <EOL> print ( cmd ) <EOL> try : <EOL> py . process . cmdexec ( cmd ) <EOL> except py . process . cmdexec . Error : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> else : <EOL> counter = pid = <NUM_LIT:0> <EOL> while counter < <NUM_LIT:10> : <EOL> counter += <NUM_LIT:1> <EOL> try : <EOL> pid = pidfile . read ( ) <EOL> except py . error . ENOENT : <EOL> pass <EOL> if pid : <EOL> break <EOL> time . sleep ( <NUM_LIT> ) <EOL> return port , int ( pid ) <EOL> port += <NUM_LIT:1> <EOL> raise IOError ( '<STR_LIT>' % ( e , ) ) <EOL> class TestSvnAuth ( object ) : <EOL> def test_basic ( self ) : <EOL> auth = SvnAuth ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> assert auth . username == '<STR_LIT:foo>' <EOL> assert auth . password == '<STR_LIT:bar>' <EOL> assert str ( auth ) <EOL> def test_makecmdoptions_uname_pw_makestr ( self ) : <EOL> auth = SvnAuth ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> assert auth . makecmdoptions ( ) == '<STR_LIT>' <EOL> def test_makecmdoptions_quote_escape ( self ) : <EOL> auth = SvnAuth ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert auth . makecmdoptions ( ) == '<STR_LIT>' <EOL> def test_makecmdoptions_no_cache_auth ( self ) : <EOL> auth = SvnAuth ( '<STR_LIT:foo>' , '<STR_LIT:bar>' , cache_auth = False ) <EOL> assert auth . makecmdoptions ( ) == ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_makecmdoptions_no_interactive ( self ) : <EOL> auth = SvnAuth ( '<STR_LIT:foo>' , '<STR_LIT:bar>' , interactive = False ) <EOL> assert auth . makecmdoptions ( ) == ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_makecmdoptions_no_interactive_no_cache_auth ( self ) : <EOL> auth = SvnAuth ( '<STR_LIT:foo>' , '<STR_LIT:bar>' , cache_auth = False , <EOL> interactive = False ) <EOL> assert auth . makecmdoptions ( ) == ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> class svnwc_no_svn ( py . path . svnwc ) : <EOL> def __new__ ( cls , * args , ** kwargs ) : <EOL> self = super ( svnwc_no_svn , cls ) . __new__ ( cls , * args , ** kwargs ) <EOL> self . commands = [ ] <EOL> return self <EOL> def _svn ( self , * args ) : <EOL> self . commands . append ( args ) <EOL> class TestSvnWCAuth ( object ) : <EOL> def setup_method ( self , meth ) : <EOL> if not svnbin : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> self . auth = SvnAuth ( '<STR_LIT:user>' , '<STR_LIT>' , cache_auth = False ) <EOL> def test_checkout ( self ) : <EOL> wc = svnwc_no_svn ( '<STR_LIT:foo>' , auth = self . auth ) <EOL> wc . checkout ( '<STR_LIT:url>' ) <EOL> assert wc . commands [ <NUM_LIT:0> ] [ - <NUM_LIT:1> ] == ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_commit ( self ) : <EOL> wc = svnwc_no_svn ( '<STR_LIT:foo>' , auth = self . auth ) <EOL> wc . commit ( '<STR_LIT>' ) <EOL> assert wc . commands [ <NUM_LIT:0> ] [ - <NUM_LIT:1> ] == ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_checkout_no_cache_auth ( self ) : <EOL> wc = svnwc_no_svn ( '<STR_LIT:foo>' , auth = self . auth ) <EOL> wc . checkout ( '<STR_LIT:url>' ) <EOL> assert wc . commands [ <NUM_LIT:0> ] [ - <NUM_LIT:1> ] == ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_checkout_auth_from_constructor ( self ) : <EOL> wc = svnwc_no_svn ( '<STR_LIT:foo>' , auth = self . auth ) <EOL> wc . checkout ( '<STR_LIT:url>' ) <EOL> assert wc . commands [ <NUM_LIT:0> ] [ - <NUM_LIT:1> ] == ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> class svnurl_no_svn ( py . path . svnurl ) : <EOL> cmdexec_output = '<STR_LIT:test>' <EOL> popen_output = '<STR_LIT:test>' <EOL> def __new__ ( cls , * args , ** kwargs ) : <EOL> self = super ( svnurl_no_svn , cls ) . __new__ ( cls , * args , ** kwargs ) <EOL> self . commands = [ ] <EOL> return self <EOL> def _cmdexec ( self , cmd ) : <EOL> self . commands . append ( cmd ) <EOL> return self . cmdexec_output <EOL> def _popen ( self , cmd ) : <EOL> self . commands . append ( cmd ) <EOL> return self . popen_output <EOL> class TestSvnURLAuth ( object ) : <EOL> def setup_method ( self , meth ) : <EOL> self . auth = SvnAuth ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> def test_init ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' ) <EOL> assert u . auth is None <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> assert u . auth is self . auth <EOL> def test_new ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> new = u . new ( basename = '<STR_LIT:bar>' ) <EOL> assert new . auth is self . auth <EOL> assert new . url == '<STR_LIT>' <EOL> def test_join ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> new = u . join ( '<STR_LIT:foo>' ) <EOL> assert new . auth is self . auth <EOL> assert new . url == '<STR_LIT>' <EOL> def test_listdir ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> u . cmdexec_output = '''<STR_LIT>''' <EOL> paths = u . listdir ( ) <EOL> assert paths [ <NUM_LIT:0> ] . auth is self . auth <EOL> assert paths [ <NUM_LIT:1> ] . auth is self . auth <EOL> assert paths [ <NUM_LIT:0> ] . basename == '<STR_LIT>' <EOL> def test_info ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> def dirpath ( self ) : <EOL> return self <EOL> u . cmdexec_output = '''<STR_LIT>''' <EOL> org_dp = u . __class__ . dirpath <EOL> u . __class__ . dirpath = dirpath <EOL> try : <EOL> info = u . info ( ) <EOL> finally : <EOL> u . dirpath = org_dp <EOL> assert info . size == <NUM_LIT> <EOL> def test_open ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> foo = u . join ( '<STR_LIT:foo>' ) <EOL> foo . check = lambda * args , ** kwargs : True <EOL> ret = foo . open ( ) <EOL> assert ret == '<STR_LIT:test>' <EOL> assert '<STR_LIT>' in foo . commands [ <NUM_LIT:0> ] <EOL> def test_dirpath ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> parent = u . dirpath ( ) <EOL> assert parent . auth is self . auth <EOL> def test_mkdir ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> assert not u . commands <EOL> u . mkdir ( msg = '<STR_LIT>' ) <EOL> assert u . commands <EOL> assert '<STR_LIT>' in u . commands [ <NUM_LIT:0> ] <EOL> def test_copy ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> u2 = svnurl_no_svn ( '<STR_LIT>' ) <EOL> u . copy ( u2 , '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in u . commands [ <NUM_LIT:0> ] <EOL> def test_rename ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> u . rename ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in u . commands [ <NUM_LIT:0> ] <EOL> def test_remove ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> u . remove ( msg = '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in u . commands [ <NUM_LIT:0> ] <EOL> def test_export ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> target = py . path . local ( '<STR_LIT>' ) <EOL> u . export ( target ) <EOL> assert '<STR_LIT>' in u . commands [ <NUM_LIT:0> ] <EOL> def test_log ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> u . popen_output = py . io . TextIO ( py . builtin . _totext ( '''<STR_LIT>''' , '<STR_LIT:ascii>' ) ) <EOL> u . check = lambda * args , ** kwargs : True <EOL> ret = u . log ( <NUM_LIT:10> , <NUM_LIT:20> , verbose = True ) <EOL> assert '<STR_LIT>' in u . commands [ <NUM_LIT:0> ] <EOL> assert len ( ret ) == <NUM_LIT:1> <EOL> assert int ( ret [ <NUM_LIT:0> ] . rev ) == <NUM_LIT> <EOL> assert ret [ <NUM_LIT:0> ] . author == '<STR_LIT>' <EOL> def test_propget ( self ) : <EOL> u = svnurl_no_svn ( '<STR_LIT>' , auth = self . auth ) <EOL> u . propget ( '<STR_LIT:foo>' ) <EOL> assert '<STR_LIT>' in u . commands [ <NUM_LIT:0> ] <EOL> def pytest_funcarg__setup ( request ) : <EOL> return Setup ( request ) <EOL> class Setup : <EOL> def __init__ ( self , request ) : <EOL> if not svnbin : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> if not request . config . option . runslowtests : <EOL> py . test . skip ( '<STR_LIT>' ) <EOL> tmpdir = request . getfuncargvalue ( "<STR_LIT>" ) <EOL> repodir = tmpdir . join ( "<STR_LIT>" ) <EOL> py . process . cmdexec ( '<STR_LIT>' % repodir ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> repodir = '<STR_LIT:/>' + str ( repodir ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> self . repo = py . path . svnurl ( "<STR_LIT>" % repodir ) <EOL> if py . std . sys . platform == '<STR_LIT:win32>' : <EOL> repodir = repodir [ <NUM_LIT:1> : ] <EOL> self . repopath = py . path . local ( repodir ) <EOL> self . temppath = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> self . auth = SvnAuth ( '<STR_LIT>' , '<STR_LIT:foo>' , cache_auth = False , <EOL> interactive = False ) <EOL> make_repo_auth ( self . repopath , { '<STR_LIT>' : ( '<STR_LIT:foo>' , '<STR_LIT>' ) } ) <EOL> self . port , self . pid = serve_bg ( self . repopath . dirpath ( ) ) <EOL> py . path . svnurl . _lsnorevcache . _dict . clear ( ) <EOL> request . addfinalizer ( lambda : py . process . kill ( self . pid ) ) <EOL> class TestSvnWCAuthFunctional : <EOL> def test_checkout_constructor_arg ( self , setup ) : <EOL> wc = py . path . svnwc ( setup . temppath , auth = setup . auth ) <EOL> wc . checkout ( <EOL> '<STR_LIT>' % ( setup . port , setup . repopath . basename ) ) <EOL> assert wc . join ( '<STR_LIT>' ) . check ( ) <EOL> def test_checkout_function_arg ( self , setup ) : <EOL> wc = py . path . svnwc ( setup . temppath , auth = setup . auth ) <EOL> wc . checkout ( <EOL> '<STR_LIT>' % ( setup . port , setup . repopath . basename ) ) <EOL> assert wc . join ( '<STR_LIT>' ) . check ( ) <EOL> def test_checkout_failing_non_interactive ( self , setup ) : <EOL> auth = SvnAuth ( '<STR_LIT>' , '<STR_LIT:bar>' , cache_auth = False , <EOL> interactive = False ) <EOL> wc = py . path . svnwc ( setup . temppath , auth ) <EOL> py . test . raises ( Exception , <EOL> ( "<STR_LIT>" % <EOL> setup . __dict__ ) ) <EOL> def test_log ( self , setup ) : <EOL> wc = py . path . svnwc ( setup . temppath , setup . auth ) <EOL> wc . checkout ( <EOL> '<STR_LIT>' % ( setup . port , setup . repopath . basename ) ) <EOL> foo = wc . ensure ( '<STR_LIT>' ) <EOL> wc . commit ( '<STR_LIT>' ) <EOL> log = foo . log ( ) <EOL> assert len ( log ) == <NUM_LIT:1> <EOL> assert log [ <NUM_LIT:0> ] . msg == '<STR_LIT>' <EOL> def test_switch ( self , setup ) : <EOL> wc = py . path . svnwc ( setup . temppath , auth = setup . auth ) <EOL> svnurl = '<STR_LIT>' % ( setup . port , setup . repopath . basename ) <EOL> wc . checkout ( svnurl ) <EOL> wc . ensure ( '<STR_LIT:foo>' , dir = True ) . ensure ( '<STR_LIT>' ) . write ( '<STR_LIT:foo>' ) <EOL> wc . commit ( '<STR_LIT>' ) <EOL> wc . ensure ( '<STR_LIT:bar>' , dir = True ) <EOL> wc . commit ( '<STR_LIT>' ) <EOL> bar = wc . join ( '<STR_LIT:bar>' ) <EOL> bar . switch ( svnurl + '<STR_LIT>' ) <EOL> assert bar . join ( '<STR_LIT>' ) <EOL> def test_update ( self , setup ) : <EOL> wc1 = py . path . svnwc ( setup . temppath . ensure ( '<STR_LIT>' , dir = True ) , <EOL> auth = setup . auth ) <EOL> wc2 = py . path . svnwc ( setup . temppath . ensure ( '<STR_LIT>' , dir = True ) , <EOL> auth = setup . auth ) <EOL> wc1 . checkout ( <EOL> '<STR_LIT>' % ( setup . port , setup . repopath . basename ) ) <EOL> wc2 . checkout ( <EOL> '<STR_LIT>' % ( setup . port , setup . repopath . basename ) ) <EOL> wc1 . ensure ( '<STR_LIT:foo>' , dir = True ) <EOL> wc1 . commit ( '<STR_LIT>' ) <EOL> wc2 . update ( ) <EOL> assert wc2 . join ( '<STR_LIT:foo>' ) . check ( ) <EOL> auth = SvnAuth ( '<STR_LIT>' , '<STR_LIT>' , interactive = False ) <EOL> wc2 . auth = auth <EOL> py . test . raises ( Exception , '<STR_LIT>' ) <EOL> def test_lock_unlock_status ( self , setup ) : <EOL> port = setup . port <EOL> wc = py . path . svnwc ( setup . temppath , auth = setup . auth ) <EOL> wc . checkout ( <EOL> '<STR_LIT>' % ( port , setup . repopath . basename , ) ) <EOL> wc . ensure ( '<STR_LIT:foo>' , file = True ) <EOL> wc . commit ( '<STR_LIT>' ) <EOL> foo = wc . join ( '<STR_LIT:foo>' ) <EOL> foo . lock ( ) <EOL> status = foo . status ( ) <EOL> assert status . locked <EOL> foo . unlock ( ) <EOL> status = foo . status ( ) <EOL> assert not status . locked <EOL> auth = SvnAuth ( '<STR_LIT>' , '<STR_LIT>' , interactive = False ) <EOL> foo . auth = auth <EOL> py . test . raises ( Exception , '<STR_LIT>' ) <EOL> py . test . raises ( Exception , '<STR_LIT>' ) <EOL> def test_diff ( self , setup ) : <EOL> port = setup . port <EOL> wc = py . path . svnwc ( setup . temppath , auth = setup . auth ) <EOL> wc . checkout ( <EOL> '<STR_LIT>' % ( port , setup . repopath . basename , ) ) <EOL> wc . ensure ( '<STR_LIT:foo>' , file = True ) <EOL> wc . commit ( '<STR_LIT>' ) <EOL> wc . update ( ) <EOL> rev = int ( wc . status ( ) . rev ) <EOL> foo = wc . join ( '<STR_LIT:foo>' ) <EOL> foo . write ( '<STR_LIT:bar>' ) <EOL> diff = foo . diff ( ) <EOL> assert '<STR_LIT>' in diff <EOL> foo . commit ( '<STR_LIT>' ) <EOL> diff = foo . diff ( ) <EOL> assert not diff <EOL> diff = foo . diff ( rev = rev ) <EOL> assert '<STR_LIT>' in diff <EOL> auth = SvnAuth ( '<STR_LIT>' , '<STR_LIT>' , interactive = False ) <EOL> foo . auth = auth <EOL> py . test . raises ( Exception , '<STR_LIT>' ) <EOL> class TestSvnURLAuthFunctional : <EOL> def test_listdir ( self , setup ) : <EOL> port = setup . port <EOL> u = py . path . svnurl ( <EOL> '<STR_LIT>' % ( port , setup . repopath . basename ) , <EOL> auth = setup . auth ) <EOL> u . ensure ( '<STR_LIT:foo>' ) <EOL> paths = u . listdir ( ) <EOL> assert len ( paths ) == <NUM_LIT:1> <EOL> assert paths [ <NUM_LIT:0> ] . auth is setup . auth <EOL> auth = SvnAuth ( '<STR_LIT:foo>' , '<STR_LIT:bar>' , interactive = False ) <EOL> u = py . path . svnurl ( <EOL> '<STR_LIT>' % ( port , setup . repopath . basename ) , <EOL> auth = auth ) <EOL> py . test . raises ( Exception , '<STR_LIT>' ) <EOL> def test_copy ( self , setup ) : <EOL> port = setup . port <EOL> u = py . path . svnurl ( <EOL> '<STR_LIT>' % ( port , setup . repopath . basename ) , <EOL> auth = setup . auth ) <EOL> foo = u . mkdir ( '<STR_LIT:foo>' ) <EOL> assert foo . check ( ) <EOL> bar = u . join ( '<STR_LIT:bar>' ) <EOL> foo . copy ( bar ) <EOL> assert bar . check ( ) <EOL> assert bar . auth is setup . auth <EOL> auth = SvnAuth ( '<STR_LIT:foo>' , '<STR_LIT:bar>' , interactive = False ) <EOL> u = py . path . svnurl ( <EOL> '<STR_LIT>' % ( port , setup . repopath . basename ) , <EOL> auth = auth ) <EOL> foo = u . join ( '<STR_LIT:foo>' ) <EOL> bar = u . join ( '<STR_LIT:bar>' ) <EOL> py . test . raises ( Exception , '<STR_LIT>' ) <EOL> def test_write_read ( self , setup ) : <EOL> port = setup . port <EOL> u = py . path . svnurl ( <EOL> '<STR_LIT>' % ( port , setup . repopath . basename ) , <EOL> auth = setup . auth ) <EOL> foo = u . ensure ( '<STR_LIT:foo>' ) <EOL> fp = foo . open ( ) <EOL> try : <EOL> data = fp . read ( ) <EOL> finally : <EOL> fp . close ( ) <EOL> assert data == '<STR_LIT>' <EOL> auth = SvnAuth ( '<STR_LIT:foo>' , '<STR_LIT:bar>' , interactive = False ) <EOL> u = py . path . svnurl ( <EOL> '<STR_LIT>' % ( port , setup . repopath . basename ) , <EOL> auth = auth ) <EOL> foo = u . join ( '<STR_LIT:foo>' ) <EOL> py . test . raises ( Exception , '<STR_LIT>' ) </s>
