
    $                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SS	KJr  S
 rS rS r " S S\5      rg)zFA shared library for processing and validating Android test arguments.    )absolute_import)division)unicode_literals)arg_file)arg_util)arg_validate)catalog_manager)
exceptionsc                  8    S// SQ0 S./ / SQSS0S./ SS/0 S.S	.$ )
aO  Returns the rules for Android test args which depend on the test type.

This dict is declared in a function rather than globally to avoid garbage
collection issues during unit tests.

Returns:
  A dict keyed by whether type-specific args are required or optional, and
  with a nested dict containing any default values for those args.
test)num_uniform_shardstest_targets_for_shardtest_packagetest_runner_classtest_targetsuse_orchestratorrequiredoptionaldefaults)robo_directivesrobo_scriptresignr   Tscenario_numbersscenario_labels)instrumentationroboz	game-loop r       ?lib/googlecloudsdk/api_lib/firebase/test/android/arg_manager.pyTypedArgRulesr!      sO     h  B )+<=!
 r   c            
      &    SS// SQSSSSSSSS	.S
.$ )aT  Returns the rules for Android test args which are shared by all test types.

This dict is declared in a function rather than globally to avoid garbage
collection issues during unit tests.

Returns:
  A dict keyed by whether shared args are required or optional, and with a
  nested dict containing any default values for those shared args.
typeapp)additional_apksapp_packageasync_auto_google_loginclient_detailsdevice
device_idsdirectories_to_pullenvironment_variablesgrant_permissionslocalesnetwork_profilenum_flaky_test_attempts	obb_filesorientationsos_version_idsother_filesperformance_metricsrecord_videoresults_bucketresults_dirresults_history_nametimeoutFTr   i  all)r'   r(   r1   r6   r7   r;   r.   r   r   r   r   r    SharedArgRulesr=   >   s6     5/4 #%&!%$7$
 $r   c                  P    [         R                  " [        5       [        5       5      $ )z=Returns a set containing the names of every Android test arg.)r   GetSetOfAllTestArgsr!   r=   r   r   r    
AllArgsSetr@   o   s    		%	%mo~7G	HHr   c                   @    \ rS rSrSr   S
S jrS rS rS rS r	S	r
g)AndroidArgsManagert   z+Manages test arguments for Android devices.Nc                     U=(       d    [         R                  " 5       U l        U=(       d
    [        5       U l        U=(       d
    [        5       U l        g)a8  Constructs an AndroidArgsManager for a single Android test matrix.

Args:
  catalog_mgr: an AndroidCatalogManager object.
  typed_arg_rules: a nested dict of dicts which are keyed first on the test
    type, then by whether args are required or optional, and what their
    default values are. If None, the default from TypedArgRules() is used.
  shared_arg_rules: a dict keyed by whether shared args are required or
    optional, and with a nested dict containing any default values for those
    shared args. If None, the default dict from SharedArgRules() is used.
N)r	   AndroidCatalogManager_catalog_mgrr!   _typed_arg_rulesr=   _shared_arg_rules)selfcatalog_mgrtyped_arg_rulesshared_arg_ruless       r    __init__AndroidArgsManager.__init__w   s9     $N'L'L'ND+>}D-A1ADr   c                 ,   [         R                  " U R                  U R                  5      n[        R
                  " UR                  U5      n[         R                  " XS5        U R                  U5      nU R                  U5        U R                  U   S   nU R                  S   n[         R                  " X5        [         R                  " X5        U R                  U5        [        R                  " XU R                  U R                  U5        [        R                  " XR                  5        [        R                  " XR                  5        [        R                   " U5        [        R"                  " U5        [        R$                  " UR&                  5        [        R(                  " U5        [        R*                  " U5        [        R,                  " U5        [        R.                  " UR0                  5        [        R2                  " U5        g)aE  Load, apply defaults, and perform validation on test arguments.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    gcloud command invocation (i.e. group and command arguments combined).
    Arg values from an optional arg-file and/or arg default values may be
    added to this argparse namespace.

Raises:
  InvalidArgumentException: If an argument name is unknown, an argument does
    not contain a valid value, or an argument is not valid when used with
    the given type of test.
  RequiredArgumentException: If a required arg is missing.
Tr   N)r   r?   rG   rH   r   GetArgsFromArgFileargspecApplyLowerPriorityArgsGetTestTypeOrRaise_CheckForConflictingArgs#_ApplyLegacyMatrixDimensionDefaultsr   ValidateArgsForTestTypeValidateOsVersionsrF   ValidateDeviceListValidateResultsBucketValidateResultsDir NormalizeAndValidateObbFileNamesr2   ValidateRoboDirectivesList ValidateEnvironmentVariablesListValidateTestTargetsForShard)NormalizeAndValidateDirectoriesToPullListr,   ValidateScenarioNumbers)rI   argsall_test_args_setargs_from_file	test_typetyped_arg_defaultsshared_arg_defaultss          r    PrepareAndroidArgsManager.Prepare   s    !44T5J5J595K5KM001BDN##D$?''-I!!$'..y9*E00<##D=##D>,,T2(($:O:O)-)?)?):< ##D*;*;<##D*;*;<&&t,##D)11$..A++D111$7,,T2::  "((.r   c                    UR                   (       d  UR                  (       a  SOSUl         UR                   U R                  ;  a0  [        R                  " SSR                  UR                   5      5      eUR                   $ )a  If the test type is not user-specified, infer the most reasonable value.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    gcloud command invocation (i.e. group and command arguments combined).

Returns:
  The type of the test to be run (e.g. 'robo' or 'instrumentation') and
  sets the 'type' arg if it was not user-specified.

Raises:
  InvalidArgumentException if an explicit test type is invalid.
r   r   r#   z'{0}' is not a valid test type.)r#   r   rG   r
   InvalidArgumentExceptionformatrI   ra   s     r    rS   %AndroidArgsManager.GetTestTypeOrRaise   sa     99'+yy#fdiyy---//
3::499EG G99r   c                 h   UR                   (       a  UR                  (       a  [        R                  " SS5      eUR                  (       a  [        R                  " SS5      eUR
                  (       a  [        R                  " SS5      eUR                  (       a  [        R                  " SS5      egg)z5Check for any args that cannot appear simultaneously.z--device-idsz--devicez--os-version-idsz	--localesz--orientationsN)r*   r+   r
   ConflictingArgumentsExceptionr4   r/   r3   rl   s     r    rT   +AndroidArgsManager._CheckForConflictingArgs   s    {{	66~7AC 	C			667I7AC 	C	66{JOO			667G7AC 	C 
 r   c                 L   UR                   (       a  gUR                  (       d<  UR                  (       d+  UR                  (       d  UR                  (       d	  0 /Ul         gUR                  (       d   U R
                  R                  5       /Ul        UR                  (       d   U R
                  R                  5       /Ul        UR                  (       d   U R
                  R                  5       /Ul        UR                  (       d!  U R
                  R                  5       /Ul        gg)zFApply defaults to each dimension flag only if not using sparse matrix.N)
r*   r+   r4   r/   r3   rF   GetDefaultModelGetDefaultVersionGetDefaultLocaleGetDefaultOrientationrl   s     r    rU   6AndroidArgsManager._ApplyLegacyMatrixDimensionDefaults   s    {{ OOt22dllDdk??**::<=do!..@@BCd<<''88:;dl,,BBDEd r   )rF   rH   rG   )NNN)__name__
__module____qualname____firstlineno____doc__rM   rg   rS   rT   rU   __static_attributes__r   r   r    rB   rB   t   s-    3  # $B&+/Z*C Fr   rB   N)r{   
__future__r   r   r   $googlecloudsdk.api_lib.firebase.testr   r   r   ,googlecloudsdk.api_lib.firebase.test.androidr	   googlecloudsdk.callioper
   r!   r=   r@   objectrB   r   r   r    <module>r      sE    M &  ' 9 9 = H .D.bI
{F {Fr   