<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> from pants . backend . jvm . targets . java_library import JavaLibrary <EOL> from pants . backend . jvm . targets . jvm_target import JvmTarget <EOL> from pants . backend . jvm . tasks . prepare_resources import PrepareResources <EOL> from pants . build_graph . resources import Resources <EOL> from pants . build_graph . target import Target <EOL> from pants . util . contextutil import temporary_dir <EOL> from pants_test . tasks . task_test_base import TaskTestBase <EOL> class PrepareResourcesTest ( TaskTestBase ) : <EOL> @ classmethod <EOL> def task_type ( cls ) : <EOL> return PrepareResources <EOL> class NonJvmResourcesUsingTarget ( Target ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> kwargs . pop ( '<STR_LIT>' , None ) <EOL> super ( PrepareResourcesTest . NonJvmResourcesUsingTarget , self ) . __init__ ( * args , ** kwargs ) <EOL> @ property <EOL> def has_resources ( self ) : <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> @ property <EOL> def resources ( self ) : <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> def test_find_all_relevant_resources_targets ( self ) : <EOL> resources1 = self . make_target ( '<STR_LIT>' , target_type = Resources ) <EOL> resources2 = self . make_target ( '<STR_LIT>' , target_type = Resources ) <EOL> resources3 = self . make_target ( '<STR_LIT>' , target_type = Resources ) <EOL> resources4 = self . make_target ( '<STR_LIT>' , target_type = Resources ) <EOL> jvm_target = self . make_target ( '<STR_LIT>' , <EOL> target_type = JvmTarget , <EOL> resources = [ resources1 . address . spec ] ) <EOL> java_library = self . make_target ( '<STR_LIT>' , target_type = JavaLibrary ) <EOL> java_library2 = self . make_target ( '<STR_LIT>' , <EOL> target_type = JavaLibrary , <EOL> resources = [ resources4 . address . spec ] ) <EOL> other_target = self . make_target ( '<STR_LIT>' , <EOL> target_type = self . NonJvmResourcesUsingTarget , <EOL> resources = [ resources3 . address . spec ] ) <EOL> task = self . create_task ( self . context ( target_roots = [ resources2 , <EOL> jvm_target , <EOL> java_library , <EOL> java_library2 , <EOL> other_target ] ) ) <EOL> relevant_resources_targets = task . find_all_relevant_resources_targets ( ) <EOL> self . assertEqual ( sorted ( [ self . target ( '<STR_LIT>' ) , self . target ( '<STR_LIT>' ) ] ) , <EOL> sorted ( relevant_resources_targets ) ) <EOL> def test_prepare_resources_none ( self ) : <EOL> task = self . create_task ( self . context ( ) ) <EOL> resources = self . make_target ( '<STR_LIT>' , target_type = Resources ) <EOL> with temporary_dir ( ) as chroot : <EOL> task . prepare_resources ( resources , chroot ) <EOL> self . assertEqual ( [ ] , os . listdir ( chroot ) ) <EOL> def test_prepare_resources ( self ) : <EOL> task = self . create_task ( self . context ( ) ) <EOL> self . create_file ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . create_file ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> resources = self . make_target ( '<STR_LIT>' , <EOL> target_type = Resources , <EOL> sources = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> with temporary_dir ( ) as chroot : <EOL> task . prepare_resources ( resources , chroot ) <EOL> resource_files = [ ] <EOL> for root , dirs , files in os . walk ( chroot ) : <EOL> for f in files : <EOL> abs_path = os . path . join ( root , f ) <EOL> rel_path = os . path . relpath ( abs_path , chroot ) <EOL> with open ( abs_path ) as fp : <EOL> self . assertEqual ( rel_path , fp . read ( ) ) <EOL> resource_files . append ( rel_path ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , sorted ( resource_files ) ) </s>
