|
27 | 27 | from __future__ import unicode_literals |
28 | 28 |
|
29 | 29 | import os |
| 30 | +import pytest |
30 | 31 |
|
31 | 32 | from packagedcode import cargo |
32 | 33 |
|
@@ -65,3 +66,36 @@ def test_parse_rustup(self): |
65 | 66 | expected_loc = self.get_test_loc('cargo/rustup/Cargo.toml.expected') |
66 | 67 | package = cargo.parse(test_file) |
67 | 68 | self.check_package(package, expected_loc, regen=False) |
| 69 | + |
| 70 | + |
| 71 | +PERSON_PARSER_TEST_TABLE = [ |
| 72 | + ( 'Barney Rubble <[email protected]>', ( 'Barney Rubble ', '<[email protected]>')), |
| 73 | + ('Barney Rubble', ('Barney Rubble', None)), |
| 74 | + ( 'Some Good Guy <[email protected]>', ( 'Some Good Guy ', '<[email protected]>')), |
| 75 | + ('Some Good Guy', ('Some Good Guy', None)), |
| 76 | +] |
| 77 | + |
| 78 | +PERSON_NO_NAME_PARSER_TEST_TABLE = [ |
| 79 | + |
| 80 | + |
| 81 | +] |
| 82 | + |
| 83 | +class TestRegex(object): |
| 84 | + @pytest.mark.parametrize('person, expected_person', PERSON_PARSER_TEST_TABLE) |
| 85 | + def test_person_parser(self, person, expected_person): |
| 86 | + parsed_person = cargo.person_parser(person) |
| 87 | + person_information = parsed_person.groupdict() |
| 88 | + name, email = person_information.get('name'), person_information.get('email') |
| 89 | + assert (name, email) == expected_person |
| 90 | + |
| 91 | + def test_person_parser_no_name_failure(self): |
| 92 | + |
| 93 | + parsed_person = cargo.person_parser(person) |
| 94 | + assert parsed_person is None |
| 95 | + |
| 96 | + @pytest.mark.parametrize('person, expected_person', PERSON_NO_NAME_PARSER_TEST_TABLE) |
| 97 | + def test_person_parser_no_name(self, person, expected_person): |
| 98 | + parsed_person = cargo.person_parser_no_name(person) |
| 99 | + person_information = parsed_person.groupdict() |
| 100 | + name, email = person_information.get('name'), person_information.get('email') |
| 101 | + assert (name, email) == expected_person |
0 commit comments