<s> import os <EOL> import shutil <EOL> import textwrap <EOL> from peru . compat import makedirs <EOL> from peru . runtime import CommandLineError <EOL> import shared <EOL> class PathsTest ( shared . PeruTest ) : <EOL> def setUp ( self ) : <EOL> self . test_root = shared . create_dir ( ) <EOL> self . project_dir = os . path . join ( self . test_root , '<STR_LIT>' ) <EOL> self . state_dir = os . path . join ( self . project_dir , '<STR_LIT>' ) <EOL> self . cache_dir = os . path . join ( self . state_dir , '<STR_LIT>' ) <EOL> self . yaml = textwrap . dedent ( '''<STR_LIT>''' ) <EOL> shared . write_files ( self . project_dir , { '<STR_LIT>' : self . yaml } ) <EOL> self . peru_file = os . path . join ( self . project_dir , '<STR_LIT>' ) <EOL> self . foo_dir = os . path . join ( self . test_root , '<STR_LIT:foo>' ) <EOL> shared . write_files ( self . foo_dir , { '<STR_LIT:bar>' : '<STR_LIT>' } ) <EOL> self . cwd = os . path . join ( self . project_dir , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> makedirs ( self . cwd ) <EOL> def assert_success ( self , sync_dir , state_dir , cache_dir , more_excludes = [ ] ) : <EOL> shared . assert_contents ( sync_dir , { '<STR_LIT:bar>' : '<STR_LIT>' } , <EOL> excludes = [ '<STR_LIT>' , '<STR_LIT>' ] + more_excludes ) <EOL> assert os . path . isfile ( os . path . join ( state_dir , '<STR_LIT>' ) ) <EOL> assert os . path . isdir ( os . path . join ( cache_dir , '<STR_LIT>' ) ) <EOL> def test_unmodified_sync ( self ) : <EOL> shared . run_peru_command ( [ '<STR_LIT>' ] , self . cwd ) <EOL> self . assert_success ( self . project_dir , self . state_dir , self . cache_dir ) <EOL> def test_peru_file_and_sync_dir_must_be_set_together ( self ) : <EOL> for command in [ [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ] : <EOL> with self . assertRaises ( CommandLineError ) : <EOL> shared . run_peru_command ( command , cwd = self . cwd ) <EOL> def test_file_and_file_basename_incompatible ( self ) : <EOL> with self . assertRaises ( CommandLineError ) : <EOL> shared . run_peru_command ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> cwd = self . cwd ) <EOL> def test_setting_all_flags ( self ) : <EOL> cwd = shared . create_dir ( ) <EOL> sync_dir = shared . create_dir ( ) <EOL> state_dir = shared . create_dir ( ) <EOL> cache_dir = shared . create_dir ( ) <EOL> shared . run_peru_command ( <EOL> [ '<STR_LIT>' , self . peru_file , '<STR_LIT>' , sync_dir , <EOL> '<STR_LIT>' , state_dir , '<STR_LIT>' , cache_dir , '<STR_LIT>' ] , <EOL> cwd ) <EOL> self . assert_success ( sync_dir , state_dir , cache_dir ) <EOL> def test_setting_all_env_vars ( self ) : <EOL> cache_dir = shared . create_dir ( ) <EOL> shared . run_peru_command ( [ '<STR_LIT>' ] , self . cwd , env = { <EOL> '<STR_LIT>' : cache_dir , <EOL> } ) <EOL> self . assert_success ( self . project_dir , self . state_dir , cache_dir ) <EOL> def test_flags_override_vars ( self ) : <EOL> flag_cache_dir = shared . create_dir ( ) <EOL> env_cache_dir = shared . create_dir ( ) <EOL> shared . run_peru_command ( [ '<STR_LIT>' , flag_cache_dir , '<STR_LIT>' ] , <EOL> self . cwd , <EOL> env = { '<STR_LIT>' : env_cache_dir } ) <EOL> self . assert_success ( self . project_dir , self . state_dir , flag_cache_dir ) <EOL> def test_relative_paths ( self ) : <EOL> '''<STR_LIT>''' <EOL> shared . run_peru_command ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:.>' , '<STR_LIT>' ] , <EOL> cwd = self . project_dir ) <EOL> self . assert_success ( self . project_dir , self . state_dir , self . cache_dir ) <EOL> def test_default_file_name ( self ) : <EOL> shutil . move ( self . peru_file , os . path . join ( self . project_dir , '<STR_LIT>' ) ) <EOL> shared . run_peru_command ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> cwd = self . cwd ) <EOL> self . assert_success ( self . project_dir , self . state_dir , self . cache_dir , <EOL> more_excludes = [ '<STR_LIT>' ] ) </s>
