<s> from __future__ import absolute_import <EOL> import os <EOL> import os . path <EOL> import tempfile <EOL> from salttesting import TestCase <EOL> from salttesting . helpers import ensure_in_syspath <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> import salt . loader <EOL> import salt . config <EOL> import integration <EOL> from salt . exceptions import SaltRenderError <EOL> from salt . ext . six . moves import StringIO <EOL> import salt . ext . six as six <EOL> REQUISITES = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class StateConfigRendererTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . root_dir = tempfile . mkdtemp ( dir = integration . TMP ) <EOL> self . state_tree_dir = os . path . join ( self . root_dir , '<STR_LIT>' ) <EOL> self . cache_dir = os . path . join ( self . root_dir , '<STR_LIT>' ) <EOL> if not os . path . isdir ( self . root_dir ) : <EOL> os . makedirs ( self . root_dir ) <EOL> if not os . path . isdir ( self . state_tree_dir ) : <EOL> os . makedirs ( self . state_tree_dir ) <EOL> if not os . path . isdir ( self . cache_dir ) : <EOL> os . makedirs ( self . cache_dir ) <EOL> self . config = salt . config . minion_config ( None ) <EOL> self . config [ '<STR_LIT>' ] = self . root_dir <EOL> self . config [ '<STR_LIT>' ] = False <EOL> self . config [ '<STR_LIT:id>' ] = '<STR_LIT>' <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . config [ '<STR_LIT>' ] = dict ( base = [ self . state_tree_dir ] ) <EOL> self . config [ '<STR_LIT>' ] = self . cache_dir <EOL> self . config [ '<STR_LIT:test>' ] = False <EOL> self . _renderers = salt . loader . render ( <EOL> self . config , <EOL> { '<STR_LIT>' : lambda a , b : False } <EOL> ) <EOL> def _render_sls ( self , <EOL> content , <EOL> sls = '<STR_LIT>' , <EOL> saltenv = '<STR_LIT>' , <EOL> argline = '<STR_LIT>' , <EOL> ** kws ) : <EOL> return self . _renderers [ '<STR_LIT>' ] ( <EOL> StringIO ( content ) , saltenv = saltenv , sls = sls , <EOL> argline = argline , <EOL> renderers = salt . loader . render ( self . config , { } ) , <EOL> ** kws <EOL> ) <EOL> def test_state_config ( self ) : <EOL> result = self . _render_sls ( '''<STR_LIT>''' , sls = '<STR_LIT:test>' ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:3> ) <EOL> self . assertTrue ( '<STR_LIT>' in result and '<STR_LIT:test>' in result ) <EOL> self . assertTrue ( '<STR_LIT>' in result ) <EOL> self . assertEqual ( result [ '<STR_LIT:test>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , <EOL> '<STR_LIT>' ) <EOL> def test_sls_dir ( self ) : <EOL> result = self . _render_sls ( '''<STR_LIT>''' , sls = '<STR_LIT>' ) <EOL> self . assertEqual ( result [ '<STR_LIT:test>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , <EOL> '<STR_LIT>' ) <EOL> def test_states_declared_with_shorthand_no_args ( self ) : <EOL> result = self . _render_sls ( '''<STR_LIT>''' ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:3> ) <EOL> for args in ( result [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> result [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> self . assertTrue ( isinstance ( args , list ) ) <EOL> self . assertEqual ( len ( args ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( result [ '<STR_LIT:test>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> def test_adding_state_name_arg_for_dot_state_id ( self ) : <EOL> result = self . _render_sls ( '''<STR_LIT>''' , sls = '<STR_LIT:test>' ) <EOL> self . assertEqual ( <EOL> result [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , '<STR_LIT:test>' <EOL> ) <EOL> self . assertEqual ( <EOL> result [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' <EOL> ) <EOL> def test_state_prefix ( self ) : <EOL> result = self . _render_sls ( '''<STR_LIT>''' , sls = '<STR_LIT:test>' ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( '<STR_LIT>' in result ) <EOL> self . assertTrue ( '<STR_LIT>' in result ) <EOL> def test_dot_state_id_in_requisites ( self ) : <EOL> for req in REQUISITES : <EOL> result = self . _render_sls ( '''<STR_LIT>''' . format ( req ) , sls = '<STR_LIT:test>' ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( '<STR_LIT>' in result ) <EOL> self . assertTrue ( '<STR_LIT>' in result ) <EOL> self . assertEqual ( <EOL> result [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ req ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT>' <EOL> ) <EOL> def test_relative_include_with_requisites ( self ) : <EOL> for req in REQUISITES : <EOL> result = self . _render_sls ( '''<STR_LIT>''' . format ( req ) , sls = '<STR_LIT>' ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] [ <NUM_LIT:1> ] , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( <EOL> result [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ req ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_relative_include_and_extend ( self ) : <EOL> result = self . _render_sls ( '''<STR_LIT>''' , sls = '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in result [ '<STR_LIT>' ] ) <EOL> def test_multilevel_relative_include_with_requisites ( self ) : <EOL> for req in REQUISITES : <EOL> result = self . _render_sls ( '''<STR_LIT>''' . format ( req ) , sls = '<STR_LIT>' ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] [ <NUM_LIT:1> ] , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] [ <NUM_LIT:2> ] , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( <EOL> result [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ req ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_multilevel_relative_include_beyond_top_level ( self ) : <EOL> self . assertRaises ( SaltRenderError , self . _render_sls , '''<STR_LIT>''' , sls = '<STR_LIT>' ) <EOL> def test_start_state_generation ( self ) : <EOL> result = self . _render_sls ( '''<STR_LIT>''' , sls = '<STR_LIT:test>' , argline = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( <EOL> result [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT:A>' <EOL> ) <EOL> def test_goal_state_generation ( self ) : <EOL> result = self . _render_sls ( '''<STR_LIT>''' , sls = '<STR_LIT>' , argline = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( result ) , len ( '<STR_LIT>' ) + <NUM_LIT:1> ) <EOL> reqs = result [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> self . assertEqual ( <EOL> set ( [ next ( six . itervalues ( i ) ) for i in reqs ] ) , set ( '<STR_LIT>' ) <EOL> ) <EOL> def test_implicit_require_with_goal_state ( self ) : <EOL> result = self . _render_sls ( '''<STR_LIT>''' , sls = '<STR_LIT:test>' , argline = '<STR_LIT>' ) <EOL> sids = '<STR_LIT>' [ : : - <NUM_LIT:1> ] <EOL> for i , sid in enumerate ( sids ) : <EOL> if i < len ( sids ) - <NUM_LIT:1> : <EOL> self . assertEqual ( <EOL> result [ sid ] [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , <EOL> sids [ i + <NUM_LIT:1> ] <EOL> ) <EOL> F_args = result [ '<STR_LIT:F>' ] [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( F_args ) , <NUM_LIT:3> ) <EOL> F_req = F_args [ <NUM_LIT:2> ] [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( F_req ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( F_req [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , '<STR_LIT:A>' ) <EOL> self . assertEqual ( F_req [ <NUM_LIT:2> ] [ '<STR_LIT>' ] , '<STR_LIT:B>' ) <EOL> G_args = result [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( G_args ) , <NUM_LIT:3> ) <EOL> G_req = G_args [ <NUM_LIT:2> ] [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( G_req ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( G_req [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , '<STR_LIT:D>' ) <EOL> self . assertEqual ( G_req [ <NUM_LIT:2> ] [ '<STR_LIT>' ] , '<STR_LIT:F>' ) <EOL> goal_args = result [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( goal_args ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( <EOL> [ next ( six . itervalues ( i ) ) for i in goal_args [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ] , <EOL> list ( '<STR_LIT>' ) <EOL> ) <EOL> def test_slsdir ( self ) : <EOL> result = self . _render_sls ( '''<STR_LIT>''' , sls = '<STR_LIT>' , argline = '<STR_LIT>' ) <EOL> r = result [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] <EOL> self . assertEqual ( r , '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( StateConfigRendererTestCase , needs_daemon = False ) </s>
