<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 . artifact import Artifact <EOL> from pants . backend . jvm . repository import Repository <EOL> from pants . backend . python . python_artifact import PythonArtifact <EOL> from pants . backend . python . targets . python_library import PythonLibrary <EOL> from pants . backend . python . targets . python_target import PythonTarget <EOL> from pants . base . exceptions import TargetDefinitionException <EOL> from pants . build_graph . resources import Resources <EOL> from pants_test . base_test import BaseTest <EOL> class PythonTargetTest ( BaseTest ) : <EOL> def test_validation ( self ) : <EOL> internal_repo = Repository ( url = None , push_db_basedir = None ) <EOL> with self . assertRaises ( TargetDefinitionException ) : <EOL> self . make_target ( target_type = PythonTarget , <EOL> spec = "<STR_LIT>" , <EOL> provides = Artifact ( org = '<STR_LIT>' , name = '<STR_LIT>' , repo = internal_repo ) ) <EOL> spec = "<STR_LIT>" <EOL> pa = PythonArtifact ( name = '<STR_LIT:foo>' , version = '<STR_LIT:1.0>' , description = '<STR_LIT:foo>' ) <EOL> pt_with_artifact = self . make_target ( spec = spec , <EOL> target_type = PythonTarget , <EOL> provides = pa ) <EOL> self . assertEquals ( pt_with_artifact . address . spec , spec ) <EOL> spec = "<STR_LIT>" <EOL> pt_no_artifact = self . make_target ( spec = spec , <EOL> target_type = PythonTarget , <EOL> provides = None ) <EOL> self . assertEquals ( pt_no_artifact . address . spec , spec ) <EOL> def assert_single_resource_dep ( self , target , expected_resource_path , expected_resource_contents ) : <EOL> self . assertEqual ( <NUM_LIT:1> , len ( target . dependencies ) ) <EOL> resources_dep = target . dependencies [ <NUM_LIT:0> ] <EOL> self . assertIsInstance ( resources_dep , Resources ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( target . resources ) ) <EOL> resources_tgt = target . resources [ <NUM_LIT:0> ] <EOL> self . assertIs ( resources_dep , resources_tgt ) <EOL> self . assertEqual ( [ expected_resource_path ] , resources_tgt . sources_relative_to_buildroot ( ) ) <EOL> resource_rel_path = resources_tgt . sources_relative_to_buildroot ( ) [ <NUM_LIT:0> ] <EOL> with open ( os . path . join ( self . build_root , resource_rel_path ) ) as fp : <EOL> self . assertEqual ( expected_resource_contents , fp . read ( ) ) <EOL> return resources_tgt <EOL> def test_resources ( self ) : <EOL> self . create_file ( '<STR_LIT>' , contents = '<STR_LIT>' ) <EOL> lib = self . make_target ( spec = '<STR_LIT>' , target_type = PythonLibrary , resources = [ '<STR_LIT>' ] ) <EOL> self . assert_single_resource_dep ( lib , <EOL> expected_resource_path = '<STR_LIT>' , <EOL> expected_resource_contents = '<STR_LIT>' ) <EOL> def test_resource_targets ( self ) : <EOL> self . create_file ( '<STR_LIT>' , contents = '<STR_LIT>' ) <EOL> res = self . make_target ( spec = '<STR_LIT>' , target_type = Resources , sources = [ '<STR_LIT>' ] ) <EOL> lib = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = PythonLibrary , <EOL> resource_targets = [ res . address . spec ] ) <EOL> resource_dep = self . assert_single_resource_dep ( lib , <EOL> expected_resource_path = '<STR_LIT>' , <EOL> expected_resource_contents = '<STR_LIT>' ) <EOL> self . assertIs ( res , resource_dep ) </s>
