Commit 1ac8a65d authored by FichteFoll's avatar FichteFoll

Small edits for tests, no functionality changes

parent 94d086a0
...@@ -37,9 +37,7 @@ for arg in userargs: ...@@ -37,9 +37,7 @@ for arg in userargs:
def _open(filepath, *args, **kwargs): def _open(filepath, *args, **kwargs):
"""Wrapper function that can search one dir above if the desired file """Wrapper function to search one dir above if a file does not exist."""
does not exist.
"""
if not os.path.exists(filepath): if not os.path.exists(filepath):
filepath = os.path.join("..", filepath) filepath = os.path.join("..", filepath)
...@@ -100,7 +98,7 @@ def generator_class(cls): ...@@ -100,7 +98,7 @@ def generator_class(cls):
def get_package_name(data): def get_package_name(data):
"""Gets "name" from a package with a workaround when it's not defined. """Get "name" from a package with a workaround when it's not defined.
Use the last part of details url for the package's name otherwise since Use the last part of details url for the package's name otherwise since
packages must define one of these two keys anyway. packages must define one of these two keys anyway.
...@@ -113,6 +111,7 @@ def get_package_name(data): ...@@ -113,6 +111,7 @@ def get_package_name(data):
class TestContainer(object): class TestContainer(object):
"""Contains tests that the generators can easily access (when subclassing). """Contains tests that the generators can easily access (when subclassing).
Does not contain tests itself, must be used as mixin with unittest.TestCase. Does not contain tests itself, must be used as mixin with unittest.TestCase.
...@@ -133,15 +132,19 @@ class TestContainer(object): ...@@ -133,15 +132,19 @@ class TestContainer(object):
'labels': list 'labels': list
} }
d_reg = r'''^ (https:// github\.com/ [^/]+/ [^/]+ (/tree/ .+ (?<!/) rel_d_reg = r'''^ (https:// github\.com/ [^/]+/ [^/]+ (/tree/ .+ (?<!/)
|/tags |/tags
|/)? |/)?
|https:// bitbucket\.org/ [^/]+/ [^/]+ (/src/ .+ (?<!/) |https:// bitbucket\.org/ [^/]+/ [^/]+ (/src/ .+ (?<!/)
|\#tags |\#tags
|/)? |/)?
) $''' ) $'''
# Strip multilines for better debug info on failures # Strip multilines for better debug info on failures
details_regex = re.compile(' '.join(d_reg.split()), re.X) rel_d_reg = ' '.join(map(str.strip, rel_d_reg.split()))
release_details_regex = re.compile(rel_d_reg, re.X)
# Use the same as for releases, for now
package_details_regex = release_details_regex
def _test_repository_keys(self, include, data): def _test_repository_keys(self, include, data):
self.assertTrue(2 <= len(data) <= 3, "Unexpected number of keys") self.assertTrue(2 <= len(data) <= 3, "Unexpected number of keys")
...@@ -173,7 +176,8 @@ class TestContainer(object): ...@@ -173,7 +176,8 @@ class TestContainer(object):
# Check if in the correct file # Check if in the correct file
for package_name in packages: for package_name in packages:
if letter == '0-9': if letter == '0-9':
self.assertTrue(package_name[0].isdigit()) self.assertTrue(package_name[0].isdigit(),
"Package inserted in wrong file")
else: else:
self.assertEqual(package_name[0].lower(), letter, self.assertEqual(package_name[0].lower(), letter,
"Package inserted in wrong file") "Package inserted in wrong file")
...@@ -199,7 +203,7 @@ class TestContainer(object): ...@@ -199,7 +203,7 @@ class TestContainer(object):
self.assertRegex(v, '^https?://') self.assertRegex(v, '^https?://')
elif k == 'details': elif k == 'details':
self.assertRegex(v, self.details_regex, self.assertRegex(v, self.package_details_regex,
'The details url is badly formatted or ' 'The details url is badly formatted or '
'invalid') 'invalid')
...@@ -254,7 +258,7 @@ class TestContainer(object): ...@@ -254,7 +258,7 @@ class TestContainer(object):
self.assertRegex(v, r'^https?://') self.assertRegex(v, r'^https?://')
if k == 'details': if k == 'details':
self.assertRegex(v, self.details_regex, self.assertRegex(v, self.release_details_regex,
'The details url is badly formatted or ' 'The details url is badly formatted or '
'invalid') 'invalid')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment