Skip to content

Commit 542aaa9

Browse files
committed
Hybrid example
1 parent ab3ba40 commit 542aaa9

File tree

7 files changed

+93
-6
lines changed

7 files changed

+93
-6
lines changed

docs/example/01-static/StaticLibrary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def wait_something_to_happen(self, arg1: str, arg2: int) -> str:
2727
logger.info("Waiting done")
2828
return f"{arg1} and {arg2}"
2929

30-
def join_string_with_separator(self, *strings, separator: Optional[str] =None):
30+
def join_string_with_separator(self, *strings, separator: Optional[str] = None):
3131
"""Joins strings with separator"""
3232
return f"{separator if separator else self.separator}".join(strings)
3333

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from robot.api import logger
2+
3+
from calculator import Calculator
4+
from stringtools import StringTools
5+
from waiter import Waiter
6+
7+
8+
class HybridLibrary(Calculator, StringTools, Waiter):
9+
def __init__(self, separator: str = ";"):
10+
self.separator = separator
11+
12+
def get_keyword_names(self):
13+
keywords = []
14+
for name in dir(self):
15+
method = getattr(self, name)
16+
if hasattr(method, "robot_name"):
17+
keywords.append(name)
18+
return keywords

docs/example/02-hybrid/calculator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from robot.api import logger
2+
from robot.api.deco import keyword
3+
4+
5+
class Calculator:
6+
@keyword
7+
def sum(self, value1: int, value2: int) -> int:
8+
"""Do other thing."""
9+
logger.info(f"Calculating hard.")
10+
return value1 + value2

docs/example/02-hybrid/stringtools.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import Optional
2+
3+
from robot.api import logger
4+
from robot.api.deco import keyword
5+
6+
7+
class StringTools:
8+
@keyword
9+
def join_strings(self, *strings: str) -> str:
10+
"""Joins args strings."""
11+
logger.info("Joining.")
12+
return " ".join(strings)
13+
14+
@keyword
15+
def join_string_with_separator(self, *strings, separator: Optional[str] = None):
16+
"""Joins strings with separator"""
17+
return f"{separator if separator else self.separator}".join(strings)

docs/example/02-hybrid/test.robot

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*** Settings ***
2+
Library HybridLibrary
3+
4+
*** Test Cases ***
5+
Join Stings
6+
${data} = Join Strings kala is big
7+
Should Be Equal ${data} kala is big
8+
9+
Sum Values
10+
${data} = Sum 1 2
11+
Should Be Equal As Numbers ${data} 3
12+
13+
Wait Something To Happen
14+
${data} = Wait Something To Happen tidii 3
15+
Should Be Equal ${data} tidii tidii and 6
16+
17+
Join Strings With Separator
18+
${data} = Join String With Separator Foo Bar Tidii separator=|-|
19+
Should Be Equal ${data} Foo|-|Bar|-|Tidii
20+
${data} = Join String With Separator Foo Bar Tidii
21+
Should Be Equal ${data} Foo;Bar;Tidii
22+
23+
Waiter Is Not Keyword
24+
Run Keyword And Expect Error
25+
... No keyword with name 'Waiter' found.
26+
... Waiter 1.0

docs/example/02-hybrid/waiter.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import time
2+
3+
from robot.api import logger
4+
from robot.api.deco import keyword
5+
6+
7+
class Waiter:
8+
@keyword
9+
def wait_something_to_happen(self, arg1: str, arg2: int) -> str:
10+
self.waiter(0.3)
11+
arg1 = self.join_strings(arg1, arg1)
12+
self.waiter(0.2)
13+
arg2 = self.sum(arg2, arg2)
14+
self.waiter()
15+
logger.info("Waiting done")
16+
return f"{arg1} and {arg2}"
17+
18+
def waiter(self, timeout: float = 0.1):
19+
logger.info(f"Waiting {timeout}")
20+
time.sleep(timeout)

docs/example/run.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@
1111
folder = f"02-{args.type}"
1212
else:
1313
raise ValueError("Invalid value for library type.")
14-
run_cli([
15-
"--pythonpath",
16-
folder,
17-
folder
18-
])
14+
run_cli(["--loglevel", "trace", "--pythonpath", folder, folder])

0 commit comments

Comments
 (0)