3232import attr
3333import subprocess
3434import json
35+ import sys
3536
3637from absl import app
3738from absl import flags
3839from absl import logging
3940
41+ sys .path .append (os .path .dirname (os .path .realpath (__file__ )))
4042from integration_testing import test_validation
4143from integration_testing import gcs
4244
@@ -59,18 +61,7 @@ def main(argv):
5961 test_result = json .loads (FLAGS .test_result )
6062 tests = []
6163 for app in test_result .get ("apps" ):
62- app_path = app .get ("testapp_path" )
63- return_code = app .get ("return_code" )
64- logging .info ("testapp: %s\n return code: %s" % (app_path , return_code ))
65- if return_code == 0 :
66- gcs_dir = app .get ("raw_result_link" ).replace ("https://console.developers.google.com/storage/browser/" , "gs://" )
67- logging .info ("gcs_dir: %s" % gcs_dir )
68- logs = _get_testapp_log_text_from_gcs (gcs_dir )
69- logging .info ("Test result: %s" , logs )
70- tests .append (Test (testapp_path = app_path , logs = logs ))
71- else :
72- logging .error ("Test failed: %s" , app )
73- tests .append (Test (testapp_path = app_path , logs = None ))
64+ tests .append (_parse_testapp_to_test (app ))
7465
7566 (output_dir , file_name ) = os .path .split (os .path .abspath (FLAGS .output_path ))
7667 return test_validation .summarize_test_results (
@@ -80,6 +71,22 @@ def main(argv):
8071 file_name = file_name )
8172
8273
74+ def _parse_testapp_to_test (app ):
75+ """Parsed the given testapp run into a Test object."""
76+ app_path = app .get ("testapp_path" )
77+ return_code = app .get ("return_code" )
78+ logging .info ("testapp: %s\n return code: %s" % (app_path , return_code ))
79+ if return_code == 0 :
80+ gcs_dir = app .get ("raw_result_link" ).replace ("https://console.developers.google.com/storage/browser/" , "gs://" )
81+ logging .info ("gcs_dir: %s" % gcs_dir )
82+ logs = _get_testapp_log_text_from_gcs (gcs_dir )
83+ logging .info ("Test result: %s" , logs )
84+ return Test (testapp_path = app_path , logs = logs )
85+ else :
86+ logging .error ("Test failed: %s" , app )
87+ return Test (testapp_path = app_path , logs = None )
88+
89+
8390def _get_testapp_log_text_from_gcs (gcs_path ):
8491 """Gets the testapp log text generated by game loops."""
8592 try :
@@ -130,6 +137,18 @@ def _gcs_read_file(gcs_path):
130137 return result .stdout
131138
132139
140+
141+ def validate (test_summary ):
142+ """Validates a given test summary, assuming it is from a Unity testapp."""
143+ if not test_summary :
144+ logging .error ("Nothing to be validate! Please provide test_summary" )
145+ return False
146+
147+ test = _parse_testapp_to_test (test_summary )
148+ result = test_validation .validate_results (test .logs , "unity" )
149+ return result .complete and result .fails == 0
150+
151+
133152if __name__ == '__main__' :
134153 flags .mark_flag_as_required ("test_result" )
135154 flags .mark_flag_as_required ("output_path" )
0 commit comments