1
+ # pylint: disable=unused-argument
2
+ # pylint: disable=undefined-variable
3
+
1
4
import json
2
5
import os
3
6
import unittest
9
12
from core .enums .platform_type import Platform
10
13
from core .settings import Settings
11
14
from core .utils .file_utils import Folder , File
12
- from core .utils .git import Git
13
15
from core .utils .gradle import Gradle
14
16
from core .utils .json_utils import JsonUtils
15
17
from core .utils .npm import Npm
19
21
from data .templates import Template
20
22
from products .nativescript .tns import Tns
21
23
22
- retry_count = 3
23
- tolerance = 0.20
24
- app_name = Settings .AppName .DEFAULT
25
- expected_results = JsonUtils .read (os .path .join (Settings .TEST_RUN_HOME , 'tests' , 'perf' , 'data.json' ))
24
+ RETRY_COUNT = 3
25
+ TOLERANCE = 0.20
26
+ APP_NAME = Settings .AppName .DEFAULT
27
+ EXPECTED_RESULTS = JsonUtils .read (os .path .join (Settings .TEST_RUN_HOME , 'tests' , 'perf' , 'data.json' ))
26
28
27
29
28
30
# noinspection PyMethodMayBeStatic,PyUnusedLocal
@@ -40,15 +42,6 @@ class PrepareAndBuildPerfTests(TnsTest):
40
42
def setUpClass (cls ):
41
43
TnsTest .setUpClass ()
42
44
43
- # Get master detail template locally.
44
- local_folder = os .path .join (Settings .TEST_SUT_HOME , Template .MASTER_DETAIL_NG .name )
45
- local_package = os .path .join (Settings .TEST_SUT_HOME , Template .MASTER_DETAIL_NG .name + '.tgz' )
46
- Folder .clean (local_folder )
47
- Git .clone (repo_url = Template .MASTER_DETAIL_NG .repo , local_folder = local_folder )
48
- Npm .pack (folder = local_folder , output_file = local_package )
49
- Folder .clean (local_folder )
50
- Template .MASTER_DETAIL_NG .local_package = local_package
51
-
52
45
def setUp (self ):
53
46
TnsTest .setUp (self )
54
47
@@ -69,66 +62,66 @@ def test_001_prepare_data(self, template, template_package, change_set, bundle):
69
62
def test_200_prepare_android_initial (self , template , template_package , change_set , bundle ):
70
63
actual = Helpers .get_actual_result (template , Platform .ANDROID , bundle , 'prepare_initial' )
71
64
expected = Helpers .get_expected_result (template , Platform .ANDROID , bundle , 'prepare_initial' )
72
- assert PerfUtils .is_value_in_range (actual , expected , tolerance ), 'Initial android prepare time is not OK.'
65
+ assert PerfUtils .is_value_in_range (actual , expected , TOLERANCE ), 'Initial android prepare time is not OK.'
73
66
74
67
@parameterized .expand (TEST_DATA )
75
68
@unittest .skipIf (Settings .HOST_OS is not OSType .OSX , 'iOS tests can be executed only on macOS.' )
76
69
def test_201_prepare_ios_initial (self , template , template_package , change_set , bundle ):
77
70
actual = Helpers .get_actual_result (template , Platform .iOS , bundle , 'prepare_initial' )
78
71
expected = Helpers .get_expected_result (template , Platform .iOS , bundle , 'prepare_initial' )
79
- assert PerfUtils .is_value_in_range (actual , expected , tolerance ), 'Initial ios prepare time is not OK.'
72
+ assert PerfUtils .is_value_in_range (actual , expected , TOLERANCE ), 'Initial ios prepare time is not OK.'
80
73
81
74
@parameterized .expand (TEST_DATA )
82
75
def test_210_prepare_android_skip (self , template , template_package , change_set , bundle ):
83
76
actual = Helpers .get_actual_result (template , Platform .ANDROID , bundle , 'prepare_skip' )
84
77
expected = Helpers .get_expected_result (template , Platform .ANDROID , bundle , 'prepare_skip' )
85
- assert PerfUtils .is_value_in_range (actual , expected , tolerance ), 'Skip android prepare time is not OK.'
78
+ assert PerfUtils .is_value_in_range (actual , expected , TOLERANCE ), 'Skip android prepare time is not OK.'
86
79
87
80
@parameterized .expand (TEST_DATA )
88
81
@unittest .skipIf (Settings .HOST_OS is not OSType .OSX , 'iOS tests can be executed only on macOS.' )
89
82
def test_211_prepare_ios_skip (self , template , template_package , change_set , bundle ):
90
83
actual = Helpers .get_actual_result (template , Platform .iOS , bundle , 'prepare_skip' )
91
84
expected = Helpers .get_expected_result (template , Platform .iOS , bundle , 'prepare_skip' )
92
- assert PerfUtils .is_value_in_range (actual , expected , tolerance ), 'Skip ios prepare time is not OK.'
85
+ assert PerfUtils .is_value_in_range (actual , expected , TOLERANCE ), 'Skip ios prepare time is not OK.'
93
86
94
87
@parameterized .expand (TEST_DATA )
95
88
def test_220_prepare_android_incremental (self , template , template_package , change_set , bundle ):
96
89
actual = Helpers .get_actual_result (template , Platform .ANDROID , bundle , 'prepare_incremental' )
97
90
expected = Helpers .get_expected_result (template , Platform .ANDROID , bundle , 'prepare_incremental' )
98
- assert PerfUtils .is_value_in_range (actual , expected , tolerance ), 'Incremental android prepare time is not OK.'
91
+ assert PerfUtils .is_value_in_range (actual , expected , TOLERANCE ), 'Incremental android prepare time is not OK.'
99
92
100
93
@parameterized .expand (TEST_DATA )
101
94
@unittest .skipIf (Settings .HOST_OS is not OSType .OSX , 'iOS tests can be executed only on macOS.' )
102
95
def test_221_prepare_ios_incremental (self , template , template_package , change_set , bundle ):
103
96
actual = Helpers .get_actual_result (template , Platform .iOS , bundle , 'prepare_incremental' )
104
97
expected = Helpers .get_expected_result (template , Platform .iOS , bundle , 'prepare_incremental' )
105
- assert PerfUtils .is_value_in_range (actual , expected , tolerance ), 'Incremental ios prepare time is not OK.'
98
+ assert PerfUtils .is_value_in_range (actual , expected , TOLERANCE ), 'Incremental ios prepare time is not OK.'
106
99
107
100
@parameterized .expand (TEST_DATA )
108
101
def test_300_build_android_initial (self , template , template_package , change_set , bundle ):
109
102
actual = Helpers .get_actual_result (template , Platform .ANDROID , bundle , 'build_initial' )
110
103
expected = Helpers .get_expected_result (template , Platform .ANDROID , bundle , 'build_initial' )
111
- assert PerfUtils .is_value_in_range (actual , expected , tolerance ), 'Initial android build time is not OK.'
104
+ assert PerfUtils .is_value_in_range (actual , expected , TOLERANCE ), 'Initial android build time is not OK.'
112
105
113
106
@parameterized .expand (TEST_DATA )
114
107
@unittest .skipIf (Settings .HOST_OS is not OSType .OSX , 'iOS tests can be executed only on macOS.' )
115
108
def test_301_build_ios_initial (self , template , template_package , change_set , bundle ):
116
109
actual = Helpers .get_actual_result (template , Platform .iOS , bundle , 'build_initial' )
117
110
expected = Helpers .get_expected_result (template , Platform .iOS , bundle , 'build_initial' )
118
- assert PerfUtils .is_value_in_range (actual , expected , tolerance ), 'Initial ios build time is not OK.'
111
+ assert PerfUtils .is_value_in_range (actual , expected , TOLERANCE ), 'Initial ios build time is not OK.'
119
112
120
113
@parameterized .expand (TEST_DATA )
121
114
def test_310_build_android_incremental (self , template , template_package , change_set , bundle ):
122
115
actual = Helpers .get_actual_result (template , Platform .ANDROID , bundle , 'build_incremental' )
123
116
expected = Helpers .get_expected_result (template , Platform .ANDROID , bundle , 'build_incremental' )
124
- assert PerfUtils .is_value_in_range (actual , expected , tolerance ), 'Incremental android build time is not OK.'
117
+ assert PerfUtils .is_value_in_range (actual , expected , TOLERANCE ), 'Incremental android build time is not OK.'
125
118
126
119
@parameterized .expand (TEST_DATA )
127
120
@unittest .skipIf (Settings .HOST_OS is not OSType .OSX , 'iOS tests can be executed only on macOS.' )
128
121
def test_311_build_ios_incremental (self , template , template_package , change_set , bundle ):
129
122
actual = Helpers .get_actual_result (template , Platform .iOS , bundle , 'build_incremental' )
130
123
expected = Helpers .get_expected_result (template , Platform .iOS , bundle , 'build_incremental' )
131
- assert PerfUtils .is_value_in_range (actual , expected , tolerance ), 'Incremental ios build time is not OK.'
124
+ assert PerfUtils .is_value_in_range (actual , expected , TOLERANCE ), 'Incremental ios build time is not OK.'
132
125
133
126
134
127
class PrepareBuildInfo (object ):
@@ -147,43 +140,43 @@ def prepare_and_build(template, platform, bundle, change_set, result_file):
147
140
prepare_incremental = 0
148
141
build_initial = 0
149
142
build_incremental = 0
150
- for i in range (retry_count ):
143
+ for _ in range (RETRY_COUNT ):
151
144
Tns .kill ()
152
145
Gradle .kill ()
153
146
Npm .cache_clean ()
154
147
Xcode .cache_clean ()
155
- Folder .clean (folder = os .path .join (Settings .TEST_RUN_HOME , app_name ))
156
- Tns .create (app_name = app_name , template = template , update = True )
148
+ Folder .clean (folder = os .path .join (Settings .TEST_RUN_HOME , APP_NAME ))
149
+ Tns .create (app_name = APP_NAME , template = template , update = True )
157
150
if platform == Platform .ANDROID :
158
- Tns .platform_add_android (app_name = app_name , framework_path = Settings .Android .FRAMEWORK_PATH )
151
+ Tns .platform_add_android (app_name = APP_NAME , framework_path = Settings .Android .FRAMEWORK_PATH )
159
152
elif platform == Platform .IOS :
160
- Tns .platform_add_ios (app_name = app_name , framework_path = Settings .IOS .FRAMEWORK_PATH )
153
+ Tns .platform_add_ios (app_name = APP_NAME , framework_path = Settings .IOS .FRAMEWORK_PATH )
161
154
else :
162
155
raise Exception ('Unknown platform: ' + str (platform ))
163
156
164
157
# Prepare
165
- time = Tns .prepare (app_name = app_name , platform = platform , bundle = bundle ).duration
158
+ time = Tns .prepare (app_name = APP_NAME , platform = platform , bundle = bundle ).duration
166
159
prepare_initial = prepare_initial + time
167
- time = Tns .prepare (app_name = app_name , platform = platform , bundle = bundle ).duration
160
+ time = Tns .prepare (app_name = APP_NAME , platform = platform , bundle = bundle ).duration
168
161
prepare_skip = prepare_skip + time
169
- Sync .replace (app_name = app_name , change_set = change_set )
170
- time = Tns .prepare (app_name = app_name , platform = platform , bundle = bundle ).duration
162
+ Sync .replace (app_name = APP_NAME , change_set = change_set )
163
+ time = Tns .prepare (app_name = APP_NAME , platform = platform , bundle = bundle ).duration
171
164
prepare_incremental = prepare_incremental + time
172
165
173
166
# Build
174
- time = Tns .build (app_name = app_name , platform = platform , bundle = bundle ).duration
167
+ time = Tns .build (app_name = APP_NAME , platform = platform , bundle = bundle ).duration
175
168
build_initial = build_initial + time
176
- Sync .revert (app_name = app_name , change_set = change_set )
177
- time = Tns .build (app_name = app_name , platform = platform , bundle = bundle ).duration
169
+ Sync .revert (app_name = APP_NAME , change_set = change_set )
170
+ time = Tns .build (app_name = APP_NAME , platform = platform , bundle = bundle ).duration
178
171
build_incremental = build_incremental + time
179
172
180
173
# Calculate averages
181
174
result = PrepareBuildInfo ()
182
- result .prepare_initial = prepare_initial / retry_count
183
- result .prepare_skip = prepare_skip / retry_count
184
- result .prepare_incremental = prepare_incremental / retry_count
185
- result .build_initial = build_initial / retry_count
186
- result .build_incremental = build_incremental / retry_count
175
+ result .prepare_initial = prepare_initial / RETRY_COUNT
176
+ result .prepare_skip = prepare_skip / RETRY_COUNT
177
+ result .prepare_incremental = prepare_incremental / RETRY_COUNT
178
+ result .build_initial = build_initial / RETRY_COUNT
179
+ result .build_incremental = build_incremental / RETRY_COUNT
187
180
188
181
# Save to results file
189
182
File .delete (path = result_file )
@@ -206,4 +199,4 @@ def get_actual_result(template, platform, bundle, entry):
206
199
def get_expected_result (template , platform , bundle , entry ):
207
200
if bundle :
208
201
platform = str (platform ) + '_bundle'
209
- return expected_results [template ][platform ][entry ]
202
+ return EXPECTED_RESULTS [template ][platform ][entry ]
0 commit comments