| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit tests for checkout.py.""" | 6 """Unit tests for checkout.py.""" |
| 7 | 7 |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| 11 import stat | 11 import stat |
| 12 import sys | 12 import sys |
| 13 import unittest | 13 import unittest |
| 14 | 14 |
| 15 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | 15 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 16 sys.path.append(os.path.join(ROOT_DIR, '..')) | 16 sys.path.append(os.path.join(ROOT_DIR, '..')) |
| 17 | 17 |
| 18 import checkout | 18 import checkout |
| 19 import pending_manager | 19 import patch |
| 20 from tests import fake_repos | 20 from tests import fake_repos |
| 21 | 21 |
| 22 | 22 |
| 23 # pass -v to enable it. | 23 # pass -v to enable it. |
| 24 DEBUGGING = False | 24 DEBUGGING = False |
| 25 | 25 |
| 26 GIT_PATCH = ( | 26 GIT_PATCH = ( |
| 27 """\ | 27 """\ |
| 28 diff --git a/tests/svn_utils_test_data/svn_utils_test.txt b/tests/svn_utils_test
_data/svn_utils_test.txt | 28 diff --git a/tests/svn_utils_test_data/svn_utils_test.txt b/tests/svn_utils_test
_data/svn_utils_test.txt |
| 29 index 0e4de76..8320059 100644 | 29 index 0e4de76..8320059 100644 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 co = checkout.SvnCheckout( | 114 co = checkout.SvnCheckout( |
| 115 ROOT_DIR, self.name, self.usr, self.pwd, self.svn_url) | 115 ROOT_DIR, self.name, self.usr, self.pwd, self.svn_url) |
| 116 self.assertEquals(self.root_dir, co.project_path) | 116 self.assertEquals(self.root_dir, co.project_path) |
| 117 revision = co.prepare() | 117 revision = co.prepare() |
| 118 self.assertTrue(isinstance(revision, int)) | 118 self.assertTrue(isinstance(revision, int)) |
| 119 self.assertEquals(2, revision) | 119 self.assertEquals(2, revision) |
| 120 self.assertEquals('pouet', co.get_settings('bar')) | 120 self.assertEquals('pouet', co.get_settings('bar')) |
| 121 svn_utils_test_path = os.path.join(self.root_dir, 'svn_utils_test.txt') | 121 svn_utils_test_path = os.path.join(self.root_dir, 'svn_utils_test.txt') |
| 122 content = read(svn_utils_test_path) | 122 content = read(svn_utils_test_path) |
| 123 self.assertTrue(svn_utils_test_path) | 123 self.assertTrue(svn_utils_test_path) |
| 124 co.apply_patch(pending_manager.auto_mangle_git_patch(GIT_PATCH)) | 124 co.apply_patch(patch.auto_mangle_git_patch(GIT_PATCH)) |
| 125 content_lines = content.splitlines(True) | 125 content_lines = content.splitlines(True) |
| 126 content_modified = ''.join( | 126 content_modified = ''.join( |
| 127 content_lines[0:5] + ['FOO!\n'] + content_lines[5:]) | 127 content_lines[0:5] + ['FOO!\n'] + content_lines[5:]) |
| 128 self.assertEquals( | 128 self.assertEquals( |
| 129 content_modified, | 129 content_modified, |
| 130 read(svn_utils_test_path)) | 130 read(svn_utils_test_path)) |
| 131 hook_path = os.path.join( | 131 hook_path = os.path.join( |
| 132 self.FAKE_REPOS.repos_dir, 'svn', 'hooks', 'pre-revprop-change') | 132 self.FAKE_REPOS.repos_dir, 'svn', 'hooks', 'pre-revprop-change') |
| 133 write(hook_path, '#!/bin/sh\ntrue\n') | 133 write(hook_path, '#!/bin/sh\ntrue\n') |
| 134 os.chmod( | 134 os.chmod( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 149 checkout.SvnCheckout(ROOT_DIR, self.name, None, None, self.svn_url)) | 149 checkout.SvnCheckout(ROOT_DIR, self.name, None, None, self.svn_url)) |
| 150 self.assertEquals(self.root_dir, co.project_path) | 150 self.assertEquals(self.root_dir, co.project_path) |
| 151 revision = co.prepare() | 151 revision = co.prepare() |
| 152 self.assertTrue(isinstance(revision, int)) | 152 self.assertTrue(isinstance(revision, int)) |
| 153 # TODO: Need to fix other test side effects. | 153 # TODO: Need to fix other test side effects. |
| 154 self.assertTrue(2 <= revision <= 4) | 154 self.assertTrue(2 <= revision <= 4) |
| 155 self.assertEquals('pouet', co.get_settings('bar')) | 155 self.assertEquals('pouet', co.get_settings('bar')) |
| 156 svn_utils_test_path = os.path.join(self.root_dir, 'svn_utils_test.txt') | 156 svn_utils_test_path = os.path.join(self.root_dir, 'svn_utils_test.txt') |
| 157 content = read(svn_utils_test_path) | 157 content = read(svn_utils_test_path) |
| 158 self.assertTrue(svn_utils_test_path) | 158 self.assertTrue(svn_utils_test_path) |
| 159 co.apply_patch(pending_manager.auto_mangle_git_patch(GIT_PATCH)) | 159 co.apply_patch(patch.auto_mangle_git_patch(GIT_PATCH)) |
| 160 content_lines = content.splitlines(True) | 160 content_lines = content.splitlines(True) |
| 161 content_modified = ''.join(content_lines[0:5] + ['FOO!\n'] + | 161 content_modified = ''.join(content_lines[0:5] + ['FOO!\n'] + |
| 162 content_lines[5:]) | 162 content_lines[5:]) |
| 163 self.assertEquals(content_modified, read(svn_utils_test_path)) | 163 self.assertEquals(content_modified, read(svn_utils_test_path)) |
| 164 self.assertEquals('FAKE', co.commit('msg', 'usr')) | 164 self.assertEquals('FAKE', co.commit('msg', 'usr')) |
| 165 revision = co.prepare() | 165 revision = co.prepare() |
| 166 self.assertEquals(content, read(svn_utils_test_path)) | 166 self.assertEquals(content, read(svn_utils_test_path)) |
| 167 | 167 |
| 168 | 168 |
| 169 class GitSvnCheckout(BaseTest): | 169 class GitSvnCheckout(BaseTest): |
| (...skipping 10 matching lines...) Expand all Loading... |
| 180 self.name, self.usr, | 180 self.name, self.usr, |
| 181 self.svn_base, self.svn_trunk) | 181 self.svn_base, self.svn_trunk) |
| 182 co = checkout.ReadOnlyCheckout(rw_co) | 182 co = checkout.ReadOnlyCheckout(rw_co) |
| 183 self.assertEquals(self.root_dir, co.project_path) | 183 self.assertEquals(self.root_dir, co.project_path) |
| 184 revision = co.prepare() | 184 revision = co.prepare() |
| 185 self.assertTrue(isinstance(revision, int)) | 185 self.assertTrue(isinstance(revision, int)) |
| 186 self.assertEquals(2, revision) | 186 self.assertEquals(2, revision) |
| 187 self.assertEquals('pouet', co.get_settings('bar')) | 187 self.assertEquals('pouet', co.get_settings('bar')) |
| 188 content = read(os.path.join(self.root_dir, 'svn_utils_test.txt')) | 188 content = read(os.path.join(self.root_dir, 'svn_utils_test.txt')) |
| 189 self.assertTrue(os.path.join(self.root_dir, 'svn_utils_test.txt')) | 189 self.assertTrue(os.path.join(self.root_dir, 'svn_utils_test.txt')) |
| 190 co.apply_patch(pending_manager.auto_mangle_git_patch(GIT_PATCH)) | 190 co.apply_patch(patch.auto_mangle_git_patch(GIT_PATCH)) |
| 191 content_lines = content.splitlines(True) | 191 content_lines = content.splitlines(True) |
| 192 content_modified = ''.join(content_lines[0:5] + ['FOO!\n'] + | 192 content_modified = ''.join(content_lines[0:5] + ['FOO!\n'] + |
| 193 content_lines[5:]) | 193 content_lines[5:]) |
| 194 self.assertEquals(content_modified, | 194 self.assertEquals(content_modified, |
| 195 read(os.path.join(self.root_dir, 'svn_utils_test.txt'))) | 195 read(os.path.join(self.root_dir, 'svn_utils_test.txt'))) |
| 196 self.assertEquals('FAKE', co.commit('msg', 'usr')) | 196 self.assertEquals('FAKE', co.commit('msg', 'usr')) |
| 197 revision = co.prepare() | 197 revision = co.prepare() |
| 198 self.assertEquals(content, | 198 self.assertEquals(content, |
| 199 read(os.path.join(self.root_dir, 'svn_utils_test.txt'))) | 199 read(os.path.join(self.root_dir, 'svn_utils_test.txt'))) |
| 200 | 200 |
| 201 | 201 |
| 202 | 202 |
| 203 | 203 |
| 204 if __name__ == '__main__': | 204 if __name__ == '__main__': |
| 205 if '-v' in sys.argv: | 205 if '-v' in sys.argv: |
| 206 DEBUGGING = True | 206 DEBUGGING = True |
| 207 logging.basicConfig(level=logging.INFO) | 207 logging.basicConfig(level=logging.INFO) |
| 208 else: | 208 else: |
| 209 logging.basicConfig(level=logging.ERROR) | 209 logging.basicConfig(level=logging.ERROR) |
| 210 unittest.main() | 210 unittest.main() |
| OLD | NEW |