def test_types(lib_py3):
    spec = KeywordBuilder.build(lib_py3.self_and_keyword_only_types)
    assert spec.argument_types == {
        'varargs': int,
        'other': bool,
        'kwargs': int
    }
def test_named_only_rf31(lib_py3):
    spec = KeywordBuilder.build(lib_py3.named_only_with_defaults)
    assert spec.argument_specification == [
        '*varargs', 'key1', 'key2', 'key3=default1', 'key4=True'
    ]
def test_named_only(lib_py3):
    spec = KeywordBuilder.build(lib_py3.named_only)
    assert spec.argument_specification == ['*varargs', 'key1', 'key2']
def test_varargs_and_kwargs(lib):
    spec = KeywordBuilder.build(lib.varargs_kwargs)
    assert spec.argument_specification == ['*vargs', '**kwargs']
def test_named_only_rf31(lib):
    spec = KeywordBuilder.build(lib.default_only)
    assert spec.argument_specification == ['named1=string1', 'named2=123']
def test_named_only_rf32(lib):
    spec = KeywordBuilder.build(lib.default_only)
    assert spec.argument_specification == [('named1', 'string1'),
                                           ('named2', 123)]
示例#7
0
def test_named_only(lib):
    spec = KeywordBuilder.build(lib.named_only_with_defaults)
    assert spec.argument_specification == [
        '*varargs', 'key1', 'key2', ('key3', 'default1'), ('key4', True)
    ]
    def run_keyword(self, name: str, args: tuple, kwargs: Optional[dict] = None): ...
    def get_keyword_arguments(self, name: str): ...
    def get_keyword_tags(self, name: str): ...
    def get_keyword_documentation(self, name: str): ...
    def get_keyword_types(self, name: str): ...
    def get_keyword_source(self, keyword_name: str): ...
    def failure_occurred(self): ...
    def register_driver(self, driver: WebDriver, alias: str): ...
    @property
    def driver(self) -> WebDriver: ...
    def find_element(self, locator: str, parent: Optional[WebElement] = None): ...
    def find_elements(self, locator: str, parent: WebElement = None): ...
    def _parse_plugins(self, plugins: Any): ...
    def _parse_plugin_doc(self): ...
    def _get_intro_documentation(self): ...
    def _parse_listener(self, event_firing_webdriver: Any): ...
    def _string_to_modules(self, modules: Any): ...
    def _store_plugin_keywords(self, plugin): ...
    def _resolve_screenshot_root_directory(self): ...
"""

INIT_METHOD = KeywordBuilder.build(SL.__init__)
with open("src/SeleniumLibrary/__init__.pyi", "w") as stub_file:
    stub_file.write(pyi_boilerplate)
    stub_file.write(
        keyword_line(INIT_METHOD.argument_specification,
                     INIT_METHOD.argument_types, "__init__"))
    stub_file.writelines(FUNCTION_LIST)
    stub_file.write("\n    # methods from library.")
    stub_file.writelines(pyi_boilerplate_append.splitlines(keepends=True))
def test_no_args(lib):
    spec = KeywordBuilder.build(lib.no_args)
    assert spec.argument_specification == []
def test_documentation(lib):
    spec = KeywordBuilder.build(lib.positional_args)
    assert spec.documentation == 'Some documentation\n\nMulti line docs'
    spec = KeywordBuilder.build(lib.positional_and_default)
    assert spec.documentation == ''
def test_optional_none(lib_py3):
    spec = KeywordBuilder.build(lib_py3.optional_none)
    assert spec.argument_types == {'arg1': str, 'arg2': str}
def test_types_(lib_py3):
    spec = KeywordBuilder.build(lib_py3.args_with_type_hints)
    assert spec.argument_types == {'arg3': str, 'arg4': type(None)}
示例#13
0
def test_complex_deco(dyn_types):
    spec = KeywordBuilder.build(dyn_types.keyword_with_deco_and_signature)
    assert spec.argument_types == {'arg1': bool, 'arg2': bool}
    assert spec.argument_specification == [('arg1', False), ('arg2', False)]
    assert spec.documentation == "Test me doc here"
示例#14
0
def test_optional_none(lib):
    spec = KeywordBuilder.build(lib.optional_none)
    assert spec.argument_types == {
        'arg1': typing.Union[str, None],
        'arg2': typing.Union[str, None]
    }
def test_types_in_keyword_deco(lib):
    spec = KeywordBuilder.build(lib.positional_args)
    assert spec.argument_types == {'arg1': str, 'arg2': int}
def test_positional_args(lib):
    spec = KeywordBuilder.build(lib.positional_args)
    assert spec.argument_specification == ['arg1', 'arg2']
def test_types_disabled_in_keyword_deco(lib):
    spec = KeywordBuilder.build(lib.types_disabled)
    assert spec.argument_types is None
def test_positional_and_named_rf31(lib):
    spec = KeywordBuilder.build(lib.positional_and_default)
    assert spec.argument_specification == [
        'arg1', 'arg2', 'named1=string1', 'named2=123'
    ]
示例#19
0
    arguments_string = (f", {', '.join(arguments_list)}"
                        if len(arguments_list) > 0 else "")
    return f"    def {method_name}(self{arguments_string}): ...\n"


br: Any = Browser.Browser()
function_list = get_function_list_from_keywords(br.get_keyword_names())

pyi_boilerplate = """from concurrent.futures import Future
from typing import (
    Any,
    Dict,
    List,
    Optional,
    Union,
)

from .utils.data_types import *


class Browser:
"""

init_method = KeywordBuilder.build(br.__init__)
with open("Browser/__init__.pyi", "w") as stub_file:
    stub_file.write(pyi_boilerplate)
    stub_file.write(
        keyword_line(init_method.argument_specification,
                     init_method.argument_types, "__init__"))
    stub_file.writelines(function_list)
示例#20
0
def test_positional_and_named(lib):
    spec = KeywordBuilder.build(lib.positional_and_default)
    assert spec.argument_specification == [
        'arg1', 'arg2', ('named1', 'string1'), ('named2', 123)
    ]