#! /usr/bin/env python from bzrlib.plugins.bzrp4 import bzr2p4 from bzrlib.plugins.bzrp4 import git_p4 from bzrlib.plugins.bzrp4.tests import TestCaseForTwoVcs from bzrlib.plugins.bzrp4.tests.p4_for_test import P4ForTest from cStringIO import StringIO import os import os.path import shutil import stat import subprocess import sys import tempfile import unittest class TestGitP4(TestCaseForTwoVcs): def __init__(self, method_name): TestCaseForTwoVcs.__init__(self, method_name) self.bzr_branch_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '..') def setUp(self): TestCaseForTwoVcs.setUp(self) self.p4fortest = P4ForTest() self.p4_compatible_cwd = os.getcwd() self.p4d_workdir = os.path.join(self.p4_compatible_cwd, 'p4d') os.mkdir(self.p4d_workdir) self.p4_client_workdir = os.path.join(self.p4_compatible_cwd, 'p4') os.mkdir(self.p4_client_workdir) self.git_workdir = os.path.join(self.p4_compatible_cwd, 'git') self.git_p4_stdout = StringIO() self.git_p4_stderr = StringIO() os.mkdir(self.git_workdir) self.p4fortest.p4.port = 'rsh:%s -r %s -L log -vserver=3 -i' % ('p4d', self.p4d_workdir) # TODO: Remove parameters, and add them to initialization of # p4fortest? self.p4client_name = 'TestGitP4' self.p4fortest.create_client( self.p4client_name, self.p4_client_workdir) def tearDown(self): self.p4fortest.destroy_client() TestCaseForTwoVcs.tearDown(self) def _git_p4(self, args): orig_dir = os.getcwdu() orig_stdout = sys.stdout orig_stderr = sys.stderr sys.stdout = self.git_p4_stdout sys.stderr = self.git_p4_stderr code = 0 try: os.chdir(self.git_workdir) code = git_p4.main(args) finally: sys.stdout = orig_stdout sys.stderr = orig_stderr os.chdir(orig_dir) return code def test_git_p4__gitify_add(self): try: self.p4fortest.p4.connect() self.p4fortest.sync() self.p4fortest.add_file('file_1', 'file_1 contents\n') self.p4fortest.submit('gitify_add change 1') # Runs git-p4. os.environ['P4PORT'] = self.p4fortest.p4.port self.assertEqual(0, self._git_p4(['clone', '//depot@all'])) self.assertDirectoriesEqualModIgnored( self.p4_client_workdir, os.path.join(self.git_workdir, 'depot'), [], ['.git']) finally: self.p4fortest.p4.disconnect() def test_git_p4__fails_on_no_args(self): self.assertEqual(2, self._git_p4([])) self.assertContainsRe(self.git_p4_stdout.getvalue(), 'usage: ') def test_git_p4__syncs_branch_from_p4(self): # Uses bzr2p4 to migrate this Bazaar branch to Perforce, so # that I have a fixture for this test. os.environ['P4CLIENT'] = self.p4client_name self.p4fortest.p4.client = self.p4client_name self.p4fortest.p4.connect() try: os.environ['P4PORT'] = self.p4fortest.p4.port bzr2p4.main(['-q', self.bzr_branch_path, self.p4_client_workdir]) # Uses git-p4 to migrate the Perforce depot to git, so that I # exercise git-p4. self.assertEqual(0, self._git_p4(['clone', '//depot@all'])) # Asserts that the Perforce depot and the git branch are the # same at every revision, so that I can verify git-p4 works. self.assertP4DepotAndGitRepositoryEqual() finally: self.p4fortest.p4.disconnect() def assertP4DepotAndGitRepositoryEqual(self): p4_change_iter = reversed(self.p4fortest.p4.run_changes()) for commit_line in self._git_iter_revisions(): commit = commit_line.rstrip('\n\r') self.assertP4AndGitRevisionEqual( p4_change_iter.next()['change'], commit) self.assertRaises(StopIteration, p4_change_iter.next) def _git_iter_revisions(self): proc = subprocess.Popen( ['git', 'rev-list', '--reverse', 'HEAD'], stdout=subprocess.PIPE, cwd=os.path.join(self.git_workdir, 'depot')) proc_stdout = proc.communicate()[0] revisions_text = proc_stdout.rstrip('\n') return revisions_text.split('\n') def assertP4AndGitRevisionEqual(self, p4_change, git_commit): self.p4fortest.p4.run_sync('...@' + p4_change) self._git_checkout(git_commit) self.assertDirectoriesEqualModIgnored( self.p4_client_workdir, os.path.join(self.git_workdir, 'depot'), ['.bzr2p4', '.bzr2p4.log', '.bzr2p4.revdb'], ['.git']) # TODO: Verify that change descriptions are the same in # Perforce and Git. def _git_checkout(self, commit): proc = subprocess.Popen( ['git', 'checkout', '-q', commit], cwd=os.path.join(self.git_workdir, 'depot')) proc.wait() if __name__ == '__main__': unittest.main()
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#28 | 7356 | Matt McClure | Uses rsh P4PORT so that there's no need to explicitly start and stop a p4d server for the tests. | ||
#27 | 7119 | Matt McClure | Improves the test coverage reporting by importing python modules rather than forking processes. | ||
#26 | 7092 | Matt McClure |
Converts all source files to UNIX line endings. bzr: revno 88.2.25, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sat 2008-12-27 14:36:39 -0500 |
||
#25 | 7071 | Matt McClure |
Quiets bzr2p4 in tests. bzr: revno 88.2.4, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Mon 2008-12-01 21:21:53 -0500 |
||
#24 | 7044 | Matt McClure |
Avoids deadlocks with former use of subprocess.Popen.wait(). bzr: revno 80, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sat 2008-11-15 14:35:47 -0500 |
||
#23 | 7043 | Matt McClure |
Merges changes from doc branch. bzr: revno 79, part 2 of 2 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sat 2008-11-15 12:35:42 -0500 |
||
#22 | 7038 | Matt McClure |
Adds a brief user guide. bzr: revno 77.1.1, part 3 of 3 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Fri 2008-11-14 09:58:48 -0500 |
||
#21 | 7031 | Matt McClure |
Removes an obsolete import. bzr: revno 69.2.26, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Fri 2008-11-14 19:05:36 -0500 |
||
#20 | 7017 | Matt McClure |
git_p4.main takes arguments instead of reading sys.argv directly. bzr: revno 69.2.14, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-11-09 07:05:28 -0500 |
||
#19 | 7015 | Matt McClure |
This is a better fix for git hanging than revision id mlm@aya.yale.edu-20081103023152-dw8al8aij4hsoac3 . bzr: revno 69.2.12, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sat 2008-11-08 23:07:10 -0500 |
||
#18 | 7012 | Matt McClure |
Reads git rev-list's output so that git will exit. bzr: revno 69.2.9, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-11-02 21:31:52 -0500 |
||
#17 | 7003 | Matt McClure |
Snapshot. bzr: revno 69.2.1, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-08-10 10:47:26 -0400 |
||
#16 | 7000 | Matt McClure |
Merges fix for hanging git dogfood test. bzr: revno 75, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-11-02 21:42:21 -0500 |
||
#15 | 6969 | Matt McClure |
Verifies that all revisions have the same data in the dogfood test that exercises git-p4. bzr: revno 69, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sat 2008-08-09 18:39:16 -0400 |
||
#14 | 6968 | Matt McClure |
This change is very much a work in progress. See the diff to remember what I was doing. bzr: revno 68, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sat 2008-08-09 11:59:00 -0400 |
||
#13 | 6967 | Matt McClure |
Adds a test that exercises git-p4 using this Bazaar branch as input. bzr: revno 67, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sat 2008-08-09 10:35:16 -0400 |
||
#12 | 6964 | Matt McClure |
I can run the tests from any working directory now. bzr: revno 64, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sat 2008-08-09 08:59:35 -0400 |
||
#11 | 6945 | Matt McClure |
Removes unused import. bzr: revno 46, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-07-20 09:47:02 -0400 |
||
#10 | 6944 | Matt McClure |
Refactors: removes method _get_p4. bzr: revno 45, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-07-20 09:45:11 -0400 |
||
#9 | 6943 | Matt McClure |
Mid-refactoring. Moves and renames methods. bzr: revno 44, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-07-20 09:24:54 -0400 |
||
#8 | 6942 | Matt McClure |
Mid-refactoring... bzr: revno 43, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-07-20 09:10:16 -0400 |
||
#7 | 6940 | Matt McClure |
Refactors: adds a parameters and renames assertDirectoriesEqualModIgnored(). The test_git_p4.py tests pass on Windows and Cygwin. The test_dogfood.py tests pass on Windows, but not on Cygwin yet. bzr: revno 41, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sat 2008-07-19 07:55:59 -0400 |
||
#6 | 6939 | Matt McClure |
Cleans up git-p4 tests a bit. Makes the test fail on unexpected warnings. bzr: revno 40, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Thu 2008-07-17 22:38:20 -0400 |
||
#5 | 6937 | Matt McClure |
Passes test_git_p4.py test with Cygwin P4Python. Needs major clean up. I wouldn't be surprised if I broke the test on native Windows. I should probably change the 'dir /S' to 'ls -R' to make sure the test is verifying what I think it is. I used a native Windows p4 command line client for my test. bzr: revno 38, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-07-13 20:07:59 -0400 |
||
#4 | 6936 | Matt McClure |
Extracts a base class from some of the copied common code in test_dogfood.py and test_git_p4.py. bzr: revno 37, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-07-13 14:33:20 -0400 |
||
#3 | 6934 | Matt McClure |
Verifies more strongly the results of git-p4. Compares the Perforce and Git directories. bzr: revno 35, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-07-13 14:19:19 -0400 |
||
#2 | 6933 | Matt McClure |
Adds a simple test, with weak verification, that exercises git-p4. bzr: revno 34, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-07-13 14:09:44 -0400 |
||
#1 | 6931 | Matt McClure |
Copies test_dogfood.py. bzr: revno 32, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sat 2008-07-12 14:22:28 -0400 |