Skip to content

Commit

Permalink
unicode_rules: Use back-ticks for printing literal chars/strings
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Aug 26, 2020
1 parent b4366ad commit cfeb302
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions cylc/flow/unicode_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
ENGLISH_REGEX_MAP = {
r'\w': 'alphanumeric',
r'a-zA-Z0-9': 'latin letters and numbers',
r'\-': '-',
r'\.': '.',
r'\/': '/'
r'\-': '``-``',
r'\.': '``.``',
r'\/': '``/``'
}


Expand All @@ -39,10 +39,12 @@ def regex_chars_to_text(chars):
['-', '.', '/']
>>> regex_chars_to_text([r'\w'])
['alphanumeric']
>>> regex_chars_to_text(['not_in_map'])
['not_in_map']
"""
return [
ENGLISH_REGEX_MAP.get(char, char)
ENGLISH_REGEX_MAP.get(char, f'``{char}``')
for char in chars
]

Expand Down Expand Up @@ -72,7 +74,7 @@ def allowed_characters(*chars):
Example:
>>> regex, message = allowed_characters('a', 'b', 'c')
>>> message
'can only contain: a, b, c'
'can only contain: ``a``, ``b``, ``c``'
>>> bool(regex.match('abc'))
True
>>> bool(regex.match('def'))
Expand All @@ -91,7 +93,7 @@ def not_starts_with(*chars):
Example:
>>> regex, message = not_starts_with('a', 'b', 'c')
>>> message
'can not start with: a, b, c'
'can not start with: ``a``, ``b``, ``c``'
>>> bool(regex.match('def'))
True
>>> bool(regex.match('adef'))
Expand All @@ -111,7 +113,7 @@ def not_contains_colon_unless_starts_with(*chars):
>>> regex, message = not_contain_colon_unless_starts_with(
'INFO', 'WARNING')
>>> message
'cannot contain a colon unless starts with: INFO, WARNING'
'cannot contain a colon unless starts with: ``INFO``, ``WARNING``'
>>> bool(regex.match('Foo: bar'))
False
>>> bool(regex.match('INFO: Foo: bar'))
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_suite_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_register_test_cases():
None, # expected symlink
None, # expected return value
SuiteServiceFileError, # expected exception
"can not start with: ., -" # expected part of exception message
"can not start with: ``.``, ``-``" # expected part of exception message
)
]

Expand Down

0 comments on commit cfeb302

Please sign in to comment.