Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbovbel committed Apr 16, 2019
1 parent 338f9ae commit f767092
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
7 changes: 4 additions & 3 deletions catkin_virtualenv/scripts/combine_requirements
Expand Up @@ -44,12 +44,13 @@ def combine_requirements(requirements_list, output_file):
# Support for VCS requirements. First try to match a SemVer requirement then a VCS requirement.
try:
requirement = Requirement(requirement_string)
except InvalidRequirement as e:
except InvalidRequirement as semver_err:
try:
requirement = VcsRequirement(requirement_string)
except RuntimeError as err:
except RuntimeError as vcs_err:
raise RuntimeError(
"Could not match requirement for VCS or SemVer: {}, {}".format(str(e), str(err)))
"Could not match requirement {} for VCS ({}) or SemVer ({})".format(
requirement_string, str(vcs_err), str(semver_err)))

if requirement.name not in combined_requirements:
combined_requirements[requirement.name] = CombinedRequirement(
Expand Down
12 changes: 6 additions & 6 deletions catkin_virtualenv/src/catkin_virtualenv/requirements.py
Expand Up @@ -57,10 +57,10 @@ class VcsRequirement(object):
)

def __init__(self, string):
self.name = string
match = self.name_regex.search(string)
if match is None:
raise RuntimeError("Invalid VCS requirement, must match {}".format(self.name_regex.pattern))

if not self.name_regex.match(string):
raise RuntimeError("Invalid VCS requirement name {}, must match {}".format(string, self.name_regex))

def __str__(self):
return self.name
self.name = match.group('name')
if self.name is None:
raise RuntimeError("No project name '#egg=<name>' was provided in requirement string {}".format(string))
16 changes: 15 additions & 1 deletion catkin_virtualenv/test/test_requirements.py
Expand Up @@ -22,4 +22,18 @@


class TestRequirements(unittest.TestCase):
pass

def test_vcs_requirement_parse(self):
string = "git+git://github.com/pytransitions/transitions@dev-async#egg=transitions"
req = VcsRequirement(string)
self.assertEqual(req.name, "transitions")

def test_vcs_requirement_parse_no_name(self):
string = "git+git://github.com/pytransitions/transitions@dev-async"
req = VcsRequirement(string)
self.assertEqual(req.name, "transitions")

def test_vcs_requirement_parse_fail(self):
string = "asdf"
req = VcsRequirement(string)
self.assertEqual(req.name, "transitions")

0 comments on commit f767092

Please sign in to comment.