
    B              
          S r SSKJr  SSKJr  SSKJr  SSK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r " S S\R$                  " S/ SQ5      5      rSrSrSrSrSr\S\S\S\S\S0rS r " S S\5      rS rS rS rS  r S! r!g)"z*A library to build a test results summary.    )absolute_import)division)unicode_literalsN)
exceptions)util)logzNative crashzFor test execution [{0}], a native process crashed on the device. This could be caused by your app, by an app dependency, or by an unrelated cause.zInfrastructure failurezNeed help for test execution [{0}]? Please join the #test-lab Slack channel at https://firebase.community/ and include test matrix ID [{1}] with your question.c                       \ rS rSrSrSrg)TestOutcome(   a  A tuple to hold the outcome for a single test axis value.

Fields:
  outcome: string containing the test outcome (e.g. 'Passed')
  axis_value: string representing one axis value within the matrix.
  test_details: string with extra details (e.g. "Incompatible architecture")
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       ;lib/googlecloudsdk/api_lib/firebase/test/results_summary.pyr
   r
   (   s    r   r
   outcome
axis_valuetest_detailsPassedFlakyFailedInconclusiveSkipped
         r   2   c                 h    [        [        U R                     U R                  U R                  /5      $ )zCTransform a TestOutcome to a tuple yielding the desired sort order.)tuple_OUTCOME_SORTINGr   r   r   )xs    r   _TestOutcomeSortKeyr&   E   s&    	 +Q^^Q\\J	KKr   c                   f    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rSrg)ToolResultsSummaryFetcherJ   zACreates Test Results summary using data from the ToolResults API.c           
         Xl         X l        X0l        UR                  U l        UR
                  U l        XPl        UR                  R                  R                  [        UR                  R                  R                  [        UR                  R                  R                  [        UR                  R                  R                   ["        UR                  R                  R$                  [&        0U l        g)a_  Constructs a ToolResultsSummaryFetcher.

Args:
  project: string containing the GCE project id.
  client: ToolResults API client lib generated by apitools.
  messages: ToolResults API message classes generated by apitools.
  tool_results_ids: a ToolResultsIds object holding history & execution IDs.
  test_matrix_id: test matrix ID from Testing API.
N)_project_client	_messages
history_id_history_idexecution_id_execution_id_test_matrix_idOutcomeSummaryValueValuesEnumsuccess_SUCCESSfailure_FAILUREflaky_FLAKYskipped_SKIPPEDinconclusive_INCONCLUSIVE_outcome_names)selfprojectclientmessagestool_results_idstest_matrix_ids         r   __init__"ToolResultsSummaryFetcher.__init__M   s     MLN'22D)66D)//77//77//55v//77//<<mDr   c                 n   U R                   R                  U R                  U R                  U R                  S9n U R
                  R                  R                  U5      nUR                  $ ! [        R                   a4  nS[        R                  " U5      -   n[        R                  " U5      eSnAff = f)zGets a test execution's rolled-up outcome from the ToolResults service.

Returns:
  The rolled-up test execution outcome (type: toolresults_v1beta3.Outcome).

Raises:
  HttpException if the ToolResults service reports a back-end error.
)	projectId	historyIdexecutionIdz*Http error fetching test roll-up outcome: N)r-   0ToolresultsProjectsHistoriesExecutionsGetRequestr+   r/   r1   r,   projects_histories_executionsGetr   apitools_exceptions	HttpErrorr   GetErrorr   HttpException)r@   requestresponseerrormsgs        r   FetchMatrixRollupOutcome2ToolResultsSummaryFetcher.FetchMatrixRollupOutcomef   s     nnMM--""&& N (G*;;??Hh(( *84==;OOc$$S))*s   0A, ,B4 /B//B4c           	         / nU R                  5       nU(       d  [        R                  " S5        U$ U H  nUR                  nU R	                  U5      nUR
                  (       d'  [        R                  " SR                  U5      5        MX  U R                  U5      nU R                  Xe5        UR
                  R                  nU R                  U5      nUR                  [        UUUS95        M     [        U[        S9$ )a  Fetches test results and creates a test outcome summary.

Lists all the steps in an execution and creates a high-level outcome summary
for each step (pass/fail/inconclusive). Each step represents a test run on
a single device (e.g. running the tests on a Nexus 5 in portrait mode using
the en locale and API level 18).

Returns:
  A list of TestOutcome objects.

Raises:
  HttpException if the ToolResults service reports a back-end error.
zFNo test results found, something went wrong. Try re-running the tests.z$Step for [{0}] had no outcome value.r   key)_ListAllStepsr   warningdimensionValue_GetAxisValuer   format_GetStepOutcomeDetails_LogWarningssummary_GetOutcomeSummaryDisplayNameappendr
   sortedr&   )	r@   outcomesstepsstepdimension_valuer   detailsoutcome_summaryoutcome_strs	            r   $CreateMatrixOutcomeSummaryUsingSteps>ToolResultsSummaryFetcher.CreateMatrixOutcomeSummaryUsingStepsz   s     H E	kk
R o++o%%o6j \\:AA*MN--d3'.,,..88I#%$&	' $ ( 344r   c           	      d   / nU R                  5       nU(       d&  [        R                  " S5        U R                  5       $ U H  nUR                  nU R                  U5      nUR                  R                  (       d7  [        R                  " SR                  U5      5        U R                  5       s  $ U R                  U5      nU R                  Xe5        UR                  R                  R                  nU R                  U5      nUR                  [        XUS95        M     [        U[         S9$ )a  Fetches test results and creates a test outcome summary.

Lists all the environments in an execution and creates a high-level outcome
summary for each environment (pass/flaky/fail/skipped/inconclusive). Each
environment represents a combination of one or more test executions with the
same device configuration (e.g. running the tests on a Nexus 5 in portrait
mode using the en locale and API level 18).

Returns:
  A list of TestOutcome objects.

Raises:
  HttpException if the ToolResults service reports a back-end error.
zSEnvironment has no results, something went wrong. Displaying step outcomes instead.zMEnvironment for [{0}] had no outcome value. Displaying step outcomes instead.r   rZ   )_ListAllEnvironmentsr   r]   rn   r^   r_   environmentResultr   r`   _GetEnvironmentOutcomeDetailsrb   rc   rd   re   r
   rf   r&   )	r@   rg   environmentsenvironmentrj   r   rk   rl   rm   s	            r   +CreateMatrixOutcomeSummaryUsingEnvironmentsEToolResultsSummaryFetcher.CreateMatrixOutcomeSummaryUsingEnvironments   s    H,,.L 	kk 6688##22o%%o6j **22 --3VJ-?	A88::22;?g
,#55==EEo66Gkoo
!wPQ $$ ( 344r   c                     [         U;   a)  [        R                  " [        R	                  U5      5        [
        U;   a4  [        R                  " [        R	                  X R                  5      5        gg)zALog warnings if there was native crash or infrustructure failure.N)_NATIVE_CRASHr   r]   _NATIVE_CRASH_DETAILED_FORMATr`   _INFRASTRUCTURE_FAILURE'_INFRASTRUCTURE_FAILURE_DETAILED_FORMATr2   )r@   rk   r   s      r   rb   &ToolResultsSummaryFetcher._LogWarnings   sR    	kk/66zBC')	kk
1
8
8..01 *r   c           	          0 nU H  nUR                   X#R                  '   M     SR                  UR                  SS5      UR                  SS5      UR                  SS5      UR                  SS5      S9$ )Nz{m}-{v}-{l}-{o}Model?VersionLocaleOrientation)mvlo)valuer[   r`   get)r@   dimensionvalueaxes	dimensions       r   r_   'ToolResultsSummaryFetcher._GetAxisValue   sq    D#	%OOd== $$$
((7C
 
((9c
"
((8S
!
((=#
&	 % ( )r   c                    U R                  S5      n/ nUR                  UR                  5        UR                  (       aI  U R                  UR                  5      nUR                  UR                  5        UR                  (       a  MI  U$ )z}Lists all steps for a test execution using the ToolResults service.

Returns:
  The full list of steps for a test execution.
N)
_ListStepsextendrh   nextPageToken)r@   rT   rh   s      r   r\   'ToolResultsSummaryFetcher._ListAllSteps   si     t$HE	LL 

 
 !7!78hll8>>" 
 
 
  Lr   c                 Z   U R                   R                  U R                  U R                  U R                  SUS9n U R
                  R                  R                  U5      $ ! [        R                   a4  nS[        R                  " U5      -   n[        R                  " U5      eSnAff = f)aG  Lists one page of steps using the ToolResults service.

Args:
  page_token: A page token to attach to the List request. If it's None, then
    it returns at most the first 200 steps.

Returns:
  A ListStepsResponse containing a single page's steps.

Raises:
  HttpException if the ToolResults service reports a back-end error.
d   rI   rJ   rK   pageSize	pageTokenz0Http error while listing test results of steps: N)r-   6ToolresultsProjectsHistoriesExecutionsStepsListRequestr+   r/   r1   r,   #projects_histories_executions_stepsListrO   rP   r   rQ   r   rR   r@   
page_tokenrS   rU   rV   s        r   r   $ToolResultsSummaryFetcher._ListSteps   s     	MMmm&&**  	N 	" *\\==BB7KK(( *>
B c$$S))*   $A" "B*6/B%%B*c                    U R                  S5      n/ nUR                  UR                  5        UR                  (       aI  U R                  UR                  5      nUR                  UR                  5        UR                  (       a  MI  U$ )zLists all environments of a test execution using the ToolResults service.

Returns:
  A ListEnvironmentsResponse containing all environments within execution.
N)_ListEnvironmentsr   rt   r   )r@   rT   rt   s      r   rq   .ToolResultsSummaryFetcher._ListAllEnvironments  sv     %%d+HL--.

 
 ''(>(>?h(//0 
 
 
  r   c                 Z   U R                   R                  U R                  U R                  U R                  SUS9n U R
                  R                  R                  U5      $ ! [        R                   a4  nS[        R                  " U5      -   n[        R                  " U5      eSnAff = f)a^  Lists one page of environments using the ToolResults service.

Args:
  page_token: A page token to attach to the List request. If it's None, then
    it returns a maximum of 200 Environments.

Returns:
  A ListEnvironmentsResponse containing a single page's environments.

Raises:
  HttpException if the ToolResults service reports a back-end error.
r   r   z'Http error while listing test results: N)r-   =ToolresultsProjectsHistoriesExecutionsEnvironmentsListRequestr+   r/   r1   r,   *projects_histories_executions_environmentsr   rO   rP   r   rQ   r   rR   r   s        r   r   +ToolResultsSummaryFetcher._ListEnvironments  s     		F	Fmm&&**  
G 
" *\\DDII
 (( *5e8LLc$$S))*r   c                 B     U R                   U   $ ! [         a     gf = f)zTransforms the outcome enum to a human readable outcome.

Args:
  outcome: An Outcome.SummaryValueValuesEnum value.

Returns:
  A string containing a human readable outcome.
Unknown)r?   
ValueError)r@   r   s     r   rd   7ToolResultsSummaryFetcher._GetOutcomeSummaryDisplayName<  s*      )) s    
c                    UR                   nU R                  R                  R                  nUR                  R
                  nUR                  UR                  :X  aM  [        U5      nUR                  (       a/  UR                  R                  (       a  SR                  U[        S9$ U$ UR                  UR                  :X  a9  UR                  (       a  [        X$5      $ UR                  (       d  g[!        U5      $ UR                  UR"                  :X  a  [%        U5      $ UR                  UR&                  :X  a  [)        U5      $ g)CTurn test outcome counts and details into something human readable.	{d} ({c})dczUnknown failureUnknown outcome)r   r-   r3   r4   testExecutionSteptestSuiteOverviewsrc   r5   _GetSuccessCountDetailssuccessDetailotherNativeCrashr`   ry   r7   failureDetail_GetFailureDetail_GetFailureOrFlakyCountDetailsr=   _GetInconclusiveDetailr;   _GetSkippedDetail)r@   ri   r   summary_enumtest_suite_overviewsrk   s         r   ra   0ToolResultsSummaryFetcher._GetStepOutcomeDetailsJ  s    llG>>))@@L11DD,...'(<=g			7#8#8#I#I!!G}!==	L00	0			 ??## +,@AA	L55	5#G,,	L00	0w'' r   c                    UR                   R                  nU R                  R                  R                  nUR                   R
                  nUR                  UR                  :X  aM  [        U5      nUR                  (       a/  UR                  R                  (       a  SR                  U[        S9$ U$ UR                  UR                  :X  d  UR                  UR                  :X  a'  UR                  (       a  [!        X$5      $ [#        U5      $ UR                  UR$                  :X  a  ['        U5      $ UR                  UR(                  :X  a  [+        U5      $ g)r   r   r   r   )rr   r   r-   r3   r4   r   rc   r5   r   r   r   r`   ry   r7   r9   r   r   r   r=   r   r;   r   )r@   ru   r   r   r   rk   s         r   rs   7ToolResultsSummaryFetcher._GetEnvironmentOutcomeDetailsg  s   ++33G>>))@@L&88KK,...'(<=g			7#8#8#I#I!!G}!==	L00	0GOO|GYGY4Y			 ??+,@AA	L55	5#G,,	L00	0w'' r   )r,   r1   r/   r-   r?   r+   r2   N)r   r   r   r   r   rF   rW   rn   rv   rb   r_   r\   r   rq   r   rd   ra   rs   r   r   r   r   r(   r(   J   sH    I2*((5T+5Z1) *6 *::r   r(   c                 r   SnU R                   R                  (       a  SnO;U R                   R                  (       a  SnOU R                   R                  (       a  SnU R                   R                  (       a  [
        OSnU(       a  U(       a  SR                  X#S9$ U(       a  U$ U(       a  U$ [        U5      $ )z-Build a string with failureDetail if present. zApplication crashedzTest timed outzApp failed to installr   r   )r   crashedtimedOutnotInstalledr   ry   r`   r   )r   r   rk   crashs       r   r   r     s    '""#G%%G))%G"00AA-r%11NL	'(<	==r   c                     U R                   (       aU  U R                   R                  (       a  gU R                   R                  (       a   gU R                   R                  (       a  gg)z-Build a string with skippedDetail if present.z"Incompatible device/OS combinationzGApp architecture or requested options are incompatible with this devicez#App does not support the OS versionUnknown reason)skippedDetailincompatibleDeviceincompatibleArchitectureincompatibleAppVersionr   s    r   r   r     sM    //155 332	r   c                     U R                   (       a=  U R                   R                  (       a  [        $ U R                   R                  (       a  gg)z2Build a string with inconclusiveDetail if present.zTest run aborted by userr   )inconclusiveDetailinfrastructureFailurer{   abortedByUserr   s    r   r   r     s5    !!77$$!!//'	r   c                     SnSnU  H1  nXR                   =(       d    S-  nX#R                  =(       d    S-  nM3     X-
  nU(       a'  SR                  US9nU(       a  SR                  XRS9nU$ g)=Build a string with status count sums for testSuiteOverviews.r   z{p} test cases passed)p{m}, {s} skippedr   sz--)
totalCountskippedCountr`   )r   totalr;   overviewpassedrV   s         r   r   r     sy    
%'&h	  %A%E$$))G ' ?&
!
(
(6
(
2C%%%7cJ	r   c                 R   SnSnSnSnSnU  Hv  nXR                   =(       d    S-  nX&R                  =(       d    S-  nX6R                  =(       d    S-  nXFR                  =(       d    S-  nXVR                  =(       d    S-  nMx     U(       a  SR                  US9nX-
  U-
  U-
  U-
  nU(       a  U(       a  SR                  XuS9nU(       a  U(       d  SR                  US9nU(       a  SR                  XxS9nU(       a  S	R                  XrS
9nU(       a  SR                  XtS9nU$ g)r   r   z{f} test cases failed)fz{m}, {f} flaky)r   r   z{f} test cases flakyz{m}, {p} passed)r   r   z{m}, {e} errors)r   er   r   zTest failed to run)r   
errorCountfailureCountr   
flakyCountr`   )	r   r   rU   failedr;   r9   r   rV   r   s	            r   r   r     s,   
%
%&'
%&h	  %A%E	  %A%E
##(q(F$$))G	  %A%E ' 
!
(
(6
(
2C]V#g-5F##c#3cV"))E)2c$$s$5c$$s$4c%%%7cJr   )"r   
__future__r   r   r   collectionsapitools.base.pyr   rO   $googlecloudsdk.api_lib.firebase.testr   googlecloudsdk.calliopegooglecloudsdk.corer   ry   rz   r{   r|   
namedtupler
   r6   r:   r8   r>   r<   r$   r&   objectr(   r   r   r   r   r   r   r   r   <module>r      s    1 &  '  > 5 . #!J  3 + '	=DF	 	 b
Bb2b L
v vr	>*  r   