Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ops.lib line matching regexp #350

Merged
merged 5 commits into from Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ops/lib/__init__.py
Expand Up @@ -25,7 +25,7 @@

_libraries = None

_libline_re = re.compile(r'''^LIB([A-Z]+)\s+=\s+([0-9]+|['"][a-zA-Z0-9_.-@]+['"])\s*$''')
_libline_re = re.compile(r'''^LIB([A-Z]+)\s*=\s*([0-9]+|['"][a-zA-Z0-9_.\-@]+['"])''')
_libname_re = re.compile(r'''^[a-z][a-z0-9]+$''')

# Not perfect, but should do for now.
Expand Down
39 changes: 39 additions & 0 deletions test/test_lib.py
Expand Up @@ -187,6 +187,45 @@ def test_simple(self):
# also check the repr while we're at it
self.assertEqual(repr(lib), '<_Lib foo by alice@example.com, API 2, patch 42>')

def test_libauthor_has_dashes(self):
m = self._mkmod('foo', '''
LIBNAME = "foo"
LIBAPI = 2
LIBPATCH = 42
LIBAUTHOR = "alice-someone@example.com"
LIBANANA = True
''')
lib = ops.lib._parse_lib(m)
self.assertEqual(lib, ops.lib._Lib(None, "foo", "alice-someone@example.com", 2, 42))
# also check the repr while we're at it
self.assertEqual(repr(lib), '<_Lib foo by alice-someone@example.com, API 2, patch 42>')

def test_lib_definitions_without_spaces(self):
m = self._mkmod('foo', '''
LIBNAME="foo"
LIBAPI=2
LIBPATCH=42
LIBAUTHOR="alice@example.com"
LIBANANA=True
''')
lib = ops.lib._parse_lib(m)
self.assertEqual(lib, ops.lib._Lib(None, "foo", "alice@example.com", 2, 42))
# also check the repr while we're at it
self.assertEqual(repr(lib), '<_Lib foo by alice@example.com, API 2, patch 42>')

def test_lib_definitions_trailing_comments(self):
m = self._mkmod('foo', '''
LIBNAME = "foo" # comment style 1
LIBAPI = 2 = comment style 2
LIBPATCH = 42
LIBAUTHOR = "alice@example.com"anything after the quote is a comment
LIBANANA = True
''')
lib = ops.lib._parse_lib(m)
self.assertEqual(lib, ops.lib._Lib(None, "foo", "alice@example.com", 2, 42))
# also check the repr while we're at it
self.assertEqual(repr(lib), '<_Lib foo by alice@example.com, API 2, patch 42>')

def test_incomplete(self):
"""Check that if anything is missing, nothing is returned"""
m = self._mkmod('foo', '''
Expand Down