# test_mailmap.py -- Tests for dulwich.mailmap # Copyright (C) 2018 Jelmer Vernooij # # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later # Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU # General Public License as public by the Free Software Foundation; version 2.0 # or (at your option) any later version. You can redistribute it and/or # modify it under the terms of either of these two licenses. # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # You should have received a copy of the licenses; if not, see # for a copy of the GNU General Public License # and for a copy of the Apache # License, Version 2.0. # """Tests for dulwich.mailmap.""" from io import BytesIO from unittest import TestCase from dulwich.mailmap import Mailmap, read_mailmap class ReadMailmapTests(TestCase): def test_read(self) -> None: b = BytesIO( b"""\ Jane Doe Joe R. Developer # A comment # Comment Some Dude nick1 Other Author nick2 Other Author Santa Claus """ ) self.assertEqual( [ ((b"Jane Doe", b"jane@desktop.(none)"), None), ((b"Joe R. Developer", b"joe@example.com"), None), ((None, b"cto@company.xx"), (None, b"cto@coompany.xx")), ( (b"Some Dude", b"some@dude.xx"), (b"nick1", b"bugs@company.xx"), ), ( (b"Other Author", b"other@author.xx"), (b"nick2", b"bugs@company.xx"), ), ( (b"Other Author", b"other@author.xx"), (None, b"nick2@company.xx"), ), ( (b"Santa Claus", b"santa.claus@northpole.xx"), (None, b"me@company.xx"), ), ], list(read_mailmap(b)), ) class MailmapTests(TestCase): def test_lookup(self) -> None: m = Mailmap() m.add_entry((b"Jane Doe", b"jane@desktop.(none)"), (None, None)) m.add_entry((b"Joe R. Developer", b"joe@example.com"), None) m.add_entry((None, b"cto@company.xx"), (None, b"cto@coompany.xx")) m.add_entry((b"Some Dude", b"some@dude.xx"), (b"nick1", b"bugs@company.xx")) m.add_entry( (b"Other Author", b"other@author.xx"), (b"nick2", b"bugs@company.xx"), ) m.add_entry((b"Other Author", b"other@author.xx"), (None, b"nick2@company.xx")) m.add_entry( (b"Santa Claus", b"santa.claus@northpole.xx"), (None, b"me@company.xx"), ) self.assertEqual( b"Jane Doe ", m.lookup(b"Jane Doe "), ) self.assertEqual( b"Jane Doe ", m.lookup(b"Jane Doe "), ) self.assertEqual( b"Jane Doe ", m.lookup(b"Jane D. "), ) self.assertEqual( b"Some Dude ", m.lookup(b"nick1 ") ) self.assertEqual(b"CTO ", m.lookup(b"CTO "))