<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> from pants . base . exceptions import TaskError <EOL> from pants . util . contextutil import temporary_dir , temporary_file <EOL> from pants_test . contrib . android . test_android_base import TestAndroidBase <EOL> from pants . contrib . android . tasks . sign_apk import SignApkTask <EOL> class SignApkTest ( TestAndroidBase ) : <EOL> _TEST_KEYSTORE = '<STR_LIT>' <EOL> @ classmethod <EOL> def task_type ( cls ) : <EOL> return SignApkTask <EOL> class FakeKeystore ( object ) : <EOL> def __init__ ( self ) : <EOL> self . build_type = '<STR_LIT>' <EOL> self . keystore_name = '<STR_LIT>' <EOL> self . keystore_location = '<STR_LIT>' <EOL> self . keystore_alias = '<STR_LIT>' <EOL> self . keystore_password = '<STR_LIT>' <EOL> self . key_password = '<STR_LIT>' <EOL> class FakeDistribution ( object ) : <EOL> @ classmethod <EOL> def binary ( cls , tool ) : <EOL> return '<STR_LIT>' . format ( tool ) <EOL> def _get_context ( self , location = _TEST_KEYSTORE ) : <EOL> self . set_options ( keystore_config_location = location ) <EOL> return self . context ( ) <EOL> def test_sign_apk_smoke ( self ) : <EOL> task = self . create_task ( self . _get_context ( ) ) <EOL> task . execute ( ) <EOL> def test_no_location_defined ( self ) : <EOL> task = self . create_task ( self . _get_context ( location = '<STR_LIT>' ) ) <EOL> with self . assertRaises ( TaskError ) : <EOL> task . config_file <EOL> def test_setting_location ( self ) : <EOL> with temporary_dir ( ) as temp : <EOL> task = self . create_task ( self . _get_context ( location = temp ) ) <EOL> self . assertEquals ( temp , task . config_file ) <EOL> def test_package_name ( self ) : <EOL> with self . android_binary ( ) as android_binary : <EOL> key = self . FakeKeystore ( ) <EOL> target = android_binary <EOL> self . assertEquals ( SignApkTask . signed_package_name ( target , key . build_type ) , <EOL> '<STR_LIT>' ) <EOL> def test_setup_default_config ( self ) : <EOL> with temporary_dir ( ) as temp : <EOL> default_config = os . path . join ( temp , '<STR_LIT>' ) <EOL> SignApkTask . setup_default_config ( default_config ) <EOL> self . assertTrue ( os . path . isfile ( default_config ) ) <EOL> def test_setup_default_config_no_permission ( self ) : <EOL> with temporary_file ( ) as temp : <EOL> os . chmod ( temp . name , <NUM_LIT> ) <EOL> with self . assertRaises ( TaskError ) : <EOL> SignApkTask . setup_default_config ( temp . name ) <EOL> def test_render_args ( self ) : <EOL> with temporary_dir ( ) as temp : <EOL> with self . android_binary ( ) as android_binary : <EOL> task = self . create_task ( self . _get_context ( ) ) <EOL> target = android_binary <EOL> fake_key = self . FakeKeystore ( ) <EOL> task . _dist = self . FakeDistribution ( ) <EOL> expected_args = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> expected_args . extend ( [ '<STR_LIT>' . format ( temp , target . manifest . package_name , <EOL> fake_key . build_type ) ] ) <EOL> expected_args . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEquals ( expected_args , task . _render_args ( target , fake_key , '<STR_LIT>' , <EOL> temp ) ) </s>
