7
7
# R0201 - Method could be a function
8
8
# pylint: disable=C0103, C0111, R0201
9
9
10
- import psutil , subprocess , shutil , time , unittest
11
- from multiprocessing import Process
10
+ import shutil , time
12
11
13
12
from helpers ._os_lib import cleanup_folder , replace
14
13
from helpers ._tns_lib import IOS_RUNTIME_SYMLINK_PATH , \
17
16
from helpers .simulator import create_simulator , delete_simulator , \
18
17
cat_app_file_on_simulator , start_simulator , stop_simulators , \
19
18
SIMULATOR_NAME
19
+ from helpers .watch_base_class import WatchBaseClass
20
20
21
21
22
- class LiveSyncSimulator (unittest . TestCase ):
22
+ class LiveSyncSimulator (WatchBaseClass ):
23
23
24
24
SECONDS_TO_WAIT = 120
25
25
@@ -56,7 +56,7 @@ def setUpClass(cls):
56
56
# livesync
57
57
command = TNS_PATH + " livesync ios --emulator --watch --path TNS_App --log trace"
58
58
print command
59
- cls .process = subprocess . Popen (command , shell = True , stdout = subprocess . PIPE )
59
+ cls .start_watcher (command )
60
60
61
61
def setUp (self ):
62
62
@@ -73,62 +73,12 @@ def tearDown(self):
73
73
74
74
@classmethod
75
75
def tearDownClass (cls ):
76
- print "~~~ Killing subprocess ..."
77
- cls .process .terminate ()
78
-
79
- time .sleep (2 )
80
- if psutil .pid_exists (cls .process .pid ):
81
- print "~~~ Forced killing subprocess ..."
82
- cls .process .kill ()
83
-
76
+ cls .terminate_watcher ()
84
77
stop_simulators ()
78
+
85
79
cleanup_folder ('TNS_App' )
86
80
cleanup_folder ('appTest' )
87
81
88
- def wait_for_text_in_output (self , text ):
89
- def read_loop ():
90
- count = 0
91
- found = False
92
- print "~~~ Waiting for: " + text
93
-
94
- while not found :
95
- if count == 0 :
96
- line = self .process .stdout .readline ()
97
- if text in line :
98
- print " + Text \" {0}\" found in: " .format (text ) + line .rstrip (),
99
- print '\n '
100
- count = 1
101
- continue
102
- else :
103
- print (" - " + line ),
104
- if count == 1 :
105
- line = self .process .stdout .readline ()
106
- if text in line :
107
- print " + Text \" {0}\" found in: " .format (text ) + line .rstrip (),
108
- raise Exception ("The console.log() message duplicates." )
109
- else :
110
- found = True
111
- print (" - " + line ),
112
- break
113
-
114
- self .run_with_timeout (self .SECONDS_TO_WAIT , read_loop )
115
-
116
- def run_with_timeout (self , timeout , func ):
117
- if not timeout :
118
- func ()
119
- return
120
-
121
- p = Process (target = func )
122
- p .start ()
123
-
124
- start_time = time .time ()
125
- end_time = start_time + timeout
126
- while p .is_alive ():
127
- if time .time () > end_time :
128
- p .terminate ()
129
- raise Exception ("Timeout while waiting for livesync." )
130
- time .sleep (0.5 )
131
-
132
82
def test_001_full_livesync_ios_simulator_xml_js_css_tns_files (self ):
133
83
134
84
# TODO: Update with console.log() when supported on simulators ...
@@ -216,15 +166,9 @@ def test_113_livesync_ios_simulator_watch_change_css_file(self):
216
166
# assert "No such file or directory" in output
217
167
218
168
def test_301_livesync_ios_simulator_before_run (self ):
219
- print "~~~ Killing subprocess ..."
220
- self .process .terminate ()
221
-
222
- time .sleep (2 )
223
- if psutil .pid_exists (self .process .pid ):
224
- print "~~~ Forced killing subprocess ..."
225
- self .process .kill ()
226
-
169
+ self .terminate_watcher ()
227
170
cleanup_folder ('TNS_App' )
171
+
228
172
create_project (proj_name = "TNS_App" )
229
173
platform_add (platform = "ios" , framework_path = IOS_RUNTIME_SYMLINK_PATH , \
230
174
path = "TNS_App" , symlink = True )
0 commit comments