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

Unified Diff: prebuilt_unittest.py

Issue 6261013: Update prebuilt.py to handle files not existing. Add a unittest to test the case (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils@master
Patch Set: Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « prebuilt.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: prebuilt_unittest.py
diff --git a/prebuilt_unittest.py b/prebuilt_unittest.py
index 1e0f2ea385a2b7fa7dc38aea753dfb7940839b34..d3291333f083b4d4e50d9c82f07a64413d6a7b52 100755
--- a/prebuilt_unittest.py
+++ b/prebuilt_unittest.py
@@ -45,9 +45,12 @@ class TestUpdateFile(unittest.TestCase):
def tearDown(self):
os.remove(self.version_file)
- def _read_version_file(self):
+ def _read_version_file(self, version_file=None):
"""Read the contents of self.version_file and return as a list."""
- version_fh = open(self.version_file)
+ if not version_file:
+ version_file = self.version_file
+
+ version_fh = open(version_file)
try:
return [line.strip() for line in version_fh.readlines()]
finally:
@@ -86,6 +89,18 @@ class TestUpdateFile(unittest.TestCase):
prebuilt.UpdateLocalFile(self.version_file, new_val)
self._verify_key_pair(key, new_val)
+ def testUpdateNonExistentFile(self):
+ key = 'PORTAGE_BINHOST'
+ value = '1234567'
+ non_existent_file = tempfile.mktemp()
+ try:
+ prebuilt.UpdateLocalFile(non_existent_file, value)
+ file_contents = self._read_version_file(non_existent_file)
+ self.assertEqual(file_contents, ['%s=%s' % (key, value)])
+ finally:
+ if os.path.exists(non_existent_file):
+ os.remove(non_existent_file)
+
class TestPrebuiltFilters(unittest.TestCase):
« no previous file with comments | « prebuilt.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698