import os _bzr_plugin_path = os.environ.get('BZR_PLUGIN_PATH') from bzrlib.tests import TestCaseInTempDir from bzrlib.plugins.bzrp4 import p4_fast_export from bzrlib.plugins.bzrp4.tests.p4_for_test import P4ForTest import os.path import re from cStringIO import StringIO import sys class TestP4FastExport(TestCaseInTempDir): # TODO: Eliminate duplicated code that appears here, in test_git_p4 and # in test_dogfood. def __init__(self, method_name): TestCaseInTempDir.__init__(self, method_name) def setUp(self): TestCaseInTempDir.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.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 = 'TestP4FastExport' self.p4fortest.create_client( self.p4client_name, self.p4_client_workdir) self.p4fortest.p4.connect() self.p4fortest.sync() def tearDown(self): self.p4fortest.p4.disconnect() self.p4fortest.destroy_client() TestCaseInTempDir.tearDown(self) def test_p4_fast_export__export_add(self): self.p4fortest.add_file('file_1', 'file_1 contents\n') self.p4fortest.submit('gitify_add change 1') os.environ['P4PORT'] = self.p4fortest.p4.port if _bzr_plugin_path: os.environ['BZR_PLUGIN_PATH'] = _bzr_plugin_path p4_fast_export_stdout = StringIO() orig_stdout = sys.stdout try: sys.stdout = p4_fast_export_stdout p4_fast_export.main(['//depot@all']) finally: sys.stdout = orig_stdout actual_fast_export_data = p4_fast_export_stdout.getvalue() self.assertFastExportRevision( '1', self.p4fortest.get_user(), 'gitify_add change 1', None, 'file_1 contents', actual_fast_export_data) def test_export_two_revisions(self): self.p4fortest.add_file('file_1', 'file_1 contents\n') self.p4fortest.submit('change 1 description') self.p4fortest.add_file('file_2', 'file_2 contents\n') self.p4fortest.submit('change 2 description') os.environ['P4PORT'] = self.p4fortest.p4.port if _bzr_plugin_path: os.environ['BZR_PLUGIN_PATH'] = _bzr_plugin_path p4_fast_export_stdout = StringIO() orig_stdout = sys.stdout try: sys.stdout = p4_fast_export_stdout p4_fast_export.main(['//depot@all']) finally: sys.stdout = orig_stdout pattern = re.compile('(^commit .*\n)', re.MULTILINE) actual_revisions = pattern.split(p4_fast_export_stdout.getvalue()) self.assertFastExportRevision( '1', self.p4fortest.get_user(), 'change 1 description', None, 'file_1 contents', actual_revisions[2]) self.assertFastExportRevision( '2', self.p4fortest.get_user(), 'change 2 description', '1', 'file_2 contents', actual_revisions[4]) def assertFastExportRevision( self, mark, committer, #timestamp, comment, parent_mark, contents, actual_fast_export_data): self.assertUnixLine(self._committer_line(actual_fast_export_data)) self.assertContains(actual_fast_export_data, 'mark :%s' % mark) # TODO: Verify the structure and order in addition to the content. self.assertContains(actual_fast_export_data, committer) # TODO: self.assertContains(actual_fast_export_data, timestamp) self.assertContains(actual_fast_export_data, comment) if (None != parent_mark): self.assertContains( actual_fast_export_data, 'from :%s' % parent_mark) self.assertContains(actual_fast_export_data, contents) def assertUnixLine(self, line): self.assertEqual('\n', line[-1]) try: self.assertNotEqual('\r', line[-2]) except IndexError: pass def _committer_line(self, fast_export_data): """Returns the first committer line in fast_export_data.""" keepends = True for line in fast_export_data.splitlines(keepends): if line.startswith('committer '): return line return '' # TODO: Contribute this back to Bazaar proper, or find and use its # equivalent from Bazaar. I only found assertContainsRe(). def assertContains(self, haystack, needle): if -1 == haystack.find(needle): if '\n' in haystack or len(haystack) > 60: # a long string, format it in a more readable way raise AssertionError( 'pattern "%s" not found in\n"""\n%s"""\n' % (needle, haystack)) else: raise AssertionError('substring "%s" not found in "%s"' % (needle, haystack))
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#21 | 7400 | Matt McClure |
p4-fast-export emits `from` fast-import commands. Flush the output stream before exiting. Fixes a bug I observed where the output stream ended prematurely when called from `bzr fast-export-from-p4`. |
||
#20 | 7356 | Matt McClure | Uses rsh P4PORT so that there's no need to explicitly start and stop a p4d server for the tests. | ||
#19 | 7119 | Matt McClure | Improves the test coverage reporting by importing python modules rather than forking processes. | ||
#18 | 7106 | Matt McClure | Fixes test failure in case bzrp4 is installed without BZR_PLUGIN_PATH. | ||
#17 | 7101 | Matt McClure | Emits mark commands in the fast export stream. | ||
#16 | 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 |
||
#15 | 7087 | Matt McClure |
Changes the format of the change description addendum appended by p4-fast-export. Reverts the addendum appended by git-p4 to its original form. bzr: revno 88.2.20, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-12-21 15:47:50 -0500 |
||
#14 | 7076 | Matt McClure |
Merges upstream changes. bzr: revno 88.2.9, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Wed 2008-12-10 23:18:43 -0500 |
||
#13 | 7068 | Matt McClure |
Removes Bazaar metadata from Perforce commit descriptions. bzr: revno 88.2.1, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Mon 2008-12-01 18:26:45 -0500 |
||
#12 | 7061 | Matt McClure |
Set BZR_PLUGIN_PATH for the child process. bzr: revno 88.1.1, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Wed 2008-12-10 22:30:15 -0500 |
||
#11 | 7056 | Matt McClure |
Adds a test that verifies that p4-fast-export produces fast-export commands with UNIX line endings. bzr: revno 86.1.2, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Mon 2008-12-01 17:01:56 -0500 |
||
#10 | 7052 | Matt McClure |
Adds a comment about a failure I see when I upgrade Bazaar to >= revno 3841. bzr: revno 84.1.2, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Fri 2008-11-28 21:44:11 -0500 |
||
#9 | 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 |
||
#8 | 7034 | Matt McClure |
Adds a brief user guide. bzr: revno 77.1.1, part 1 of 3 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Fri 2008-11-14 09:58:48 -0500 |
||
#7 | 7027 | Matt McClure |
Generalizes the Perforce user in TestP4FastExport. bzr: revno 69.2.22, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Fri 2008-11-14 01:42:20 -0500 |
||
#6 | 7024 | Matt McClure |
Captures more information about the cause of failure so that I can figure out how to generalize the committer. bzr: revno 69.2.21, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Fri 2008-11-14 01:12:56 -0500 |
||
#5 | 7023 | Matt McClure |
Exercises p4-fast-export and verifies the contents of the exported stream. bzr: revno 69.2.20, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Fri 2008-11-14 00:49:21 -0500 |
||
#4 | 7022 | Matt McClure |
Adds an "export" command to git_p4. bzr: revno 69.2.19, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-11-09 13:22:00 -0500 |
||
#3 | 7020 | Matt McClure |
Reverts to previous revision. bzr: revno 69.2.17, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-11-09 07:58:17 -0500 |
||
#2 | 7019 | Matt McClure |
Emits export stream on stdout by hacking up P4Clone. Consider implementing a "P4Export". bzr: revno 69.2.16, part 1 of 1 bzr: author Matt McClure <mlm@aya.yale.edu> bzr: committed Sun 2008-11-09 07:43:54 -0500 |
||
#1 | 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 |