def test_upper_case_email(self): mapping = Contributor.Mapping() mapping.create('Fujii Hironori', '*****@*****.**') self.assertEqual(mapping['*****@*****.**'].name, 'Fujii Hironori') self.assertEqual(mapping['*****@*****.**'].name, 'Fujii Hironori')
def test_number(self): with OutputCapture() as captured, mocks.local.Git( self.path) as mock, mocks.local.Svn(), MockTime: contirbutors = Contributor.Mapping() contirbutors.create('Jonathan Bedard', '*****@*****.**') self.assertEqual( 0, program.main( args=('canonicalize', '--number', '3'), path=self.path, contributors=contirbutors, )) self.assertEqual( local.Git(self.path).commit(identifier='5@main').message, 'Patch Series\nIdentifier: 5@main') self.assertEqual( local.Git(self.path).commit(identifier='4@main').message, '8th commit\nIdentifier: 4@main') self.assertEqual( local.Git(self.path).commit(identifier='3@main').message, '4th commit\nIdentifier: 3@main') self.assertEqual( captured.stdout.getvalue(), 'Rewrite 1abe25b443e985f93b90d830e4a7e3731336af4d (1/3) (--- seconds passed, remaining --- predicted)\n' 'Rewrite bae5d1e90999d4f916a8a15810ccfa43f37a2fd6 (2/3) (--- seconds passed, remaining --- predicted)\n' 'Rewrite d8bce26fa65c6fc8f39c17927abb77f69fab82fc (3/3) (--- seconds passed, remaining --- predicted)\n' '3 commits successfully canonicalized!\n', )
def __init__(self, dev_branches=None, prod_branches=None, contributors=None): self.dev_branches = dev_branches or self.DEV_BRANCHES self.prod_branches = prod_branches or self.PROD_BRANCHES self.path = None self.contributors = Contributor.Mapping( ) if contributors is None else contributors
def __init__(self, dev_branches=None, prod_branches=None, contributors=None, id=None): self.dev_branches = dev_branches or self.DEV_BRANCHES self.prod_branches = prod_branches or self.PROD_BRANCHES self.path = None self.contributors = Contributor.Mapping() if contributors is None else contributors if id and not isinstance(id, six.string_types): raise ValueError("Expected 'id' to be a string type, not '{}'".format(type(id))) self.id = id
def test_branch_commits(self): with OutputCapture() as captured, mocks.local.Git( self.path) as mock, mocks.local.Svn(), MockTime: contirbutors = Contributor.Mapping() contirbutors.create('Jonathan Bedard', '*****@*****.**') local.Git(self.path).checkout('branch-a') mock.commits['branch-a'].append( Commit( hash='f93138e3bf1d5ecca25fc0844b7a2a78b8e00aae', branch='branch-a', author=Contributor('*****@*****.**', emails=['*****@*****.**']), branch_point=mock.commits['branch-a'][-1].branch_point, identifier=mock.commits['branch-a'][-1].identifier + 1, timestamp=1601668000, message='New commit 1\n', )) mock.commits['branch-a'].append( Commit( hash='0148c0df0faf248aa133d6d5ad911d7cb1b56a5b', branch='branch-a', author=Contributor('*****@*****.**', emails=['*****@*****.**']), branch_point=mock.commits['branch-a'][-1].branch_point, identifier=mock.commits['branch-a'][-1].identifier + 1, timestamp=1601669000, message='New commit 2\n', )) self.assertEqual( 0, program.main( args=('canonicalize', ), path=self.path, contributors=contirbutors, )) commit_a = local.Git(self.path).commit(branch='branch-a~1') self.assertEqual(commit_a.author, contirbutors['*****@*****.**']) self.assertEqual(commit_a.message, 'New commit 1\nIdentifier: 2.3@branch-a') commit_b = local.Git(self.path).commit(branch='branch-a') self.assertEqual(commit_b.author, contirbutors['*****@*****.**']) self.assertEqual(commit_b.message, 'New commit 2\nIdentifier: 2.4@branch-a') self.assertEqual( captured.stdout.getvalue(), 'Rewrite f93138e3bf1d5ecca25fc0844b7a2a78b8e00aae (1/2) (--- seconds passed, remaining --- predicted)\n' 'Rewrite 0148c0df0faf248aa133d6d5ad911d7cb1b56a5b (2/2) (--- seconds passed, remaining --- predicted)\n' '2 commits successfully canonicalized!\n', )
def test_email_mapping(self): contributors = Contributor.Mapping() Contributor.from_scm_log('Author: Jonathan Bedard <*****@*****.**>', contributors) contributor = Contributor.from_scm_log( 'r266751 | [email protected] | 2020-09-08 14:33:42 -0700 (Tue, 08 Sep 2020) | 10 lines', contributors) self.assertEqual(contributor.name, 'Jonathan Bedard') self.assertEqual(contributor.emails, ['*****@*****.**'])
def test_author_mapping(self): contributors = Contributor.Mapping() Contributor.from_scm_log('Author: Jonathan Bedard <*****@*****.**>', contributors) contributor = Contributor.from_scm_log( 'Author: Jonathan Bedard <*****@*****.**>', contributors) self.assertEqual(contributor.name, 'Jonathan Bedard') self.assertEqual(contributor.emails, ['*****@*****.**', '*****@*****.**'])
def test_formated_identifier(self): with OutputCapture() as captured, mocks.local.Git( self.path) as mock, mocks.local.Svn(), MockTime: contirbutors = Contributor.Mapping() contirbutors.create('\u017dan Dober\u0161ek', '*****@*****.**') mock.commits[mock.default_branch].append( Commit( hash='38ea50d28ae394c9c8b80e13c3fb21f1c262871f', branch=mock.default_branch, author=Contributor('\u017dan Dober\u0161ek', emails=['*****@*****.**']), identifier=mock.commits[mock.default_branch][-1].identifier + 1, timestamp=1601668000, message='New commit\n', )) self.assertEqual( 0, program.main( args=( 'canonicalize', '-v', ), path=self.path, contributors=contirbutors, identifier_template= 'Canonical link: https://commits.webkit.org/{}', )) commit = local.Git(self.path).commit(branch=mock.default_branch) self.assertEqual(commit.author, contirbutors['*****@*****.**']) self.assertEqual( commit.message, 'New commit\nCanonical link: https://commits.webkit.org/5@main' ) self.assertEqual( captured.stdout.getvalue(), 'Rewrite 38ea50d28ae394c9c8b80e13c3fb21f1c262871f (1/1) (--- seconds passed, remaining --- predicted)\n' 'Overwriting 38ea50d28ae394c9c8b80e13c3fb21f1c262871f\n' '1 commit successfully canonicalized!\n', )
def test_git_svn(self): with OutputCapture() as captured, mocks.local.Git( self.path, git_svn=True) as mock, mocks.local.Svn(), MockTime: contirbutors = Contributor.Mapping() contirbutors.create('Jonathan Bedard', '*****@*****.**') mock.commits[mock.default_branch].append( Commit( hash='766609276fe201e7ce2c69994e113d979d2148ac', branch=mock.default_branch, author=Contributor('*****@*****.**', emails=['*****@*****.**']), identifier=mock.commits[mock.default_branch][-1].identifier + 1, timestamp=1601668000, revision=9, message='New commit\n', )) self.assertEqual( 0, program.main( args=('canonicalize', '-vv'), path=self.path, contributors=contirbutors, )) commit = local.Git(self.path).commit(branch=mock.default_branch) self.assertEqual(commit.author, contirbutors['*****@*****.**']) self.assertEqual( commit.message, 'New commit\n' 'Identifier: 5@main\n' 'svn-id: https://svn.example.org/repository/repository/trunk@9 268f45cc-cd09-0410-ab3c-d52691b4dbfc', ) self.assertEqual( captured.stdout.getvalue(), 'Rewrite 766609276fe201e7ce2c69994e113d979d2148ac (1/1) (--- seconds passed, remaining --- predicted)\n' 'Overwriting 766609276fe201e7ce2c69994e113d979d2148ac\n' ' GIT_AUTHOR_NAME=Jonathan Bedard\n' ' [email protected]\n' ' GIT_COMMITTER_NAME=Jonathan Bedard\n' ' [email protected]\n' '1 commit successfully canonicalized!\n', )
def test_saving(self): mapping_a = Contributor.Mapping() mapping_a.create('Jonathan Bedard', '*****@*****.**') mapping_a.create('Stephanie Lewis', '*****@*****.**') mapping_a['JonWBedard'] = mapping_a['*****@*****.**'] file = StringIO() mapping_a.save(file) file.seek(0) mapping_b = Contributor.Mapping.load(file) self.assertEqual(mapping_a['*****@*****.**'], mapping_b['*****@*****.**']) self.assertEqual(mapping_a['*****@*****.**'], mapping_b['JonWBedard']) self.assertEqual(mapping_a['*****@*****.**'], mapping_b['*****@*****.**'])
def test_existing_identifier(self): with OutputCapture() as captured, mocks.local.Git( self.path) as mock, mocks.local.Svn(), MockTime: contirbutors = Contributor.Mapping() contirbutors.create('Jonathan Bedard', '*****@*****.**') mock.commits[mock.default_branch].append( Commit( hash='38ea50d28ae394c9c8b80e13c3fb21f1c262871f', branch=mock.default_branch, author=Contributor('Jonathan Bedard', emails=['*****@*****.**']), identifier=mock.commits[mock.default_branch][-1].identifier + 1, timestamp=1601668000, message='New commit\nIdentifier: {}@{}'.format( mock.commits[mock.default_branch][-1].identifier + 1, mock.default_branch, ), )) self.assertEqual( 0, program.main( args=( 'canonicalize', '-v', ), path=self.path, contributors=contirbutors, )) commit = local.Git(self.path).commit(branch=mock.default_branch) self.assertEqual(commit.author, contirbutors['*****@*****.**']) self.assertEqual(commit.message, 'New commit\nIdentifier: 5@main') self.assertEqual( captured.stdout.getvalue(), 'Rewrite 38ea50d28ae394c9c8b80e13c3fb21f1c262871f (1/1) (--- seconds passed, remaining --- predicted)\n' 'Overwriting 38ea50d28ae394c9c8b80e13c3fb21f1c262871f\n' '1 commit successfully canonicalized!\n', )