2
0

test_mailmap.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # test_mailmap.py -- Tests for dulwich.mailmap
  2. # Copyright (C) 2018 Jelmer Vernooij <jelmer@jelmer.uk>
  3. #
  4. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  5. # Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
  6. # General Public License as public by the Free Software Foundation; version 2.0
  7. # or (at your option) any later version. You can redistribute it and/or
  8. # modify it under the terms of either of these two licenses.
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. # You should have received a copy of the licenses; if not, see
  17. # <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
  18. # and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
  19. # License, Version 2.0.
  20. #
  21. """Tests for dulwich.mailmap."""
  22. from io import BytesIO
  23. from unittest import TestCase
  24. from dulwich.mailmap import Mailmap, read_mailmap
  25. class ReadMailmapTests(TestCase):
  26. def test_read(self) -> None:
  27. b = BytesIO(
  28. b"""\
  29. Jane Doe <jane@desktop.(none)>
  30. Joe R. Developer <joe@example.com>
  31. # A comment
  32. <cto@company.xx> <cto@coompany.xx> # Comment
  33. Some Dude <some@dude.xx> nick1 <bugs@company.xx>
  34. Other Author <other@author.xx> nick2 <bugs@company.xx>
  35. Other Author <other@author.xx> <nick2@company.xx>
  36. Santa Claus <santa.claus@northpole.xx> <me@company.xx>
  37. """
  38. )
  39. self.assertEqual(
  40. [
  41. ((b"Jane Doe", b"jane@desktop.(none)"), None),
  42. ((b"Joe R. Developer", b"joe@example.com"), None),
  43. ((None, b"cto@company.xx"), (None, b"cto@coompany.xx")),
  44. (
  45. (b"Some Dude", b"some@dude.xx"),
  46. (b"nick1", b"bugs@company.xx"),
  47. ),
  48. (
  49. (b"Other Author", b"other@author.xx"),
  50. (b"nick2", b"bugs@company.xx"),
  51. ),
  52. (
  53. (b"Other Author", b"other@author.xx"),
  54. (None, b"nick2@company.xx"),
  55. ),
  56. (
  57. (b"Santa Claus", b"santa.claus@northpole.xx"),
  58. (None, b"me@company.xx"),
  59. ),
  60. ],
  61. list(read_mailmap(b)),
  62. )
  63. class MailmapTests(TestCase):
  64. def test_lookup(self) -> None:
  65. m = Mailmap()
  66. m.add_entry((b"Jane Doe", b"jane@desktop.(none)"), (None, None))
  67. m.add_entry((b"Joe R. Developer", b"joe@example.com"), None)
  68. m.add_entry((None, b"cto@company.xx"), (None, b"cto@coompany.xx"))
  69. m.add_entry((b"Some Dude", b"some@dude.xx"), (b"nick1", b"bugs@company.xx"))
  70. m.add_entry(
  71. (b"Other Author", b"other@author.xx"),
  72. (b"nick2", b"bugs@company.xx"),
  73. )
  74. m.add_entry((b"Other Author", b"other@author.xx"), (None, b"nick2@company.xx"))
  75. m.add_entry(
  76. (b"Santa Claus", b"santa.claus@northpole.xx"),
  77. (None, b"me@company.xx"),
  78. )
  79. self.assertEqual(
  80. b"Jane Doe <jane@desktop.(none)>",
  81. m.lookup(b"Jane Doe <jane@desktop.(none)>"),
  82. )
  83. self.assertEqual(
  84. b"Jane Doe <jane@desktop.(none)>",
  85. m.lookup(b"Jane Doe <jane@example.com>"),
  86. )
  87. self.assertEqual(
  88. b"Jane Doe <jane@desktop.(none)>",
  89. m.lookup(b"Jane D. <jane@desktop.(none)>"),
  90. )
  91. self.assertEqual(
  92. b"Some Dude <some@dude.xx>", m.lookup(b"nick1 <bugs@company.xx>")
  93. )
  94. self.assertEqual(b"CTO <cto@company.xx>", m.lookup(b"CTO <cto@coompany.xx>"))