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

Unified Diff: build/android/pylib/utils/device_temp_file_test.py

Issue 706203003: Update from https://crrev.com/303153 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/utils/device_temp_file.py ('k') | build/android/setup.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/utils/device_temp_file_test.py
diff --git a/build/android/pylib/utils/device_temp_file_test.py b/build/android/pylib/utils/device_temp_file_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..b0d23b12685fe04b7ada456307c6e6627f7727ea
--- /dev/null
+++ b/build/android/pylib/utils/device_temp_file_test.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Unit tests for the contents of device_temp_file.py.
+"""
+
+import logging
+import os
+import sys
+import unittest
+
+from pylib import constants
+from pylib.utils import device_temp_file
+
+sys.path.append(os.path.join(
+ constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
+import mock # pylint: disable=F0401
+
+class DeviceTempFileTest(unittest.TestCase):
+
+ def setUp(self):
+ self.device_utils = mock.MagicMock()
+
+ def testTempFileNameAlreadyExists(self):
+ self.device_utils.GetExternalStoragePath.return_value = '/sdcard'
+ self.device_utils.FileExists.side_effect = [True, True, True, False]
+
+ tmpfile = device_temp_file.DeviceTempFile(self.device_utils)
+ logging.debug('Temp file name: %s' % tmpfile.name)
+ self.assertEqual(self.device_utils.FileExists.call_count, 4)
+ self.device_utils.WriteFile.assert_called_with(tmpfile.name, '')
+
+ def testTempFileLifecycle(self):
+ self.device_utils.GetExternalStoragePath.return_value = '/sdcard'
+ self.device_utils.FileExists.return_value = False
+
+ with device_temp_file.DeviceTempFile(self.device_utils) as tmpfile:
+ filename = tmpfile.name
+ self.assertEqual(self.device_utils.WriteFile.call_count, 1)
+ self.assertNotEqual(self.device_utils.RunShellCommand.call_args,
+ mock.call(['rm', mock.ANY]))
+
+ self.assertEqual(self.device_utils.RunShellCommand.call_args,
+ mock.call(['rm', filename]))
+
+if __name__ == '__main__':
+ logging.getLogger().setLevel(logging.DEBUG)
+ unittest.main(verbosity=2)
« no previous file with comments | « build/android/pylib/utils/device_temp_file.py ('k') | build/android/setup.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698