| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 # Copyright (c) 2010 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 """Unit tests for svn_utils.py.""" | |
| 7 | |
| 8 import logging | |
| 9 import os | |
| 10 import shutil | |
| 11 import sys | |
| 12 import unittest | |
| 13 | |
| 14 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 15 sys.path.append(os.path.join(ROOT_DIR, '..')) | |
| 16 sys.path.append(os.path.join(ROOT_DIR, '..', '..', 'depot_tools')) | |
| 17 | |
| 18 import patch | |
| 19 import svn_utils | |
| 20 | |
| 21 PATCH = """\ | |
| 22 --- svn_utils_test.txt | |
| 23 +++ svn_utils_test.txt | |
| 24 @@ -3,6 +3,7 @@ bb | |
| 25 ccc | |
| 26 dd | |
| 27 e | |
| 28 +FOO! | |
| 29 ff | |
| 30 ggg | |
| 31 hh | |
| 32 """ | |
| 33 | |
| 34 def read(filename): | |
| 35 f = open(filename, 'rb') | |
| 36 content = f.read() | |
| 37 f.close() | |
| 38 return content | |
| 39 | |
| 40 | |
| 41 class SvnUtils(unittest.TestCase): | |
| 42 def setUp(self): | |
| 43 super(SvnUtils, self).setUp() | |
| 44 self.root_dir = os.path.join(ROOT_DIR, 'foo') | |
| 45 if os.path.exists(self.root_dir): | |
| 46 shutil.rmtree(self.root_dir) | |
| 47 | |
| 48 def tearDown(self): | |
| 49 super(SvnUtils, self).tearDown() | |
| 50 if os.path.exists(self.root_dir): | |
| 51 shutil.rmtree(self.root_dir) | |
| 52 | |
| 53 def testModification(self): | |
| 54 # A bit sad as it relies on the public server. | |
| 55 url = ('http://src.chromium.org/svn/trunk/tools/commit-queue/tests/' | |
| 56 'svn_utils_test_data') | |
| 57 svn_utils.revert(url, self.root_dir, None, None) | |
| 58 content = read(os.path.join(self.root_dir, 'svn_utils_test.txt')) | |
| 59 self.assertTrue(os.path.join(self.root_dir, 'svn_utils_test.txt')) | |
| 60 patch.apply_patch( | |
| 61 self.root_dir, patch.auto_mangle_git_patch(PATCH)) | |
| 62 content_lines = content.splitlines(True) | |
| 63 content_modified = ''.join(content_lines[0:5] + ['FOO!\n'] + | |
| 64 content_lines[5:]) | |
| 65 self.assertEquals(content_modified, | |
| 66 read(os.path.join(self.root_dir, 'svn_utils_test.txt'))) | |
| 67 svn_utils.revert(url, self.root_dir, None, None) | |
| 68 self.assertEquals(content, | |
| 69 read(os.path.join(self.root_dir, 'svn_utils_test.txt'))) | |
| 70 | |
| 71 | |
| 72 if __name__ == '__main__': | |
| 73 logging.basicConfig(level=logging.ERROR) | |
| 74 unittest.main() | |
| OLD | NEW |