Skip to content

Commit

Permalink
API doc tuning/fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkaklarck committed Oct 11, 2022
1 parent 547cc77 commit 1a1e399
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/robot/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
returned by the :func:`~robot.result.resultbuilder.ExecutionResult` or
an executed :class:`~robot.running.model.TestSuite`.
* :class:`~robot.conf.languages.Language` base class for custom translations.
* :class:`~robot.conf.languages.Languages` and :class:`~robot.conf.languages.Language`
classes for external tools that need to work with different translations.
The latter is also the base class to use with custom translations.
All of the above names can be imported like::
Expand Down
15 changes: 12 additions & 3 deletions src/robot/conf/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class Languages:
languages = Languages('de', add_english=False)
print(languages.settings)
languages = Languages(['pt-BR', 'Finnish', 'MyLang.py'])
print(list(languages))
for lang in languages:
print(lang.name, lang.code)
"""

def __init__(self, languages=None, add_english=True):
Expand All @@ -37,7 +38,7 @@ def __init__(self, languages=None, add_english=True):
Languages can be given as language codes or names, paths or names of
language modules to load, or as :class:`Language` instances.
:param add_english: If True, English is added automatically.
:raises :class:`~robot.errors.DataError` if a given language is not found.
:raises: :class:`~robot.errors.DataError` if a given language is not found.
:meth:`add.language` can be used to add languages after initialization.
"""
Expand Down Expand Up @@ -217,8 +218,12 @@ def code(cls):
Got based on the class name. If the class name is two characters (or less),
the code is just the name in lower case. If it is longer, a hyphen is added
remainder of the class name is upper-cased.
and the remainder of the class name is upper-cased.
This special property can be accessed also directly from the class.
"""
if cls is Language:
return cls.__dict__['code']
code = cls.__name__.lower()
if len(code) < 3:
return code
Expand All @@ -229,7 +234,11 @@ def name(cls):
"""Language name like 'Finnish' or 'Brazilian Portuguese'.
Got from the first line of the class docstring.
This special property can be accessed also directly from the class.
"""
if cls is Language:
return cls.__dict__['name']
return cls.__doc__.splitlines()[0] if cls.__doc__ else ''

@property
Expand Down
4 changes: 4 additions & 0 deletions utest/api/test_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def test_all_standard_languages_have_code_and_name(self):
assert cls().name
assert cls.name

def test_code_and_name_of_Language_base_class_are_propertys(self):
assert isinstance(Language.code, property)
assert isinstance(Language.name, property)

def test_eq(self):
assert_equal(Fi(), Fi())
assert_equal(Language.from_name('fi'), Fi())
Expand Down

0 comments on commit 1a1e399

Please sign in to comment.