Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: build/android/pylib/android_commands_unittest.py

Issue 276813002: Make it harder to leak temp files on devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/android_commands.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import shutil 6 import shutil
7 import sys 7 import sys
8 import unittest 8 import unittest
9 9
10 sys.path.append(os.path.join(os.pardir, os.path.dirname(__file__))) 10 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
11 11
12 from pylib import android_commands 12 from pylib import android_commands
13 13
14 # pylint: disable=W0212,W0702 14 # pylint: disable=W0212,W0702
15 15
16 class TestDeviceTempFile(unittest.TestCase):
17 def setUp(self):
18 if not os.getenv('BUILDTYPE'):
19 os.environ['BUILDTYPE'] = 'Debug'
20
21 devices = android_commands.GetAttachedDevices()
22 self.assertGreater(len(devices), 0, 'No device attached!')
23 self.ac = android_commands.AndroidCommands(device=devices[0])
24
25 def testTempFileDeleted(self):
26 """Tests that DeviceTempFile deletes files when closed."""
27 temp_file = android_commands.DeviceTempFile(self.ac)
28 self.assertFalse(self.ac.FileExistsOnDevice(temp_file.name))
29 self.ac.SetFileContents(temp_file.name, "contents")
30 self.assertTrue(self.ac.FileExistsOnDevice(temp_file.name))
31 temp_file.close()
32 self.assertFalse(self.ac.FileExistsOnDevice(temp_file.name))
33
34 with android_commands.DeviceTempFile(self.ac) as with_temp_file:
35 self.assertFalse(self.ac.FileExistsOnDevice(with_temp_file.name))
36 self.ac.SetFileContents(with_temp_file.name, "contents")
37 self.assertTrue(self.ac.FileExistsOnDevice(with_temp_file.name))
38
39 self.assertFalse(self.ac.FileExistsOnDevice(with_temp_file.name))
40
41 def testTempFileNotWritten(self):
42 """Tests that device temp files work successfully even if not written to."""
43 temp_file = android_commands.DeviceTempFile(self.ac)
44 temp_file.close()
45 self.assertFalse(self.ac.FileExistsOnDevice(temp_file.name))
46
47 with android_commands.DeviceTempFile(self.ac) as with_temp_file:
48 pass
49 self.assertFalse(self.ac.FileExistsOnDevice(with_temp_file.name))
50
51 def testNaming(self):
52 """Tests that returned filenames are as requested."""
53 temp_file = android_commands.DeviceTempFile(self.ac, prefix="cat")
54 self.assertTrue(os.path.basename(temp_file.name).startswith("cat"))
55
56 temp_file = android_commands.DeviceTempFile(self.ac, suffix="dog")
57 self.assertTrue(temp_file.name.endswith("dog"))
58
59 temp_file = android_commands.DeviceTempFile(
60 self.ac, prefix="cat", suffix="dog")
61 self.assertTrue(os.path.basename(temp_file.name).startswith("cat"))
62 self.assertTrue(temp_file.name.endswith("dog"))
63
64
16 class TestGetFilesChanged(unittest.TestCase): 65 class TestGetFilesChanged(unittest.TestCase):
17 66
18 def setUp(self): 67 def setUp(self):
19 if not os.getenv('BUILDTYPE'): 68 if not os.getenv('BUILDTYPE'):
20 os.environ['BUILDTYPE'] = 'Debug' 69 os.environ['BUILDTYPE'] = 'Debug'
21 70
22 devices = android_commands.GetAttachedDevices() 71 devices = android_commands.GetAttachedDevices()
23 self.assertGreater(len(devices), 0, 'No device attached!') 72 self.assertGreater(len(devices), 0, 'No device attached!')
24 self.ac = android_commands.AndroidCommands(device=devices[0]) 73 self.ac = android_commands.AndroidCommands(device=devices[0])
25 self.host_data_dir = os.path.realpath('test_push_data') 74 self.host_data_dir = os.path.realpath('test_push_data')
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 def tearDown(self): 182 def tearDown(self):
134 try: 183 try:
135 shutil.rmtree(self.host_data_dir) 184 shutil.rmtree(self.host_data_dir)
136 self.ac.RunShellCommand('rm -rf %s' % self.device_data_dir) 185 self.ac.RunShellCommand('rm -rf %s' % self.device_data_dir)
137 except: 186 except:
138 pass 187 pass
139 188
140 if __name__ == '__main__': 189 if __name__ == '__main__':
141 unittest.main() 190 unittest.main()
142 191
OLDNEW
« no previous file with comments | « build/android/pylib/android_commands.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698