2
0

test_mailmap.py 3.7 KB

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