Skip to content

Commit ed29ed3

Browse files
committed
Add tests for the mailmap APIs
1 parent 87fc09d commit ed29ed3

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

test/test_mailmap.py

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# -*- coding: UTF-8 -*-
2+
#
3+
# Copyright 2010-2017 The pygit2 contributors
4+
#
5+
# This file is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License, version 2,
7+
# as published by the Free Software Foundation.
8+
#
9+
# In addition to the permissions in the GNU General Public License,
10+
# the authors give you unlimited permission to link the compiled
11+
# version of this file into combinations with other programs,
12+
# and to distribute those combinations without any restriction
13+
# coming from the use of this file. (The General Public License
14+
# restrictions do apply in other respects; for example, they cover
15+
# modification of the file, and distribution when not linked into
16+
# a combined executable.)
17+
#
18+
# This file is distributed in the hope that it will be useful, but
19+
# WITHOUT ANY WARRANTY; without even the implied warranty of
20+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21+
# General Public License for more details.
22+
#
23+
# You should have received a copy of the GNU General Public License
24+
# along with this program; see the file COPYING. If not, write to
25+
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
26+
# Boston, MA 02110-1301, USA.
27+
28+
"""Tests for Mailmap."""
29+
30+
from __future__ import absolute_import
31+
from __future__ import unicode_literals
32+
import os
33+
import unittest
34+
import tempfile
35+
36+
import pygit2
37+
from pygit2 import Mailmap
38+
from . import utils
39+
40+
41+
TEST_MAILMAP = """\
42+
# Simple Comment line
43+
44+
45+
Other Author <[email protected]> nick2 <[email protected]>
46+
47+
Phil Hill <[email protected]> # Comment at end of line
48+
49+
50+
"""
51+
52+
TEST_ENTRIES = [
53+
54+
("Some Dude", "[email protected]", "nick1", "[email protected]"),
55+
("Other Author", "[email protected]", "nick2", "[email protected]"),
56+
("Other Author", "[email protected]", None, "[email protected]"),
57+
("Phil Hill", None, None, "[email protected]"),
58+
(None, "[email protected]", "Joseph", "[email protected]"),
59+
("Santa Claus", "[email protected]", None, "[email protected]")
60+
]
61+
62+
TEST_RESOLVE = [
63+
("Brad", "[email protected]", "Brad", "[email protected]"),
64+
("Brad L", "[email protected]", "Brad L", "[email protected]"),
65+
("Some Dude", "[email protected]", "nick1", "[email protected]"),
66+
("Other Author", "[email protected]", "nick2", "[email protected]"),
67+
("nick3", "[email protected]", "nick3", "[email protected]"),
68+
("Other Author", "[email protected]", "Some Garbage", "[email protected]"),
69+
("Phil Hill", "[email protected]", "unknown", "[email protected]"),
70+
("Joseph", "[email protected]", "Joseph", "[email protected]"),
71+
("Santa Claus", "[email protected]", "Clause", "[email protected]"),
72+
("Charles", "[email protected]", "Charles", "[email protected]")
73+
]
74+
75+
class ParsingTest(utils.NoRepoTestCase):
76+
77+
def test_empty(self):
78+
mailmap = Mailmap()
79+
80+
for (_, _, name, email) in TEST_RESOLVE:
81+
self.assertEqual(mailmap.resolve(name, email), (name, email))
82+
83+
def test_new(self):
84+
mailmap = Mailmap()
85+
86+
# Add entries to the mailmap
87+
for entry in TEST_ENTRIES:
88+
mailmap.add_entry(*entry)
89+
90+
for (real_name, real_email, name, email) in TEST_RESOLVE:
91+
self.assertEqual(mailmap.resolve(name, email), (real_name, real_email))
92+
93+
def test_parsed(self):
94+
mailmap = Mailmap.from_buffer(TEST_MAILMAP)
95+
96+
for (real_name, real_email, name, email) in TEST_RESOLVE:
97+
self.assertEqual(mailmap.resolve(name, email), (real_name, real_email))
98+
99+
100+
# TODO: Add a testcase which uses .mailmap in a repo
101+
102+
if __name__ == '__main__':
103+
unittest.main()

0 commit comments

Comments
 (0)