|
| 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 | + |
| 46 | + |
| 47 | +Phil Hill <[email protected]> # Comment at end of line |
| 48 | + |
| 49 | + |
| 50 | +""" |
| 51 | + |
| 52 | +TEST_ENTRIES = [ |
| 53 | + |
| 54 | + |
| 55 | + ( "Other Author", "[email protected]", "nick2", "[email protected]"), |
| 56 | + |
| 57 | + ( "Phil Hill", None, None, "[email protected]"), |
| 58 | + |
| 59 | + |
| 60 | +] |
| 61 | + |
| 62 | +TEST_RESOLVE = [ |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + ( "Other Author", "[email protected]", "nick2", "[email protected]"), |
| 67 | + |
| 68 | + ( "Other Author", "[email protected]", "Some Garbage", "[email protected]"), |
| 69 | + |
| 70 | + |
| 71 | + ( "Santa Claus", "[email protected]", "Clause", "[email protected]"), |
| 72 | + |
| 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