Skip to content

Commit 7416220

Browse files
committed
Add tests for RegEx parsing
Signed-off-by: Ritiek Malhotra <[email protected]>
1 parent e8b2836 commit 7416220

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/packagedcode/test_cargo.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from __future__ import unicode_literals
2828

2929
import os
30+
import pytest
3031

3132
from packagedcode import cargo
3233

@@ -65,3 +66,36 @@ def test_parse_rustup(self):
6566
expected_loc = self.get_test_loc('cargo/rustup/Cargo.toml.expected')
6667
package = cargo.parse(test_file)
6768
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+
person = '<[email protected]>'
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

Comments
 (0)