<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> import re <EOL> from pants . base . build_environment import get_buildroot <EOL> from pants . util . contextutil import temporary_dir <EOL> from pants . util . dirutil import safe_rmtree <EOL> from pants_test . pants_run_integration_test import PantsRunIntegrationTest <EOL> def shared_artifacts ( version , extra_jar = None ) : <EOL> published_file_list = [ '<STR_LIT>' . format ( version ) , <EOL> '<STR_LIT>' . format ( version ) , <EOL> '<STR_LIT>' . format ( version ) , <EOL> '<STR_LIT>' . format ( version ) ] <EOL> if extra_jar : <EOL> published_file_list . append ( extra_jar ) <EOL> return { '<STR_LIT>' . format ( version ) : published_file_list } <EOL> def publish_extra_config ( unique_config ) : <EOL> return { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : unique_config , <EOL> } , <EOL> } , <EOL> } <EOL> class JarPublishIntegrationTest ( PantsRunIntegrationTest ) : <EOL> GOLDEN_DATA_DIR = '<STR_LIT>' <EOL> @ property <EOL> def pushdb_root ( self ) : <EOL> return os . path . join ( get_buildroot ( ) , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def setUp ( self ) : <EOL> self . maxDiff = None <EOL> safe_rmtree ( self . pushdb_root ) <EOL> def tearDown ( self ) : <EOL> safe_rmtree ( self . pushdb_root ) <EOL> def test_scala_publish ( self ) : <EOL> unique_artifacts = { '<STR_LIT>' : <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> '<STR_LIT>' : <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] } <EOL> self . publish_test ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> dict ( unique_artifacts . items ( ) + shared_artifacts ( '<STR_LIT>' ) . items ( ) ) , <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> extra_options = [ '<STR_LIT>' ] , <EOL> expected_primary_artifact_count = <NUM_LIT:3> , <EOL> assert_publish_config_contents = True ) <EOL> def test_java_publish ( self ) : <EOL> self . publish_test ( '<STR_LIT>' , <EOL> shared_artifacts ( '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' ] , ) <EOL> def test_protobuf_publish ( self ) : <EOL> unique_artifacts = { '<STR_LIT>' : <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> '<STR_LIT>' : <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] } <EOL> self . publish_test ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> unique_artifacts , <EOL> [ '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> extra_options = [ '<STR_LIT>' ] , <EOL> expected_primary_artifact_count = <NUM_LIT:2> ) <EOL> def test_named_snapshot ( self ) : <EOL> name = "<STR_LIT>" <EOL> self . publish_test ( '<STR_LIT>' , <EOL> shared_artifacts ( name ) , <EOL> [ '<STR_LIT>' ] , <EOL> extra_options = [ '<STR_LIT>' . format ( name ) ] ) <EOL> def test_publish_override_flag_succeeds ( self ) : <EOL> override = "<STR_LIT>" <EOL> self . publish_test ( '<STR_LIT>' , <EOL> shared_artifacts ( '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' ] , <EOL> extra_options = [ '<STR_LIT>' . format ( override ) ] ) <EOL> def publish_extras_runner ( self , extra_config = None , artifact_name = None , success_expected = True ) : <EOL> self . publish_test ( '<STR_LIT>' , <EOL> shared_artifacts ( '<STR_LIT>' , artifact_name ) , <EOL> [ '<STR_LIT>' ] , <EOL> extra_options = [ '<STR_LIT>' ] , <EOL> extra_config = extra_config , <EOL> success_expected = success_expected ) <EOL> def test_publish_extras_name_classifier ( self ) : <EOL> self . publish_extras_runner ( extra_config = publish_extra_config ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) , <EOL> artifact_name = '<STR_LIT>' ) <EOL> def test_publish_extras_name ( self ) : <EOL> self . publish_extras_runner ( extra_config = publish_extra_config ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) , <EOL> artifact_name = '<STR_LIT>' ) <EOL> def test_publish_extras_name_extension ( self ) : <EOL> self . publish_extras_runner ( extra_config = publish_extra_config ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) , <EOL> artifact_name = '<STR_LIT>' ) <EOL> def test_publish_extras_extension ( self ) : <EOL> self . publish_extras_runner ( extra_config = publish_extra_config ( { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) , <EOL> artifact_name = '<STR_LIT>' ) <EOL> def test_publish_extras_extension_classifier ( self ) : <EOL> self . publish_extras_runner ( extra_config = publish_extra_config ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) , <EOL> artifact_name = '<STR_LIT>' ) <EOL> def test_publish_extras_classifier ( self ) : <EOL> self . publish_extras_runner ( extra_config = publish_extra_config ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) , <EOL> artifact_name = '<STR_LIT>' ) <EOL> def test_publish_extras_invalid_args ( self ) : <EOL> self . publish_extras_runner ( extra_config = publish_extra_config ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) , <EOL> artifact_name = '<STR_LIT>' , <EOL> success_expected = False ) <EOL> def test_scala_publish_classifiers ( self ) : <EOL> self . publish_test ( '<STR_LIT>' , <EOL> dict ( { <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] } ) , <EOL> [ ] , <EOL> assert_publish_config_contents = True ) <EOL> def test_override_via_coord ( self ) : <EOL> self . publish_test ( <EOL> target = '<STR_LIT>' , <EOL> artifacts = dict ( { '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] } ) , <EOL> pushdb_files = [ ] , <EOL> extra_options = [ '<STR_LIT>' ] , <EOL> assert_publish_config_contents = True ) <EOL> def test_override_via_address ( self ) : <EOL> target = '<STR_LIT>' <EOL> self . publish_test ( <EOL> target = target , <EOL> artifacts = dict ( { '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] } ) , <EOL> pushdb_files = [ ] , <EOL> extra_options = [ '<STR_LIT>' . format ( target ) ] , <EOL> assert_publish_config_contents = True ) <EOL> def publish_test ( self , target , artifacts , pushdb_files , extra_options = None , extra_config = None , <EOL> extra_env = None , expected_primary_artifact_count = <NUM_LIT:1> , success_expected = True , <EOL> assert_publish_config_contents = False ) : <EOL> """<STR_LIT>""" <EOL> with temporary_dir ( ) as publish_dir : <EOL> options = [ '<STR_LIT>' . format ( publish_dir ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> if extra_options : <EOL> options . extend ( extra_options ) <EOL> pants_run = self . run_pants ( [ '<STR_LIT>' ] + options + [ target ] , config = extra_config , <EOL> extra_env = extra_env ) <EOL> if success_expected : <EOL> self . assert_success ( pants_run , "<STR_LIT>" ) <EOL> else : <EOL> self . assert_failure ( pants_run , <EOL> "<STR_LIT>" ) <EOL> return <EOL> for pushdb_file in pushdb_files : <EOL> pushdb_dir = os . path . dirname ( os . path . join ( self . pushdb_root , pushdb_file ) ) <EOL> self . assertTrue ( os . path . exists ( pushdb_dir ) ) <EOL> for pushdb_file in pushdb_files : <EOL> self . assertFalse ( os . path . exists ( os . path . join ( self . pushdb_root , pushdb_file ) ) ) <EOL> for directory , artifact_list in artifacts . items ( ) : <EOL> for artifact in artifact_list : <EOL> artifact_path = os . path . join ( publish_dir , directory , artifact ) <EOL> self . assertTrue ( os . path . exists ( artifact_path ) ) <EOL> if assert_publish_config_contents : <EOL> if artifact . endswith ( '<STR_LIT>' ) or artifact . endswith ( '<STR_LIT>' ) : <EOL> self . compare_file_contents ( artifact_path , directory ) <EOL> def compare_file_contents ( self , artifact_path , directory ) : <EOL> """<STR_LIT>""" <EOL> [ package_dir , artifact_name , version ] = directory . rsplit ( os . path . sep , <NUM_LIT:2> ) <EOL> file_name = os . path . basename ( artifact_path ) <EOL> golden_file_nm = os . path . join ( JarPublishIntegrationTest . GOLDEN_DATA_DIR , <EOL> package_dir . replace ( os . path . sep , '<STR_LIT:.>' ) , artifact_name , file_name ) <EOL> with open ( artifact_path , '<STR_LIT:r>' ) as test_file : <EOL> generated_file = test_file . read ( ) <EOL> with open ( golden_file_nm , '<STR_LIT:r>' ) as golden_file : <EOL> golden_file_contents = golden_file . read ( ) <EOL> if artifact_path . endswith ( '<STR_LIT>' ) : <EOL> generated_file = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , generated_file ) <EOL> return self . assertMultiLineEqual ( generated_file , golden_file_contents ) </s>
