<s> import unittest <EOL> import tempfile <EOL> import os <EOL> import pytest <EOL> from calvin . utilities . calvinconfig import CalvinConfig <EOL> class TestBase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . filepath = None <EOL> f , self . filepath = tempfile . mkstemp ( ) <EOL> os . unlink ( self . filepath ) <EOL> self . _env = os . environ <EOL> print "<STR_LIT>" <EOL> def tearDown ( self ) : <EOL> if self . filepath and os . path . exists ( self . filepath ) : <EOL> os . unlink ( self . filepath ) <EOL> print "<STR_LIT>" <EOL> os . environ = self . _env <EOL> class CalvinConfigTests ( TestBase ) : <EOL> @ unittest . skip ( "<STR_LIT>" ) <EOL> def test_create_default_config ( self ) : <EOL> self . assertEqual ( os . path . exists ( self . filepath ) , False ) <EOL> os . environ [ '<STR_LIT>' ] = self . filepath <EOL> CalvinConfig ( ) <EOL> self . assertEqual ( os . path . exists ( self . filepath ) , True ) <EOL> with open ( self . filepath , "<STR_LIT:rb>" ) as f : <EOL> content = f . readlines ( ) <EOL> self . assertGreater ( len ( content ) , <NUM_LIT:1> ) <EOL> def test_set_get ( self ) : <EOL> self . assertEqual ( os . path . exists ( self . filepath ) , False ) <EOL> os . environ [ '<STR_LIT>' ] = self . filepath <EOL> _conf = CalvinConfig ( ) <EOL> _conf . add_section ( "<STR_LIT:test>" ) <EOL> for a in range ( <NUM_LIT:10> ) : <EOL> _conf . set ( "<STR_LIT:test>" , "<STR_LIT>" % a , str ( a ) ) <EOL> self . assertEqual ( _conf . get ( "<STR_LIT:test>" , "<STR_LIT>" % a ) , str ( a ) ) <EOL> for a in range ( <NUM_LIT:10> ) : <EOL> _conf . set ( "<STR_LIT:test>" , "<STR_LIT>" % a , a ) <EOL> self . assertEqual ( _conf . get ( "<STR_LIT:test>" , "<STR_LIT>" % a ) , a ) <EOL> for a in range ( <NUM_LIT:10> ) : <EOL> _conf . set ( "<STR_LIT:test>" , "<STR_LIT>" % a , range ( <NUM_LIT:10> ) ) <EOL> self . assertEqual ( _conf . get ( "<STR_LIT:test>" , "<STR_LIT>" % a ) , range ( <NUM_LIT:10> ) ) <EOL> for a in range ( <NUM_LIT:10> ) : <EOL> _conf . set ( "<STR_LIT:test>" , "<STR_LIT>" % a , dict ( zip ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:10> ) ) ) ) <EOL> self . assertNotEqual ( _conf . get ( "<STR_LIT:test>" , "<STR_LIT>" % a ) , dict ( zip ( [ str ( x ) for x in range ( <NUM_LIT:10> ) ] , range ( <NUM_LIT:10> ) ) ) ) <EOL> for a in range ( <NUM_LIT:10> ) : <EOL> _conf . set ( "<STR_LIT:test>" , "<STR_LIT>" % a , dict ( zip ( [ str ( x ) for x in range ( <NUM_LIT:10> ) ] , range ( <NUM_LIT:10> ) ) ) ) <EOL> self . assertEqual ( _conf . get ( "<STR_LIT:test>" , "<STR_LIT>" % a ) , dict ( zip ( [ str ( x ) for x in range ( <NUM_LIT:10> ) ] , range ( <NUM_LIT:10> ) ) ) ) <EOL> for a in range ( <NUM_LIT:10> ) : <EOL> _conf . set ( "<STR_LIT:test>" , "<STR_LIT>" % a , dict ( zip ( [ str ( x ) for x in range ( <NUM_LIT:10> ) ] , [ range ( <NUM_LIT:10> ) ] ) ) ) <EOL> self . assertEqual ( _conf . get ( "<STR_LIT:test>" , "<STR_LIT>" % a ) , dict ( zip ( [ str ( x ) for x in range ( <NUM_LIT:10> ) ] , [ range ( <NUM_LIT:10> ) ] ) ) ) <EOL> def test_env_override ( self ) : <EOL> self . assertEqual ( os . path . exists ( self . filepath ) , False ) <EOL> os . environ [ '<STR_LIT>' ] = self . filepath <EOL> for a in range ( <NUM_LIT:10> ) : <EOL> os . environ [ '<STR_LIT>' % a ] = "<STR_LIT:100>" <EOL> _conf = CalvinConfig ( ) <EOL> for a in range ( <NUM_LIT:10> ) : <EOL> self . assertEqual ( _conf . get ( "<STR_LIT>" , "<STR_LIT>" % a ) , <NUM_LIT:100> ) <EOL> def test_lists ( self ) : <EOL> self . assertEqual ( os . path . exists ( self . filepath ) , False ) <EOL> os . environ [ '<STR_LIT>' ] = self . filepath <EOL> _conf = CalvinConfig ( ) <EOL> _conf . add_section ( "<STR_LIT:test>" ) <EOL> test_item = [ str ( x ) for x in range ( <NUM_LIT:10> ) ] <EOL> _conf . set ( "<STR_LIT:test>" , "<STR_LIT>" , test_item ) <EOL> self . assertEqual ( _conf . get ( "<STR_LIT:test>" , "<STR_LIT>" ) , test_item ) <EOL> @ pytest . mark . xfail ( ) <EOL> def test_env_override_list_append ( self ) : <EOL> self . assertEqual ( os . path . exists ( self . filepath ) , False ) <EOL> os . environ [ '<STR_LIT>' ] = self . filepath <EOL> _conf = CalvinConfig ( ) <EOL> _conf . add_section ( "<STR_LIT:test>" ) <EOL> test_item = [ str ( x ) for x in range ( <NUM_LIT:10> ) ] <EOL> _conf . set ( "<STR_LIT:test>" , "<STR_LIT>" , test_item ) <EOL> os . environ [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> self . assertEqual ( _conf . get ( "<STR_LIT:test>" , "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> test_item = range ( <NUM_LIT:10> ) <EOL> test_item2 = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> _conf . set ( "<STR_LIT:test>" , "<STR_LIT>" , test_item ) <EOL> os . environ [ '<STR_LIT>' ] = os . pathsep . join ( test_item2 ) <EOL> self . assertEqual ( _conf . get ( "<STR_LIT:test>" , "<STR_LIT>" ) , test_item2 + test_item ) <EOL> test_item = [ str ( x ) for x in range ( <NUM_LIT:10> ) ] <EOL> _conf . set ( "<STR_LIT:test>" , "<STR_LIT>" , test_item ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( _conf . get ( "<STR_LIT:test>" , "<STR_LIT>" ) , test_item2 + test_item ) </s>
