diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-20 19:51:24 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-20 19:51:24 +0000 |
commit | 9d8fe3b2085717e5889809255393f50d71a69365 (patch) | |
tree | e3eecb6dfd09cf0ab97e3876d6067516200381a0 /chrome/test/pyautolib/pyauto_utils_test.py | |
parent | f9d2de3e213d35a73eaece1bf73d3fdaa8ced209 (diff) | |
download | chromium_src-9d8fe3b2085717e5889809255393f50d71a69365.zip chromium_src-9d8fe3b2085717e5889809255393f50d71a69365.tar.gz chromium_src-9d8fe3b2085717e5889809255393f50d71a69365.tar.bz2 |
PyAuto test for renderer crash reporting
- Add a helper class (ExistingPathReplacer) to temporarily back up a path while pyauto uses it, and then reinstate it. Used by crash reporter test
- Increase PyAuto's default logging level to INFO
Review URL: http://codereview.chromium.org/3083028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56906 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib/pyauto_utils_test.py')
-rw-r--r-- | chrome/test/pyautolib/pyauto_utils_test.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/chrome/test/pyautolib/pyauto_utils_test.py b/chrome/test/pyautolib/pyauto_utils_test.py new file mode 100644 index 0000000..f612ba7 --- /dev/null +++ b/chrome/test/pyautolib/pyauto_utils_test.py @@ -0,0 +1,87 @@ +#!/usr/bin/python + +# Copyright (c) 2010 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. + +"""Tests for pyauto_utils.""" + +import glob +import os +import shutil +import tempfile +import unittest + +import pyauto_utils + + +class ExistingPathReplacerTest(unittest.TestCase): + """Tests for ExistingPathReplacer.""" + + def setUp(self): + self._workdir = tempfile.mkdtemp() + self.assertEqual(0, len(os.listdir(self._workdir))) + + def tearDown(self): + shutil.rmtree(self._workdir, ignore_errors=True) + + def _CreateFile(self, path): + fp = open(path, 'w') + fp.write('magic') + fp.close() + + def _IsOrigFile(self, path): + if not os.path.isfile(path): + return False + return open(path).read() == 'magic' + + def testNonExistingFile(self): + """Test when the requested file does not exist.""" + myfile = os.path.join(self._workdir, 'myfile.txt') + self.assertFalse(os.path.isfile(myfile)) + r = pyauto_utils.ExistingPathReplacer(myfile, path_type='file') + self.assertTrue(os.path.isfile(myfile)) + del r + self.assertEqual(0, len(os.listdir(self._workdir))) + + def testExistingFile(self): + """Test when the requested file exists.""" + myfile = os.path.join(self._workdir, 'myfile.txt') + self._CreateFile(myfile) + self.assertTrue(self._IsOrigFile(myfile)) + r = pyauto_utils.ExistingPathReplacer(myfile, path_type='file') + self.assertFalse(self._IsOrigFile(myfile)) + self.assertEqual(2, len(os.listdir(self._workdir))) + del r + self.assertEqual(1, len(os.listdir(self._workdir))) + self.assertTrue(self._IsOrigFile(myfile)) + + def testNonExistingDir(self): + """Test when the requested dir does not exist.""" + mydir = os.path.join(self._workdir, 'mydir') + self.assertFalse(os.path.isdir(mydir)) + r = pyauto_utils.ExistingPathReplacer(mydir, path_type='dir') + self.assertTrue(os.path.isdir(mydir)) + self.assertEqual(0, len(os.listdir(mydir))) + del r + self.assertFalse(os.path.isdir(mydir)) + + def testExistingDir(self): + """Test when the requested dir exists.""" + # Create a dir with one file + mydir = os.path.join(self._workdir, 'mydir') + os.makedirs(mydir) + self.assertEqual(1, len(os.listdir(self._workdir))) + myfile = os.path.join(mydir, 'myfile.txt') + open(myfile, 'w').close() + self.assertTrue(os.path.isfile(myfile)) + r = pyauto_utils.ExistingPathReplacer(mydir) + self.assertEqual(2, len(os.listdir(self._workdir))) + self.assertFalse(os.path.isfile(myfile)) + del r + self.assertEqual(1, len(os.listdir(self._workdir))) + self.assertTrue(os.path.isfile(myfile)) + + +if __name__ == '__main__': + unittest.main() |