OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 | |
7 import subprocess as sub | |
8 import time | |
stanleyw
2011/10/10 21:21:15
Remove if you can find a way without using a sleep
deepakg
2011/10/12 22:37:22
Done.
| |
9 import re | |
dennis_jeffrey
2011/10/10 21:48:32
Move this up before "subprocess" so that the impor
deepakg
2011/10/12 22:37:22
Done.
| |
10 | |
11 import pyauto_functional | |
dennis_jeffrey
2011/10/10 21:48:32
Add a comment saying that this must occur before i
deepakg
2011/10/12 22:37:22
Done.
| |
12 import pyauto | |
13 | |
14 | |
15 class ChromeosGSMCompliance(pyauto.PyUITest): | |
16 """Tests for ChromeOS GSM compliance, by checking the name of the | |
17 connected network.""" | |
dennis_jeffrey
2011/10/10 21:48:32
Make this sentence fit on a single line, since the
deepakg
2011/10/12 22:37:22
Done.
| |
18 | |
19 ethernet = None | |
dennis_jeffrey
2011/10/10 21:48:32
Prefix this variable name with an underscore since
deepakg
2011/10/12 22:37:22
Done.
| |
20 | |
21 | |
dennis_jeffrey
2011/10/10 21:48:32
Remove one of these blank lines
deepakg
2011/10/12 22:37:22
Done.
| |
22 def _Ethernet(self): | |
dennis_jeffrey
2011/10/10 21:48:32
Recommend changing this function name to "_GetEthe
deepakg
2011/10/12 22:37:22
Done.
| |
23 """Get the ethernet connected to.""" | |
dennis_jeffrey
2011/10/10 21:48:32
'connected to' --> 'to which the device is connect
deepakg
2011/10/12 22:37:22
Done.
| |
24 process = sub.Popen('ifconfig | cut -d\' \' -f 1 | grep eth', | |
25 stdout=sub.PIPE, shell=True).communicate() | |
26 self.assertNotEqual(process[0], '', 'Not connected to Ethernet.') | |
dennis_jeffrey
2011/10/10 21:48:32
msg='Not connected to Ethernet.'
deepakg
2011/10/12 22:37:22
Done.
| |
27 self.ethernet = process[0].rstrip() | |
28 | |
29 def setUp(self): | |
30 pyauto.PyUITest.setUp(self) | |
31 sub.Popen(['sudo', 'stop', 'cromo']) | |
dennis_jeffrey
2011/10/10 21:48:32
Do we need to wait for this process to complete be
deepakg
2011/10/12 22:37:22
Using sub.call() instead of sub.Popen() to make su
| |
32 ethernet = self._Ethernet() | |
33 if self.ethernet: | |
34 sub.Popen(['sudo', '/bin/sh', '/usr/local/lib/flimflam/test/backchannel', | |
35 'setup', self.ethernet, 'pseudo-modem0']) | |
dennis_jeffrey
2011/10/10 21:48:32
Do we need to wait for this process to complete be
deepakg
2011/10/12 22:37:22
Done.
| |
36 else: | |
37 # if there is no eth check if we have pseudo-modem0 | |
dennis_jeffrey
2011/10/10 21:48:32
Capitalize the 'i' in 'if', and add a period at th
deepakg
2011/10/12 22:37:22
Done.
| |
38 process = sub.Popen('ifconfig | cut -d\' \' -f 1 | grep pseudo', | |
39 stdout=sub.PIPE, shell=True).communicate() | |
dennis_jeffrey
2011/10/10 21:48:32
indent this line by 2 more spaces
dennis_jeffrey
2011/10/10 21:48:32
Do we need to wait for this process to complete be
deepakg
2011/10/12 22:37:22
Done.
| |
40 self.assertNotEqual(process[0].rstrip(), 'pseudo-modem0', | |
41 'Could not setup a pseudo-modem') | |
dennis_jeffrey
2011/10/10 21:48:32
msg='Could not setup a pseudo-modem'
deepakg
2011/10/12 22:37:22
Done.
| |
42 | |
43 def tearDown(self): | |
44 pyauto.PyUITest.tearDown(self) | |
dennis_jeffrey
2011/10/10 21:48:32
nit: call PyUITest.tearDown as the last step in th
deepakg
2011/10/12 22:37:22
Done.
| |
45 if self.ethernet: | |
46 sub.Popen(['sudo', '/bin/sh', '/usr/local/lib/flimflam/test/backchannel', | |
47 'teardown', self.ethernet, 'pseudo-modem0']) | |
dennis_jeffrey
2011/10/10 21:48:32
Should we wait for this process to terminate befor
deepakg
2011/10/12 22:37:22
Done.
| |
48 | |
49 def _BasicCarrierCompliance(self, carrier_name, cellular_name): | |
dennis_jeffrey
2011/10/10 21:48:32
I recommend changing this function name to _Verify
deepakg
2011/10/12 22:37:22
Done.
| |
50 """Faking the specified carrier and checking the name. | |
51 | |
52 Args: | |
53 carrier_name: The name of the carrier. | |
54 cellular_name: The name in the icon of the cellular network. | |
55 """ | |
56 fake_gsm = sub.Popen(['sudo', '/usr/bin/python', | |
57 '/usr/local/lib/flimflam/test/fake-gsm-modem', | |
58 '-c', carrier_name]) | |
59 time.sleep(3) # fake-gsm-modem needs time | |
stanleyw
2011/10/10 21:21:15
What time is required? Can we do without the slee
dennis_jeffrey
2011/10/10 21:48:32
A blind sleep of hard-coded time is dangerous. Is
deepakg
2011/10/12 22:37:22
Done.
deepakg
2011/10/12 22:37:22
Done.
| |
60 ps = sub.Popen('ps -ef | grep fake-gsm-modem | grep -v grep', | |
61 shell=True, stdout=sub.PIPE) | |
dennis_jeffrey
2011/10/10 21:48:32
indent this line by 3 fewer spaces
deepakg
2011/10/12 22:37:22
Done.
| |
62 self.assertNotEqual(re.search('fake-gsm-modem', ps.stdout.read()), | |
63 None, 'fake-gsm is not running.') | |
dennis_jeffrey
2011/10/10 21:48:32
indent this line by 2 fewer spaces
dennis_jeffrey
2011/10/10 21:48:32
msg='fake-gsm is not running'
deepakg
2011/10/12 22:37:22
Done.
deepakg
2011/10/12 22:37:22
Done.
| |
64 network_info = self.NetworkScan()['cellular_networks'] | |
65 for key in network_info.keys(): | |
66 fake_gsm.terminate() | |
stanleyw
2011/10/10 21:21:15
From my understanding, there should only be one fa
deepakg
2011/10/12 22:37:22
Done.
| |
67 self.assertEqual(network_info[key]['name'], cellular_name, | |
68 'Did not successfully connect to cellular network %s.') | |
dennis_jeffrey
2011/10/10 21:48:32
msg='Did not...'
Also, you have a %s in the strin
deepakg
2011/10/12 22:37:22
Done.
| |
69 | |
70 def testConnectThree(self): | |
71 """Testing connection to Three.""" | |
72 self._BasicCarrierCompliance('three', '3') | |
73 | |
74 def testConnectSFR(self): | |
75 """Testing connection to SFR.""" | |
76 self._BasicCarrierCompliance('SFR', 'SFR') | |
77 | |
78 def testConnectKPN(self): | |
79 """Testing connection to KPN.""" | |
80 self._BasicCarrierCompliance('KPN', 'KPN NL') | |
81 | |
82 def testConnectSimyo(self): | |
83 """Testing connection to Simyo.""" | |
84 self._BasicCarrierCompliance('Simyo', 'E-Plus') | |
85 | |
86 def testConnectMovistar(self): | |
87 """Testing connection to Movistar.""" | |
88 self._BasicCarrierCompliance('Movistar', 'Movistar') | |
89 | |
90 def testConnectThreeita(self): | |
91 """Testing connection to threeita.""" | |
92 self._BasicCarrierCompliance('threeita', '3ITA') | |
93 | |
94 def testConnectAtt(self): | |
95 """Testing connection to att.""" | |
96 self._BasicCarrierCompliance('att', 'AT&T') | |
97 | |
98 def testConnectTmobile(self): | |
99 """Testing connection to Tmobile.""" | |
100 self._BasicCarrierCompliance('Tmobile', 'T-Mobile') | |
101 | |
102 | |
103 if __name__ == '__main__': | |
104 pyauto_functional.Main() | |
105 | |
dennis_jeffrey
2011/10/10 21:48:32
remove this blank line.
deepakg
2011/10/12 22:37:22
Done.
| |
OLD | NEW |