<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> from textwrap import dedent <EOL> from pants . backend . codegen . targets . java_thrift_library import JavaThriftLibrary <EOL> from pants . backend . codegen . tasks . apache_thrift_gen import ApacheThriftGen <EOL> from pants . backend . jvm . targets . java_library import JavaLibrary <EOL> from pants_test . tasks . task_test_base import TaskTestBase <EOL> class ApacheThriftGenTest ( TaskTestBase ) : <EOL> @ classmethod <EOL> def task_type ( cls ) : <EOL> return ApacheThriftGen <EOL> def setUp ( self ) : <EOL> super ( ApacheThriftGenTest , self ) . setUp ( ) <EOL> def generate_single_thrift_target ( self , java_thrift_library ) : <EOL> context = self . context ( target_roots = [ java_thrift_library ] ) <EOL> apache_thrift_gen = self . create_task ( context ) <EOL> apache_thrift_gen . execute ( ) <EOL> def is_synthetic_java_library ( target ) : <EOL> return isinstance ( target , JavaLibrary ) and target . is_synthetic <EOL> synthetic_targets = context . targets ( predicate = is_synthetic_java_library ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( synthetic_targets ) ) <EOL> return synthetic_targets [ <NUM_LIT:0> ] <EOL> def test_single_namespace ( self ) : <EOL> self . create_file ( '<STR_LIT>' , contents = dedent ( """<STR_LIT>""" ) ) <EOL> one = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = JavaThriftLibrary , <EOL> sources = [ '<STR_LIT>' ] , <EOL> compiler = '<STR_LIT>' ) <EOL> synthetic_target = self . generate_single_thrift_target ( one ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , list ( synthetic_target . sources_relative_to_source_root ( ) ) ) <EOL> def test_nested_namespaces ( self ) : <EOL> self . create_file ( '<STR_LIT>' , contents = dedent ( """<STR_LIT>""" ) ) <EOL> self . create_file ( '<STR_LIT>' , contents = dedent ( """<STR_LIT>""" ) ) <EOL> one = self . make_target ( spec = '<STR_LIT>' , <EOL> target_type = JavaThriftLibrary , <EOL> sources = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> compiler = '<STR_LIT>' ) <EOL> synthetic_target = self . generate_single_thrift_target ( one ) <EOL> self . assertEqual ( sorted ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> sorted ( synthetic_target . sources_relative_to_source_root ( ) ) ) </s>
