<s> """<STR_LIT>""" <EOL> import os <EOL> from twisted . trial . unittest import TestCase <EOL> from twisted . python . systemd import ListenFDs <EOL> class InheritedDescriptorsMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def test_inheritedDescriptors ( self ) : <EOL> """<STR_LIT>""" <EOL> sddaemon = self . getDaemon ( <NUM_LIT:7> , <NUM_LIT:3> ) <EOL> self . assertEqual ( [ <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] , sddaemon . inheritedDescriptors ( ) ) <EOL> def test_repeated ( self ) : <EOL> """<STR_LIT>""" <EOL> sddaemon = self . getDaemon ( <NUM_LIT:7> , <NUM_LIT:3> ) <EOL> self . assertEqual ( <EOL> sddaemon . inheritedDescriptors ( ) , <EOL> sddaemon . inheritedDescriptors ( ) ) <EOL> class MemoryOnlyMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def getDaemon ( self , start , count ) : <EOL> """<STR_LIT>""" <EOL> return ListenFDs ( range ( start , start + count ) ) <EOL> class EnvironmentMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def initializeEnvironment ( self , count , pid ) : <EOL> """<STR_LIT>""" <EOL> result = os . environ . copy ( ) <EOL> result [ '<STR_LIT>' ] = str ( count ) <EOL> result [ '<STR_LIT>' ] = str ( pid ) <EOL> return result <EOL> def getDaemon ( self , start , count ) : <EOL> """<STR_LIT>""" <EOL> fakeEnvironment = self . initializeEnvironment ( count , os . getpid ( ) ) <EOL> return ListenFDs . fromEnvironment ( environ = fakeEnvironment , start = start ) <EOL> class MemoryOnlyTests ( MemoryOnlyMixin , InheritedDescriptorsMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> class EnvironmentTests ( EnvironmentMixin , InheritedDescriptorsMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_secondEnvironment ( self ) : <EOL> """<STR_LIT>""" <EOL> fakeEnvironment = self . initializeEnvironment ( <NUM_LIT:3> , os . getpid ( ) ) <EOL> first = ListenFDs . fromEnvironment ( environ = fakeEnvironment ) <EOL> second = ListenFDs . fromEnvironment ( environ = fakeEnvironment ) <EOL> self . assertEqual ( range ( <NUM_LIT:3> , <NUM_LIT:6> ) , first . inheritedDescriptors ( ) ) <EOL> self . assertEqual ( [ ] , second . inheritedDescriptors ( ) ) <EOL> def test_mismatchedPID ( self ) : <EOL> """<STR_LIT>""" <EOL> fakeEnvironment = self . initializeEnvironment ( <NUM_LIT:3> , os . getpid ( ) + <NUM_LIT:1> ) <EOL> sddaemon = ListenFDs . fromEnvironment ( environ = fakeEnvironment ) <EOL> self . assertEqual ( [ ] , sddaemon . inheritedDescriptors ( ) ) <EOL> def test_missingPIDVariable ( self ) : <EOL> """<STR_LIT>""" <EOL> fakeEnvironment = self . initializeEnvironment ( <NUM_LIT:3> , os . getpid ( ) ) <EOL> del fakeEnvironment [ '<STR_LIT>' ] <EOL> sddaemon = ListenFDs . fromEnvironment ( environ = fakeEnvironment ) <EOL> self . assertEqual ( [ ] , sddaemon . inheritedDescriptors ( ) ) <EOL> def test_nonIntegerPIDVariable ( self ) : <EOL> """<STR_LIT>""" <EOL> fakeEnvironment = self . initializeEnvironment ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> sddaemon = ListenFDs . fromEnvironment ( environ = fakeEnvironment ) <EOL> self . assertEqual ( [ ] , sddaemon . inheritedDescriptors ( ) ) <EOL> def test_missingFDSVariable ( self ) : <EOL> """<STR_LIT>""" <EOL> fakeEnvironment = self . initializeEnvironment ( <NUM_LIT:3> , os . getpid ( ) ) <EOL> del fakeEnvironment [ '<STR_LIT>' ] <EOL> sddaemon = ListenFDs . fromEnvironment ( environ = fakeEnvironment ) <EOL> self . assertEqual ( [ ] , sddaemon . inheritedDescriptors ( ) ) <EOL> def test_nonIntegerFDSVariable ( self ) : <EOL> """<STR_LIT>""" <EOL> fakeEnvironment = self . initializeEnvironment ( "<STR_LIT>" , os . getpid ( ) ) <EOL> sddaemon = ListenFDs . fromEnvironment ( environ = fakeEnvironment ) <EOL> self . assertEqual ( [ ] , sddaemon . inheritedDescriptors ( ) ) <EOL> def test_defaultEnviron ( self ) : <EOL> """<STR_LIT>""" <EOL> self . patch ( os , '<STR_LIT>' , { <EOL> '<STR_LIT>' : str ( os . getpid ( ) ) , <EOL> '<STR_LIT>' : '<STR_LIT:5>' } ) <EOL> sddaemon = ListenFDs . fromEnvironment ( ) <EOL> self . assertEqual ( range ( <NUM_LIT:3> , <NUM_LIT:3> + <NUM_LIT:5> ) , sddaemon . inheritedDescriptors ( ) ) </s>
