<s> import os <EOL> import pickle <EOL> import cPickle <EOL> import re <EOL> from testrunner import testhelp <EOL> import shutil <EOL> import tempfile <EOL> from StringIO import StringIO <EOL> from conary . conarycfg import ( <EOL> CfgFingerPrintMap , <EOL> CfgFlavor , <EOL> CfgLabel , <EOL> ) <EOL> from conary . lib import cfgtypes <EOL> from conary . lib . cfg import ( <EOL> ConfigFile , <EOL> ConfigSection , <EOL> ParseError , <EOL> SectionedConfigFile , <EOL> ) <EOL> from conary . lib . cfgtypes import ( <EOL> CfgBool , <EOL> CfgEnum , <EOL> CfgEnumDict , <EOL> CfgInt , <EOL> CfgList , <EOL> CfgPath , <EOL> CfgQuotedLineList , <EOL> CfgRegExpList , <EOL> CfgString , <EOL> CfgEnvironmentError <EOL> ) <EOL> from conary import versions <EOL> class ConfigTest ( testhelp . TestCase ) : <EOL> def _getDisplayLines ( self , cfg ) : <EOL> out = StringIO ( ) <EOL> cfg . display ( out ) <EOL> lines = out . getvalue ( ) <EOL> lines = re . sub ( '<STR_LIT>' , '<STR_LIT:U+0020>' , lines ) <EOL> lines = lines [ : - <NUM_LIT:1> ] <EOL> return lines . split ( '<STR_LIT:\n>' ) <EOL> def _getFileLines ( self , cfg , includeDocs = True ) : <EOL> out = StringIO ( ) <EOL> cfg . _write ( out , cfg . _displayOptions , includeDocs = includeDocs ) <EOL> lines = out . getvalue ( ) <EOL> lines = re . sub ( '<STR_LIT>' , '<STR_LIT:U+0020>' , lines ) <EOL> lines = lines [ : - <NUM_LIT:1> ] <EOL> return lines . split ( '<STR_LIT:\n>' ) <EOL> def testConfigComments ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = None <EOL> cfg = TestCfgFile ( ) <EOL> assert ( cfg . foo == None ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == '<STR_LIT>' ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == '<STR_LIT>' ) <EOL> cfg . configLine ( r'<STR_LIT>' ) <EOL> assert ( cfg . foo == '<STR_LIT>' ) <EOL> cfg . configLine ( r'<STR_LIT>' ) <EOL> assert ( cfg . foo == '<STR_LIT>' ) <EOL> def testConfigBool ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgBool , False ) <EOL> cfg = TestCfgFile ( ) <EOL> assert ( cfg . foo == False ) <EOL> assert ( cfg [ '<STR_LIT:foo>' ] == False ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == True ) <EOL> cfg . foo = False <EOL> assert ( cfg . foo == False ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == True ) <EOL> assert ( self . _getDisplayLines ( cfg ) == [ '<STR_LIT>' ] ) <EOL> def testConfigPath ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgPath , False ) <EOL> oldEnv = os . environ . get ( '<STR_LIT>' , None ) <EOL> oldHome = os . environ . get ( '<STR_LIT>' , None ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> try : <EOL> cfg = TestCfgFile ( ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( self . _getDisplayLines ( cfg ) == [ '<STR_LIT>' ] ) <EOL> cfg = TestCfgFile ( ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( self . _getDisplayLines ( cfg ) == [ '<STR_LIT>' ] ) <EOL> cfg . setDisplayOptions ( expandPaths = True ) <EOL> assert ( self . _getDisplayLines ( cfg ) == [ '<STR_LIT>' % os . environ [ '<STR_LIT>' ] ] ) <EOL> finally : <EOL> if oldEnv is None : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> else : <EOL> os . environ [ '<STR_LIT>' ] = oldEnv <EOL> if oldHome is None : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> else : <EOL> os . environ [ '<STR_LIT>' ] = oldHome <EOL> def testConfigPathCache ( self ) : <EOL> oldHome = os . environ . get ( '<STR_LIT>' , None ) <EOL> oldEnv = os . environ . get ( '<STR_LIT>' , None ) <EOL> try : <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> p = cfgtypes . Path ( '<STR_LIT>' ) <EOL> assert ( p == '<STR_LIT>' ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> p = cfgtypes . Path ( '<STR_LIT>' ) <EOL> assert ( p == '<STR_LIT>' ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> p = cfgtypes . Path ( '<STR_LIT>' ) <EOL> assert ( p == '<STR_LIT>' ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> p = cfgtypes . Path ( '<STR_LIT>' ) <EOL> assert ( p == '<STR_LIT>' ) <EOL> finally : <EOL> if oldEnv is None : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> else : <EOL> os . environ [ '<STR_LIT>' ] = oldEnv <EOL> if oldHome is None : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> else : <EOL> os . environ [ '<STR_LIT>' ] = oldHome <EOL> def testConfigInt ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgInt , <NUM_LIT:0> ) <EOL> cfg = TestCfgFile ( ) <EOL> assert ( cfg . foo == <NUM_LIT:0> ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == <NUM_LIT:1> ) <EOL> assert ( self . _getDisplayLines ( cfg ) == [ '<STR_LIT>' ] ) <EOL> def testConfigRegExp ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = CfgRegExpList <EOL> cfg = TestCfgFile ( ) <EOL> assert ( cfg . foo == [ ] ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( [ x [ <NUM_LIT:0> ] for x in cfg . foo ] == [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> lines = self . _getDisplayLines ( cfg ) <EOL> lines . remove ( '<STR_LIT>' ) <EOL> lines . remove ( '<STR_LIT>' ) <EOL> assert ( not lines ) <EOL> def testConfigLabel ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgLabel , versions . Label ( '<STR_LIT>' ) ) <EOL> cfg = TestCfgFile ( ) <EOL> assert ( cfg . foo . asString ( ) == '<STR_LIT>' ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo . asString ( ) == '<STR_LIT>' ) <EOL> def testConfigFlavor ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = CfgFlavor <EOL> cfg = TestCfgFile ( ) <EOL> assert ( str ( cfg . foo ) == '<STR_LIT>' ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( str ( cfg . foo ) == '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cfg . setDisplayOptions ( prettyPrint = True ) <EOL> lines = self . _getDisplayLines ( cfg ) <EOL> lines . remove ( '<STR_LIT>' ) <EOL> lines . remove ( '<STR_LIT>' ) <EOL> assert ( not lines ) <EOL> cfg . setDisplayOptions ( prettyPrint = False ) <EOL> lines = self . _getDisplayLines ( cfg ) <EOL> lines . remove ( '<STR_LIT>' ) <EOL> def testConfigString ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = CfgString <EOL> cfg = TestCfgFile ( ) <EOL> assert ( cfg . foo == None ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == '<STR_LIT>' ) <EOL> def testConfigStringList ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgList ( CfgString ) , [ '<STR_LIT:default>' ] ) <EOL> cfg = TestCfgFile ( ) <EOL> assert ( cfg . foo == [ '<STR_LIT:default>' ] ) <EOL> cfg . foo . append ( '<STR_LIT:bar>' ) <EOL> assert ( cfg . foo == [ '<STR_LIT:default>' , '<STR_LIT:bar>' ] ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == [ '<STR_LIT:default>' , '<STR_LIT:bar>' , '<STR_LIT>' ] ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == [ '<STR_LIT:default>' , '<STR_LIT:bar>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> lines = self . _getDisplayLines ( cfg ) <EOL> assert ( lines == [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def testConfigQuotedLineList ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgQuotedLineList ( CfgString ) , [ '<STR_LIT:default>' ] ) <EOL> cfg = TestCfgFile ( ) <EOL> assert ( cfg . foo == [ '<STR_LIT:default>' ] ) <EOL> cfg . configLine ( "<STR_LIT>" ) <EOL> assert ( cfg . foo == [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> lines = self . _getDisplayLines ( cfg ) <EOL> assert ( lines == [ "<STR_LIT>" ] ) <EOL> def testConfigLabelList ( self ) : <EOL> defaultLabel = versions . Label ( '<STR_LIT>' ) <EOL> localLabel = versions . Label ( '<STR_LIT>' ) <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgList ( CfgLabel ) , [ defaultLabel ] ) <EOL> cfg = TestCfgFile ( ) <EOL> assert ( cfg . foo == [ defaultLabel ] ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == [ localLabel ] ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == [ localLabel , defaultLabel ] ) <EOL> lines = self . _getDisplayLines ( cfg ) <EOL> assert ( lines == [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def testDocs ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgString , '<STR_LIT>' , "<STR_LIT>" ) <EOL> cfg = TestCfgFile ( ) <EOL> cfg . foo == '<STR_LIT>' <EOL> lines = self . _getFileLines ( cfg ) <EOL> assert ( lines == [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def testLineOrigins ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgString , '<STR_LIT>' ) <EOL> bar = ( CfgList ( CfgString ) , None ) <EOL> bam = ( CfgString , '<STR_LIT>' ) <EOL> cfg = TestCfgFile ( ) <EOL> cfg . configLine ( '<STR_LIT>' , fileName = '<STR_LIT>' , lineno = <NUM_LIT:32> ) <EOL> cfg . configLine ( '<STR_LIT>' , fileName = '<STR_LIT>' , lineno = <NUM_LIT> ) <EOL> cfg . configLine ( '<STR_LIT>' , fileName = '<STR_LIT>' , lineno = '<STR_LIT>' ) <EOL> cfg . configLine ( '<STR_LIT>' , fileName = '<STR_LIT>' , lineno = <NUM_LIT:3> ) <EOL> cfg . setDisplayOptions ( showLineOrigins = True ) <EOL> lines = self . _getFileLines ( cfg , includeDocs = False ) <EOL> assert ( lines == [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def testCfgEnum ( self ) : <EOL> class TestCfgEnum ( CfgEnum ) : <EOL> validValues = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( TestCfgEnum ( ) , '<STR_LIT>' ) <EOL> cfg = TestCfgFile ( ) <EOL> self . assertFalse ( cfg . foo != '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> self . assertFalse ( cfg . foo != '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> tCfg = TestCfgEnum ( ) <EOL> self . assertFalse ( tCfg . format ( '<STR_LIT>' , { } ) != '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> self . assertRaises ( ParseError , tCfg . parseString , '<STR_LIT>' ) <EOL> self . assertRaises ( ParseError , tCfg . format , '<STR_LIT:foo>' , { } ) <EOL> self . assertFalse ( tCfg . parseString ( '<STR_LIT:bar>' ) != '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> self . assertFalse ( tCfg . validValues != { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:foo>' : '<STR_LIT>' , '<STR_LIT:bar>' : '<STR_LIT>' } , <EOL> "<STR_LIT>" ) <EOL> self . assertFalse ( tCfg . origName != { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> "<STR_LIT>" ) <EOL> def testCfgEnum2 ( self ) : <EOL> class TestCfgEnum ( CfgEnum ) : <EOL> validValues = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> } <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( TestCfgEnum ( ) , <NUM_LIT:2> ) <EOL> testEnum = TestCfgEnum ( ) <EOL> self . assertFalse ( testEnum . parseString ( '<STR_LIT:foo>' ) != <NUM_LIT:1> , <EOL> "<STR_LIT>" ) <EOL> self . assertFalse ( testEnum . format ( <NUM_LIT:1> , { } ) != '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> tCfg = TestCfgEnum ( ) <EOL> self . assertFalse ( tCfg . validValues != { '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT:foo>' : <NUM_LIT:1> , '<STR_LIT:bar>' : <NUM_LIT:2> } , <EOL> "<STR_LIT>" ) <EOL> self . assertFalse ( tCfg . origName != { <NUM_LIT:3> : '<STR_LIT>' , <NUM_LIT:1> : '<STR_LIT>' , <NUM_LIT:2> : '<STR_LIT>' } , <EOL> "<STR_LIT>" ) <EOL> def testConfigEnumDict ( self ) : <EOL> class CfgEnumDictFoo ( CfgEnumDict ) : <EOL> validValues = { '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) } <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = CfgEnumDictFoo <EOL> cfg = TestCfgFile ( ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def testRegularExp ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = CfgRegExpList <EOL> cfg = TestCfgFile ( ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo . match ( '<STR_LIT:bar>' ) ) <EOL> assert ( cfg . foo . match ( '<STR_LIT>' ) ) <EOL> assert ( not cfg . foo . match ( '<STR_LIT>' ) ) <EOL> def testFingerprintMap ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = CfgFingerPrintMap <EOL> cfg = TestCfgFile ( ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == [ ( '<STR_LIT>' , None ) ] ) <EOL> self . assertRaises ( ParseError , cfg . configLine , '<STR_LIT>' ) <EOL> def testSectionedCfg ( self ) : <EOL> class TestCfgSection ( ConfigSection ) : <EOL> foo = CfgBool <EOL> class TestCfgFile ( SectionedConfigFile ) : <EOL> bar = TestCfgSection , None , '<STR_LIT>' <EOL> cfg = TestCfgFile ( ) <EOL> self . assertRaises ( ParseError , cfg . configLine , '<STR_LIT:bar>' ) <EOL> self . assertRaises ( ParseError , cfg . configLine , '<STR_LIT:foo>' ) <EOL> assert ( not cfg . bar . foo ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . bar . foo ) <EOL> def testIncludeConfigFile ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> bam = CfgBool <EOL> biff = CfgBool <EOL> dir = tempfile . mkdtemp ( ) <EOL> _home = os . getenv ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> open ( '<STR_LIT>' % dir , '<STR_LIT:w>' ) . write ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> open ( '<STR_LIT>' % dir , '<STR_LIT:w>' ) . write ( '<STR_LIT>' ) <EOL> os . mkdir ( os . path . join ( dir , '<STR_LIT>' ) ) <EOL> open ( '<STR_LIT>' % dir , '<STR_LIT:w>' ) . write ( '<STR_LIT>' ) <EOL> os . environ [ '<STR_LIT>' ] = os . path . join ( dir , '<STR_LIT>' ) <EOL> cfg = TestCfgFile ( ) <EOL> assert ( not cfg . bam ) <EOL> cfg . read ( '<STR_LIT>' % dir ) <EOL> assert ( cfg . bam and cfg . biff ) <EOL> finally : <EOL> os . environ [ '<STR_LIT>' ] = _home <EOL> shutil . rmtree ( dir ) <EOL> def testIncludeConfigFileFails ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> bam = CfgBool <EOL> dir = tempfile . mkdtemp ( ) <EOL> try : <EOL> open ( '<STR_LIT>' % dir , '<STR_LIT:w>' ) . write ( '<STR_LIT>' ) <EOL> cfg = TestCfgFile ( ) <EOL> assert ( not cfg . bam ) <EOL> try : <EOL> cfg . read ( '<STR_LIT>' % dir ) <EOL> assert ( <NUM_LIT:0> ) <EOL> except Exception , e : <EOL> if '<STR_LIT>' in str ( e ) : <EOL> raise testhelp . SkipTestException ( '<STR_LIT>' ) <EOL> desc , sep , err = str ( e ) . partition ( '<STR_LIT>' ) <EOL> self . assertEqual ( desc , "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % dir ) <EOL> self . assertIn ( err , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> cfg = TestCfgFile ( ) <EOL> cfg . ignoreUrlIncludes ( ) <EOL> cfg . read ( '<STR_LIT>' % dir ) <EOL> cfg = TestCfgFile ( ) <EOL> cfg . ignoreUrlIncludes ( ) <EOL> cfg . ignoreUrlIncludes ( False ) <EOL> self . assertRaises ( Exception , cfg . read , '<STR_LIT>' % dir ) <EOL> cfg = TestCfgFile ( ) <EOL> cfg . setIgnoreErrors ( ) <EOL> cfg . read ( '<STR_LIT>' % dir ) <EOL> finally : <EOL> shutil . rmtree ( dir ) <EOL> def testLimitKeys ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgString , '<STR_LIT:foo>' ) <EOL> bar = ( CfgString , '<STR_LIT:bar>' ) <EOL> cfg = TestCfgFile ( ) <EOL> cfg . limitToKeys ( '<STR_LIT:foo>' ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . bar == '<STR_LIT:bar>' ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . foo == '<STR_LIT>' ) <EOL> cfg . limitToKeys ( False ) <EOL> cfg . configLine ( '<STR_LIT>' ) <EOL> assert ( cfg . bar == '<STR_LIT>' ) <EOL> def testStringListOverrideDefault ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> bam = CfgList ( CfgString , default = [ '<STR_LIT:foo>' ] ) <EOL> dir = tempfile . mkdtemp ( ) <EOL> try : <EOL> open ( '<STR_LIT>' % dir , '<STR_LIT:w>' ) . write ( '<STR_LIT>' ) <EOL> cfg = TestCfgFile ( ) <EOL> cfg . read ( '<STR_LIT>' % dir ) <EOL> assert ( cfg . bam == [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) <EOL> finally : <EOL> shutil . rmtree ( dir ) <EOL> def testDefaultFlag ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgString , '<STR_LIT:foo>' ) <EOL> cfg = TestCfgFile ( ) <EOL> assert cfg . isDefault ( '<STR_LIT:foo>' ) <EOL> cfg [ '<STR_LIT:foo>' ] = '<STR_LIT:bar>' <EOL> assert not cfg . isDefault ( '<STR_LIT:foo>' ) <EOL> cfg . resetToDefault ( '<STR_LIT:foo>' ) <EOL> self . assertEquals ( cfg . foo , '<STR_LIT:foo>' ) <EOL> assert cfg . isDefault ( '<STR_LIT:foo>' ) <EOL> cfg . foo = '<STR_LIT:bar>' <EOL> assert not cfg . isDefault ( '<STR_LIT:foo>' ) <EOL> def testReadFileDoesntExist ( self ) : <EOL> class TestCfgFile ( ConfigFile ) : <EOL> foo = ( CfgString , '<STR_LIT:foo>' ) <EOL> cfg = TestCfgFile ( ) <EOL> ex = self . assertRaises ( CfgEnvironmentError , cfg . read , <EOL> '<STR_LIT>' , exception = True ) <EOL> assert ( str ( ex ) == "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def testPickle ( self ) : <EOL> cfg = PickleTestConfig ( ) <EOL> cfg . bar . append ( <NUM_LIT:3> ) <EOL> cfg . addListener ( '<STR_LIT:foo>' , lambda x : None ) <EOL> sio = StringIO ( ) <EOL> cfg . store ( sio ) <EOL> reference = sio . getvalue ( ) <EOL> for mod in ( pickle , cPickle ) : <EOL> for level in ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) : <EOL> pickled = mod . dumps ( cfg , level ) <EOL> restored = mod . loads ( pickled ) <EOL> sio = StringIO ( ) <EOL> restored . store ( sio ) <EOL> self . assertEquals ( sio . getvalue ( ) , reference ) <EOL> class PickleTestConfig ( ConfigFile ) : <EOL> foo = ( CfgList ( CfgInt ) , [ <NUM_LIT:1> ] ) <EOL> bar = ( CfgList ( CfgInt ) , [ <NUM_LIT:2> ] ) </s>
