ug: improve custom converter docs
Relates to
@@ -1770,7 +1770,7 @@ the code above:
Accessing the test library from converter
`````````````````````````````````````````
-Starting from Robot Framework 6.1, it is possible to access the test library
+Starting from Robot Framework 6.1, it is possible to access the library
instance from a converter function. This allows defining dynamic type conversions
that depend on the library state. For example, if the library can be configured to
test particular locale, you might use the library state to determine how a date
@@ -1785,18 +1785,15 @@ should be parsed like this:
def parse_date(value, library):
# Validate input using regular expression and raise ValueError if not valid.
# Use locale based from library state to determine parsing format.
- match = None
- format = ''
if library.locale == 'en_US':
- match = re.match(r'(\d{1,2})/(\d{1,2})/(\d{4})$', value)
+ match = re.match(r'(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<year>\d{4})$', value)
format = 'mm/dd/yyyy'
else:
- match = re.match(r'(\d{1,2})\.(\d{1,2})\.(\d{4})$', value)
+ match = re.match(r'(?P<day>\d{1,2})\.(?P<month>\d{1,2})\.(?P<year>\d{4})$', value)
format = 'dd.mm.yyyy'
if not match:
raise ValueError(f"Expected date in format '{format}', got '{value}'.")
- day, month, year = match.groups()
- return date(int(year), int(month), int(day))
+ return date(int(match.group('year')), int(match.group('month')), int(match.group('day')))
ROBOT_LIBRARY_CONVERTERS = {date: parse_date}
