<s> """<STR_LIT>""" <EOL> from __future__ import division , absolute_import <EOL> import os . path , sys <EOL> import shutil , errno , warnings <EOL> try : <EOL> import pwd , grp <EOL> except ImportError : <EOL> pwd = grp = None <EOL> from twisted . trial import unittest <EOL> from twisted . trial . util import suppress as SUPPRESS <EOL> from twisted . python . compat import _PY3 <EOL> from twisted . python import util <EOL> from twisted . python . reflect import fullyQualifiedName <EOL> from twisted . internet import reactor <EOL> from twisted . internet . interfaces import IReactorProcess <EOL> from twisted . internet . protocol import ProcessProtocol <EOL> from twisted . internet . defer import Deferred <EOL> from twisted . internet . error import ProcessDone <EOL> if _PY3 : <EOL> MockOS = None <EOL> else : <EOL> from twisted . test . test_process import MockOS <EOL> class UtilTestCase ( unittest . TestCase ) : <EOL> def testUniq ( self ) : <EOL> l = [ "<STR_LIT:a>" , <NUM_LIT:1> , "<STR_LIT>" , "<STR_LIT:a>" , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] <EOL> self . assertEqual ( util . uniquify ( l ) , [ "<STR_LIT:a>" , <NUM_LIT:1> , "<STR_LIT>" , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:6> ] ) <EOL> def testRaises ( self ) : <EOL> self . failUnless ( util . raises ( ZeroDivisionError , divmod , <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . failIf ( util . raises ( ZeroDivisionError , divmod , <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> try : <EOL> util . raises ( TypeError , divmod , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> except ZeroDivisionError : <EOL> pass <EOL> else : <EOL> raise unittest . FailTest ( "<STR_LIT>" ) <EOL> def test_uidFromNumericString ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( util . uidFromString ( "<STR_LIT:100>" ) , <NUM_LIT:100> ) <EOL> def test_uidFromUsernameString ( self ) : <EOL> """<STR_LIT>""" <EOL> pwent = pwd . getpwuid ( os . getuid ( ) ) <EOL> self . assertEqual ( util . uidFromString ( pwent . pw_name ) , pwent . pw_uid ) <EOL> if pwd is None : <EOL> test_uidFromUsernameString . skip = ( <EOL> "<STR_LIT>" ) <EOL> def test_gidFromNumericString ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( util . gidFromString ( "<STR_LIT:100>" ) , <NUM_LIT:100> ) <EOL> def test_gidFromGroupnameString ( self ) : <EOL> """<STR_LIT>""" <EOL> grent = grp . getgrgid ( os . getgid ( ) ) <EOL> self . assertEqual ( util . gidFromString ( grent . gr_name ) , grent . gr_gid ) <EOL> if grp is None : <EOL> test_gidFromGroupnameString . skip = ( <EOL> "<STR_LIT>" ) <EOL> class NameToLabelTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_nameToLabel ( self ) : <EOL> """<STR_LIT>""" <EOL> nameData = [ <EOL> ( '<STR_LIT:f>' , '<STR_LIT:F>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:foo>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> for inp , out in nameData : <EOL> got = util . nameToLabel ( inp ) <EOL> self . assertEqual ( <EOL> got , out , <EOL> "<STR_LIT>" % ( inp , got , out ) ) <EOL> class UntilConcludesTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_uninterruptably ( self ) : <EOL> """<STR_LIT>""" <EOL> def f ( a , b ) : <EOL> self . calls += <NUM_LIT:1> <EOL> exc = self . exceptions . pop ( ) <EOL> if exc is not None : <EOL> raise exc ( errno . EINTR , "<STR_LIT>" ) <EOL> return a + b <EOL> self . exceptions = [ None ] <EOL> self . calls = <NUM_LIT:0> <EOL> self . assertEqual ( util . untilConcludes ( f , <NUM_LIT:1> , <NUM_LIT:2> ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( self . calls , <NUM_LIT:1> ) <EOL> self . exceptions = [ None , OSError , IOError ] <EOL> self . calls = <NUM_LIT:0> <EOL> self . assertEqual ( util . untilConcludes ( f , <NUM_LIT:2> , <NUM_LIT:3> ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( self . calls , <NUM_LIT:3> ) <EOL> class SwitchUIDTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> if getattr ( os , "<STR_LIT>" , None ) is None : <EOL> skip = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> self . mockos = MockOS ( ) <EOL> self . patch ( util , "<STR_LIT>" , self . mockos ) <EOL> self . patch ( util , "<STR_LIT>" , self . initgroups ) <EOL> self . initgroupsCalls = [ ] <EOL> def initgroups ( self , uid , gid ) : <EOL> """<STR_LIT>""" <EOL> self . initgroupsCalls . append ( ( uid , gid ) ) <EOL> def test_uid ( self ) : <EOL> """<STR_LIT>""" <EOL> util . switchUID ( <NUM_LIT> , None ) <EOL> self . assertEqual ( self . initgroupsCalls , [ ( <NUM_LIT> , None ) ] ) <EOL> self . assertEqual ( self . mockos . actions , [ ( "<STR_LIT>" , <NUM_LIT> ) ] ) <EOL> def test_euid ( self ) : <EOL> """<STR_LIT>""" <EOL> util . switchUID ( <NUM_LIT> , None , True ) <EOL> self . assertEqual ( self . initgroupsCalls , [ ( <NUM_LIT> , None ) ] ) <EOL> self . assertEqual ( self . mockos . seteuidCalls , [ <NUM_LIT> ] ) <EOL> def test_currentUID ( self ) : <EOL> """<STR_LIT>""" <EOL> uid = self . mockos . getuid ( ) <EOL> util . switchUID ( uid , None ) <EOL> self . assertEqual ( self . initgroupsCalls , [ ] ) <EOL> self . assertEqual ( self . mockos . actions , [ ] ) <EOL> warnings = self . flushWarnings ( [ util . switchUID ] ) <EOL> self . assertEqual ( len ( warnings ) , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' % uid , <EOL> warnings [ <NUM_LIT:0> ] [ '<STR_LIT:message>' ] ) <EOL> self . assertIn ( '<STR_LIT>' % uid , warnings [ <NUM_LIT:0> ] [ '<STR_LIT:message>' ] ) <EOL> def test_currentEUID ( self ) : <EOL> """<STR_LIT>""" <EOL> euid = self . mockos . geteuid ( ) <EOL> util . switchUID ( euid , None , True ) <EOL> self . assertEqual ( self . initgroupsCalls , [ ] ) <EOL> self . assertEqual ( self . mockos . seteuidCalls , [ ] ) <EOL> warnings = self . flushWarnings ( [ util . switchUID ] ) <EOL> self . assertEqual ( len ( warnings ) , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' % euid , <EOL> warnings [ <NUM_LIT:0> ] [ '<STR_LIT:message>' ] ) <EOL> self . assertIn ( '<STR_LIT>' % euid , warnings [ <NUM_LIT:0> ] [ '<STR_LIT:message>' ] ) <EOL> class TestMergeFunctionMetadata ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_mergedFunctionBehavesLikeMergeTarget ( self ) : <EOL> """<STR_LIT>""" <EOL> foo_object = object ( ) <EOL> bar_object = object ( ) <EOL> def foo ( ) : <EOL> return foo_object <EOL> def bar ( x , y , ab , c = <NUM_LIT:10> , * d , ** e ) : <EOL> ( a , b ) = ab <EOL> return bar_object <EOL> baz = util . mergeFunctionMetadata ( foo , bar ) <EOL> self . assertIdentical ( baz ( <NUM_LIT:1> , <NUM_LIT:2> , ( <NUM_LIT:3> , <NUM_LIT:4> ) , quux = <NUM_LIT:10> ) , bar_object ) <EOL> def test_moduleIsMerged ( self ) : <EOL> """<STR_LIT>""" <EOL> def foo ( ) : <EOL> pass <EOL> def bar ( ) : <EOL> pass <EOL> bar . __module__ = '<STR_LIT>' <EOL> baz = util . mergeFunctionMetadata ( foo , bar ) <EOL> self . assertEqual ( baz . __module__ , foo . __module__ ) <EOL> def test_docstringIsMerged ( self ) : <EOL> """<STR_LIT>""" <EOL> def foo ( ) : <EOL> """<STR_LIT>""" <EOL> def bar ( ) : <EOL> """<STR_LIT>""" <EOL> baz = util . mergeFunctionMetadata ( foo , bar ) <EOL> self . assertEqual ( baz . __doc__ , foo . __doc__ ) <EOL> def test_nameIsMerged ( self ) : <EOL> """<STR_LIT>""" <EOL> def foo ( ) : <EOL> pass <EOL> def bar ( ) : <EOL> pass <EOL> baz = util . mergeFunctionMetadata ( foo , bar ) <EOL> self . assertEqual ( baz . __name__ , foo . __name__ ) <EOL> def test_instanceDictionaryIsMerged ( self ) : <EOL> """<STR_LIT>""" <EOL> def foo ( ) : <EOL> pass <EOL> foo . a = <NUM_LIT:1> <EOL> foo . b = <NUM_LIT:2> <EOL> def bar ( ) : <EOL> pass <EOL> bar . b = <NUM_LIT:3> <EOL> bar . c = <NUM_LIT:4> <EOL> baz = util . mergeFunctionMetadata ( foo , bar ) <EOL> self . assertEqual ( foo . a , baz . a ) <EOL> self . assertEqual ( foo . b , baz . b ) <EOL> self . assertEqual ( bar . c , baz . c ) <EOL> class OrderedDictTest ( unittest . TestCase ) : <EOL> def testOrderedDict ( self ) : <EOL> d = util . OrderedDict ( ) <EOL> d [ '<STR_LIT:a>' ] = '<STR_LIT:b>' <EOL> d [ '<STR_LIT:b>' ] = '<STR_LIT:a>' <EOL> d [ <NUM_LIT:3> ] = <NUM_LIT:12> <EOL> d [ <NUM_LIT> ] = <NUM_LIT> <EOL> self . assertEqual ( repr ( d ) , "<STR_LIT>" ) <EOL> self . assertEqual ( d . values ( ) , [ '<STR_LIT:b>' , '<STR_LIT:a>' , <NUM_LIT:12> , <NUM_LIT> ] ) <EOL> del d [ <NUM_LIT:3> ] <EOL> self . assertEqual ( repr ( d ) , "<STR_LIT>" ) <EOL> self . assertEqual ( d , { '<STR_LIT:a>' : '<STR_LIT:b>' , '<STR_LIT:b>' : '<STR_LIT:a>' , <NUM_LIT> : <NUM_LIT> } ) <EOL> self . assertEqual ( d . keys ( ) , [ '<STR_LIT:a>' , '<STR_LIT:b>' , <NUM_LIT> ] ) <EOL> self . assertEqual ( list ( d . iteritems ( ) ) , <EOL> [ ( '<STR_LIT:a>' , '<STR_LIT:b>' ) , ( '<STR_LIT:b>' , '<STR_LIT:a>' ) , ( <NUM_LIT> , <NUM_LIT> ) ] ) <EOL> item = d . popitem ( ) <EOL> self . assertEqual ( item , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> def testInitialization ( self ) : <EOL> d = util . OrderedDict ( { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . failUnless ( d . _order ) <EOL> d = util . OrderedDict ( ( ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:3> , <NUM_LIT:3> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> self . assertEqual ( repr ( d ) , "<STR_LIT>" ) <EOL> class InsensitiveDictTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_preserve ( self ) : <EOL> """<STR_LIT>""" <EOL> dct = util . InsensitiveDict ( { '<STR_LIT>' : '<STR_LIT:bar>' , <NUM_LIT:1> : <NUM_LIT:2> , '<STR_LIT>' : { <NUM_LIT:1> : <NUM_LIT:2> } } , preserve = <NUM_LIT:1> ) <EOL> self . assertEqual ( dct [ '<STR_LIT>' ] , { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> self . assertEqual ( dct [ '<STR_LIT:foo>' ] , '<STR_LIT:bar>' ) <EOL> self . assertEqual ( dct . copy ( ) , dct ) <EOL> self . assertEqual ( dct [ '<STR_LIT:foo>' ] , dct . get ( '<STR_LIT>' ) ) <EOL> self . assertIn ( <NUM_LIT:1> , dct ) <EOL> self . assertIn ( '<STR_LIT:foo>' , dct ) <EOL> InsensitiveDict = util . InsensitiveDict <EOL> self . assertEqual ( eval ( repr ( dct ) ) , dct ) <EOL> keys = [ '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ] <EOL> for x in keys : <EOL> self . assertIn ( x , dct . keys ( ) ) <EOL> self . assertIn ( ( x , dct [ x ] ) , dct . items ( ) ) <EOL> self . assertEqual ( len ( keys ) , len ( dct ) ) <EOL> del dct [ <NUM_LIT:1> ] <EOL> del dct [ '<STR_LIT:foo>' ] <EOL> self . assertEqual ( dct . keys ( ) , [ '<STR_LIT>' ] ) <EOL> def test_noPreserve ( self ) : <EOL> """<STR_LIT>""" <EOL> dct = util . InsensitiveDict ( { '<STR_LIT>' : '<STR_LIT:bar>' , <NUM_LIT:1> : <NUM_LIT:2> , '<STR_LIT>' : { <NUM_LIT:1> : <NUM_LIT:2> } } , preserve = <NUM_LIT:0> ) <EOL> keys = [ '<STR_LIT:foo>' , '<STR_LIT>' , <NUM_LIT:1> ] <EOL> for x in keys : <EOL> self . assertIn ( x , dct . keys ( ) ) <EOL> self . assertIn ( ( x , dct [ x ] ) , dct . items ( ) ) <EOL> self . assertEqual ( len ( keys ) , len ( dct ) ) <EOL> del dct [ <NUM_LIT:1> ] <EOL> del dct [ '<STR_LIT:foo>' ] <EOL> self . assertEqual ( dct . keys ( ) , [ '<STR_LIT>' ] ) <EOL> def test_unicode ( self ) : <EOL> """<STR_LIT>""" <EOL> d = util . InsensitiveDict ( preserve = False ) <EOL> d [ u"<STR_LIT>" ] = <NUM_LIT:1> <EOL> self . assertEqual ( d [ u"<STR_LIT>" ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( d . keys ( ) , [ u"<STR_LIT:foo>" ] ) <EOL> def test_bytes ( self ) : <EOL> """<STR_LIT>""" <EOL> d = util . InsensitiveDict ( preserve = False ) <EOL> d [ b"<STR_LIT>" ] = <NUM_LIT:1> <EOL> self . assertEqual ( d [ b"<STR_LIT>" ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( d . keys ( ) , [ b"<STR_LIT:foo>" ] ) <EOL> class PasswordTestingProcessProtocol ( ProcessProtocol ) : <EOL> """<STR_LIT>""" <EOL> def connectionMade ( self ) : <EOL> self . output = [ ] <EOL> self . transport . write ( '<STR_LIT>' ) <EOL> def childDataReceived ( self , fd , output ) : <EOL> self . output . append ( ( fd , output ) ) <EOL> def processEnded ( self , reason ) : <EOL> self . finished . callback ( ( reason , self . output ) ) <EOL> class GetPasswordTest ( unittest . TestCase ) : <EOL> if not IReactorProcess . providedBy ( reactor ) : <EOL> skip = "<STR_LIT>" <EOL> def test_stdin ( self ) : <EOL> """<STR_LIT>""" <EOL> p = PasswordTestingProcessProtocol ( ) <EOL> p . finished = Deferred ( ) <EOL> reactor . spawnProcess ( <EOL> p , <EOL> sys . executable , <EOL> [ sys . executable , <EOL> '<STR_LIT:-c>' , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ] , <EOL> env = { '<STR_LIT>' : os . pathsep . join ( sys . path ) } ) <EOL> def processFinished ( result ) : <EOL> ( reason , output ) = result <EOL> reason . trap ( ProcessDone ) <EOL> self . assertIn ( ( <NUM_LIT:1> , '<STR_LIT>' ) , output ) <EOL> return p . finished . addCallback ( processFinished ) <EOL> class SearchUpwardsTest ( unittest . TestCase ) : <EOL> def testSearchupwards ( self ) : <EOL> os . makedirs ( '<STR_LIT>' ) <EOL> file ( '<STR_LIT>' , '<STR_LIT:w>' ) . close ( ) <EOL> file ( '<STR_LIT>' , '<STR_LIT:w>' ) . close ( ) <EOL> file ( '<STR_LIT>' , '<STR_LIT:w>' ) . close ( ) <EOL> os . mkdir ( '<STR_LIT>' ) <EOL> os . mkdir ( '<STR_LIT>' ) <EOL> os . mkdir ( '<STR_LIT>' ) <EOL> os . mkdir ( '<STR_LIT>' ) <EOL> actual = util . searchupwards ( '<STR_LIT>' , <EOL> files = [ '<STR_LIT>' ] , <EOL> dirs = [ '<STR_LIT:bar>' , '<STR_LIT>' ] ) <EOL> expected = os . path . abspath ( '<STR_LIT>' ) + os . sep <EOL> self . assertEqual ( actual , expected ) <EOL> shutil . rmtree ( '<STR_LIT>' ) <EOL> actual = util . searchupwards ( '<STR_LIT>' , <EOL> files = [ '<STR_LIT>' ] , <EOL> dirs = [ '<STR_LIT:bar>' , '<STR_LIT>' ] ) <EOL> expected = None <EOL> self . assertEqual ( actual , expected ) <EOL> class IntervalDifferentialTestCase ( unittest . TestCase ) : <EOL> def testDefault ( self ) : <EOL> d = iter ( util . IntervalDifferential ( [ ] , <NUM_LIT:10> ) ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:10> , None ) ) <EOL> def testSingle ( self ) : <EOL> d = iter ( util . IntervalDifferential ( [ <NUM_LIT:5> ] , <NUM_LIT:10> ) ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:5> , <NUM_LIT:0> ) ) <EOL> def testPair ( self ) : <EOL> d = iter ( util . IntervalDifferential ( [ <NUM_LIT:5> , <NUM_LIT:7> ] , <NUM_LIT:10> ) ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:5> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:4> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:5> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:4> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:3> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:5> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> def testTriple ( self ) : <EOL> d = iter ( util . IntervalDifferential ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:5> ] , <NUM_LIT:10> ) ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:0> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:0> , <NUM_LIT:2> ) ) <EOL> def testInsert ( self ) : <EOL> d = iter ( util . IntervalDifferential ( [ ] , <NUM_LIT:10> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:10> , None ) ) <EOL> d . addInterval ( <NUM_LIT:3> ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> d . addInterval ( <NUM_LIT:6> ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> def testRemove ( self ) : <EOL> d = iter ( util . IntervalDifferential ( [ <NUM_LIT:3> , <NUM_LIT:5> ] , <NUM_LIT:10> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> d . removeInterval ( <NUM_LIT:3> ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:4> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:5> , <NUM_LIT:0> ) ) <EOL> d . removeInterval ( <NUM_LIT:5> ) <EOL> self . assertEqual ( d . next ( ) , ( <NUM_LIT:10> , None ) ) <EOL> self . assertRaises ( ValueError , d . removeInterval , <NUM_LIT:10> ) <EOL> class Record ( util . FancyEqMixin ) : <EOL> """<STR_LIT>""" <EOL> compareAttributes = ( '<STR_LIT:a>' , '<STR_LIT:b>' ) <EOL> def __init__ ( self , a , b ) : <EOL> self . a = a <EOL> self . b = b <EOL> class DifferentRecord ( util . FancyEqMixin ) : <EOL> """<STR_LIT>""" <EOL> compareAttributes = ( '<STR_LIT:a>' , '<STR_LIT:b>' ) <EOL> def __init__ ( self , a , b ) : <EOL> self . a = a <EOL> self . b = b <EOL> class DerivedRecord ( Record ) : <EOL> """<STR_LIT>""" <EOL> class EqualToEverything ( object ) : <EOL> """<STR_LIT>""" <EOL> def __eq__ ( self , other ) : <EOL> return True <EOL> def __ne__ ( self , other ) : <EOL> return False <EOL> class EqualToNothing ( object ) : <EOL> """<STR_LIT>""" <EOL> def __eq__ ( self , other ) : <EOL> return False <EOL> def __ne__ ( self , other ) : <EOL> return True <EOL> class EqualityTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_identity ( self ) : <EOL> """<STR_LIT>""" <EOL> class Empty ( util . FancyEqMixin ) : <EOL> pass <EOL> self . assertFalse ( Empty ( ) == Empty ( ) ) <EOL> self . assertTrue ( Empty ( ) != Empty ( ) ) <EOL> empty = Empty ( ) <EOL> self . assertTrue ( empty == empty ) <EOL> self . assertFalse ( empty != empty ) <EOL> def test_equality ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == Record ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == Record ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == Record ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == Record ( <NUM_LIT:3> , <NUM_LIT:4> ) ) <EOL> def test_unequality ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != Record ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != Record ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != Record ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != Record ( <NUM_LIT:3> , <NUM_LIT:4> ) ) <EOL> def test_differentClassesEquality ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == DifferentRecord ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> def test_differentClassesInequality ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != DifferentRecord ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> def test_inheritedClassesEquality ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == DerivedRecord ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == DerivedRecord ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == DerivedRecord ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == DerivedRecord ( <NUM_LIT:3> , <NUM_LIT:4> ) ) <EOL> def test_inheritedClassesInequality ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != DerivedRecord ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != DerivedRecord ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != DerivedRecord ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != DerivedRecord ( <NUM_LIT:3> , <NUM_LIT:4> ) ) <EOL> def test_rightHandArgumentImplementsEquality ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == EqualToEverything ( ) ) <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) == EqualToNothing ( ) ) <EOL> def test_rightHandArgumentImplementsUnequality ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertFalse ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != EqualToEverything ( ) ) <EOL> self . assertTrue ( Record ( <NUM_LIT:1> , <NUM_LIT:2> ) != EqualToNothing ( ) ) <EOL> class RunAsEffectiveUserTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> if getattr ( os , "<STR_LIT>" , None ) is None : <EOL> skip = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> self . mockos = MockOS ( ) <EOL> self . patch ( os , "<STR_LIT>" , self . mockos . geteuid ) <EOL> self . patch ( os , "<STR_LIT>" , self . mockos . getegid ) <EOL> self . patch ( os , "<STR_LIT>" , self . mockos . seteuid ) <EOL> self . patch ( os , "<STR_LIT>" , self . mockos . setegid ) <EOL> def _securedFunction ( self , startUID , startGID , wantUID , wantGID ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( wantUID == startUID or <EOL> wantUID == self . mockos . seteuidCalls [ - <NUM_LIT:1> ] ) <EOL> self . assertTrue ( wantGID == startGID or <EOL> wantGID == self . mockos . setegidCalls [ - <NUM_LIT:1> ] ) <EOL> def test_forwardResult ( self ) : <EOL> """<STR_LIT>""" <EOL> result = util . runAsEffectiveUser ( <NUM_LIT:0> , <NUM_LIT:0> , lambda : <NUM_LIT:1> ) <EOL> self . assertEqual ( result , <NUM_LIT:1> ) <EOL> def test_takeParameters ( self ) : <EOL> """<STR_LIT>""" <EOL> result = util . runAsEffectiveUser ( <NUM_LIT:0> , <NUM_LIT:0> , lambda x : <NUM_LIT:2> * x , <NUM_LIT:3> ) <EOL> self . assertEqual ( result , <NUM_LIT:6> ) <EOL> def test_takesKeyworkArguments ( self ) : <EOL> """<STR_LIT>""" <EOL> result = util . runAsEffectiveUser ( <NUM_LIT:0> , <NUM_LIT:0> , lambda x , y = <NUM_LIT:1> , z = <NUM_LIT:1> : x * y * z , <NUM_LIT:2> , z = <NUM_LIT:3> ) <EOL> self . assertEqual ( result , <NUM_LIT:6> ) <EOL> def _testUIDGIDSwitch ( self , startUID , startGID , wantUID , wantGID , <EOL> expectedUIDSwitches , expectedGIDSwitches ) : <EOL> """<STR_LIT>""" <EOL> self . mockos . euid = startUID <EOL> self . mockos . egid = startGID <EOL> util . runAsEffectiveUser ( <EOL> wantUID , wantGID , <EOL> self . _securedFunction , startUID , startGID , wantUID , wantGID ) <EOL> self . assertEqual ( self . mockos . seteuidCalls , expectedUIDSwitches ) <EOL> self . assertEqual ( self . mockos . setegidCalls , expectedGIDSwitches ) <EOL> self . mockos . seteuidCalls = [ ] <EOL> self . mockos . setegidCalls = [ ] <EOL> def test_root ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , [ ] , [ ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , [ ] , [ <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> def test_UID ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , [ ] , [ ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> , [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> def test_GID ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , [ ] , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , [ ] , [ ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> def test_UIDGID ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , [ ] , [ ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> , [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> self . _testUIDGIDSwitch ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> def _getDeprecationSuppression ( f ) : <EOL> """<STR_LIT>""" <EOL> return SUPPRESS ( <EOL> category = DeprecationWarning , <EOL> message = '<STR_LIT>' % ( fullyQualifiedName ( f ) , ) ) <EOL> class InitGroupsTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> if pwd is None : <EOL> skip = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> self . addCleanup ( setattr , util , "<STR_LIT>" , util . _c_initgroups ) <EOL> self . addCleanup ( setattr , util , "<STR_LIT>" , util . setgroups ) <EOL> def test_initgroupsForceC ( self ) : <EOL> """<STR_LIT>""" <EOL> calls = [ ] <EOL> util . _c_initgroups = lambda x , y : calls . append ( ( x , y ) ) <EOL> setgroupsCalls = [ ] <EOL> util . setgroups = calls . append <EOL> util . initgroups ( os . getuid ( ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( calls , [ ( pwd . getpwuid ( os . getuid ( ) ) [ <NUM_LIT:0> ] , <NUM_LIT:4> ) ] ) <EOL> self . assertFalse ( setgroupsCalls ) <EOL> def test_initgroupsForcePython ( self ) : <EOL> """<STR_LIT>""" <EOL> util . _c_initgroups = None <EOL> calls = [ ] <EOL> util . setgroups = calls . append <EOL> util . initgroups ( os . getuid ( ) , os . getgid ( ) ) <EOL> self . assertTrue ( calls ) <EOL> def test_initgroupsInC ( self ) : <EOL> """<STR_LIT>""" <EOL> calls = [ ] <EOL> util . setgroups = calls . append <EOL> try : <EOL> util . initgroups ( os . getuid ( ) , os . getgid ( ) ) <EOL> except OSError : <EOL> pass <EOL> self . assertFalse ( calls ) <EOL> if util . _c_initgroups is None : <EOL> test_initgroupsInC . skip = "<STR_LIT>" <EOL> class DeprecationTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_getPluginDirs ( self ) : <EOL> """<STR_LIT>""" <EOL> util . getPluginDirs ( ) <EOL> warnings = self . flushWarnings ( offendingFunctions = [ <EOL> self . test_getPluginDirs ] ) <EOL> self . assertEqual ( <EOL> warnings [ <NUM_LIT:0> ] [ '<STR_LIT:message>' ] , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( warnings [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , DeprecationWarning ) <EOL> self . assertEqual ( len ( warnings ) , <NUM_LIT:1> ) <EOL> def test_addPluginDir ( self ) : <EOL> """<STR_LIT>""" <EOL> util . addPluginDir ( ) <EOL> warnings = self . flushWarnings ( offendingFunctions = [ <EOL> self . test_addPluginDir ] ) <EOL> self . assertEqual ( <EOL> warnings [ <NUM_LIT:0> ] [ '<STR_LIT:message>' ] , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( warnings [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , DeprecationWarning ) <EOL> self . assertEqual ( len ( warnings ) , <NUM_LIT:1> ) <EOL> test_addPluginDir . suppress = [ <EOL> SUPPRESS ( category = DeprecationWarning , <EOL> message = "<STR_LIT>" ) <EOL> ] <EOL> class SuppressedWarningsTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> runWithWarningsSuppressed = staticmethod ( util . runWithWarningsSuppressed ) <EOL> def test_runWithWarningsSuppressedFiltered ( self ) : <EOL> """<STR_LIT>""" <EOL> filters = [ ( ( "<STR_LIT:ignore>" , "<STR_LIT>" ) , { } ) , <EOL> ( ( "<STR_LIT:ignore>" , "<STR_LIT>" ) , { } ) ] <EOL> self . runWithWarningsSuppressed ( filters , warnings . warn , "<STR_LIT>" ) <EOL> self . runWithWarningsSuppressed ( filters , warnings . warn , "<STR_LIT>" ) <EOL> self . assertEqual ( [ ] , self . flushWarnings ( ) ) <EOL> def test_runWithWarningsSuppressedUnfiltered ( self ) : <EOL> """<STR_LIT>""" <EOL> filters = [ ( ( "<STR_LIT:ignore>" , "<STR_LIT>" ) , { } ) , <EOL> ( ( "<STR_LIT:ignore>" , "<STR_LIT>" ) , { } ) ] <EOL> self . runWithWarningsSuppressed ( filters , warnings . warn , "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> [ "<STR_LIT>" ] , [ w [ '<STR_LIT:message>' ] for w in self . flushWarnings ( ) ] ) <EOL> def test_passThrough ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . runWithWarningsSuppressed ( [ ] , lambda : <NUM_LIT:4> ) , <NUM_LIT:4> ) <EOL> def test_noSideEffects ( self ) : <EOL> """<STR_LIT>""" <EOL> filters = [ ( ( "<STR_LIT:ignore>" , "<STR_LIT>" ) , { } ) , <EOL> ( ( "<STR_LIT:ignore>" , "<STR_LIT>" ) , { } ) ] <EOL> self . runWithWarningsSuppressed ( filters , lambda : None ) <EOL> warnings . warn ( "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> [ "<STR_LIT>" ] , [ w [ '<STR_LIT:message>' ] for w in self . flushWarnings ( ) ] ) <EOL> class FancyStrMixinTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_sequenceOfStrings ( self ) : <EOL> """<STR_LIT>""" <EOL> class Foo ( util . FancyStrMixin ) : <EOL> showAttributes = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> first = <NUM_LIT:1> <EOL> second = "<STR_LIT:hello>" <EOL> self . assertEqual ( str ( Foo ( ) ) , "<STR_LIT>" ) <EOL> def test_formatter ( self ) : <EOL> """<STR_LIT>""" <EOL> class Foo ( util . FancyStrMixin ) : <EOL> showAttributes = ( <EOL> "<STR_LIT>" , <EOL> ( "<STR_LIT>" , lambda value : repr ( value [ : : - <NUM_LIT:1> ] ) ) ) <EOL> first = "<STR_LIT:hello>" <EOL> second = "<STR_LIT>" <EOL> self . assertEqual ( "<STR_LIT>" , str ( Foo ( ) ) ) <EOL> def test_override ( self ) : <EOL> """<STR_LIT>""" <EOL> class Foo ( util . FancyStrMixin ) : <EOL> showAttributes = ( "<STR_LIT>" , ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> first = <NUM_LIT:1> <EOL> second = <NUM_LIT> <EOL> self . assertEqual ( str ( Foo ( ) ) , "<STR_LIT>" ) <EOL> def test_fancybasename ( self ) : <EOL> """<STR_LIT>""" <EOL> class Foo ( util . FancyStrMixin ) : <EOL> fancybasename = "<STR_LIT>" <EOL> self . assertEqual ( str ( Foo ( ) ) , "<STR_LIT>" ) <EOL> def test_repr ( self ) : <EOL> """<STR_LIT>""" <EOL> class Foo ( util . FancyStrMixin ) : <EOL> showAttributes = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> first = <NUM_LIT:1> <EOL> second = "<STR_LIT:hello>" <EOL> obj = Foo ( ) <EOL> self . assertEqual ( str ( obj ) , repr ( obj ) ) <EOL> class PadToTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_default ( self ) : <EOL> """<STR_LIT>""" <EOL> padded = util . padTo ( <NUM_LIT:3> , [ ] ) <EOL> self . assertEqual ( [ None ] * <NUM_LIT:3> , padded ) <EOL> def test_specificDefaultValue ( self ) : <EOL> """<STR_LIT>""" <EOL> padded = util . padTo ( <NUM_LIT:4> , [ ] , "<STR_LIT:x>" ) <EOL> self . assertEqual ( [ "<STR_LIT:x>" ] * <NUM_LIT:4> , padded ) <EOL> def test_padNonEmptyList ( self ) : <EOL> """<STR_LIT>""" <EOL> padded = util . padTo ( <NUM_LIT:3> , [ <NUM_LIT:1> , <NUM_LIT:2> ] , "<STR_LIT:z>" ) <EOL> self . assertEqual ( [ <NUM_LIT:1> , <NUM_LIT:2> , "<STR_LIT:z>" ] , padded ) <EOL> def test_padToSmallerSize ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( ValueError , util . padTo , <NUM_LIT:1> , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> def test_alreadyPadded ( self ) : <EOL> """<STR_LIT>""" <EOL> items = [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> padded = util . padTo ( len ( items ) , items ) <EOL> self . assertEqual ( items , padded ) <EOL> def test_alreadyPaddedCopies ( self ) : <EOL> """<STR_LIT>""" <EOL> items = [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> padded = util . padTo ( len ( items ) , items ) <EOL> self . assertIsNot ( padded , items ) <EOL> def test_makeCopy ( self ) : <EOL> """<STR_LIT>""" <EOL> items = [ ] <EOL> util . padTo ( <NUM_LIT:4> , items ) <EOL> self . assertEqual ( [ ] , items ) <EOL> if _PY3 : <EOL> del ( SwitchUIDTest , SearchUpwardsTest , RunAsEffectiveUserTests , <EOL> OrderedDictTest , IntervalDifferentialTestCase , UtilTestCase , <EOL> TestMergeFunctionMetadata , DeprecationTests , InitGroupsTests , <EOL> GetPasswordTest , <EOL> ) </s>
