32
32
import attr
33
33
import subprocess
34
34
import json
35
+ import sys
35
36
36
37
from absl import app
37
38
from absl import flags
38
39
from absl import logging
39
40
41
+ sys .path .append (os .path .dirname (os .path .realpath (__file__ )))
40
42
from integration_testing import test_validation
41
43
from integration_testing import gcs
42
44
@@ -59,18 +61,7 @@ def main(argv):
59
61
test_result = json .loads (FLAGS .test_result )
60
62
tests = []
61
63
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 ))
74
65
75
66
(output_dir , file_name ) = os .path .split (os .path .abspath (FLAGS .output_path ))
76
67
return test_validation .summarize_test_results (
@@ -80,6 +71,22 @@ def main(argv):
80
71
file_name = file_name )
81
72
82
73
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
+
83
90
def _get_testapp_log_text_from_gcs (gcs_path ):
84
91
"""Gets the testapp log text generated by game loops."""
85
92
try :
@@ -130,6 +137,18 @@ def _gcs_read_file(gcs_path):
130
137
return result .stdout
131
138
132
139
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
+
133
152
if __name__ == '__main__' :
134
153
flags .mark_flag_as_required ("test_result" )
135
154
flags .mark_flag_as_required ("output_path" )
0 commit comments