Skip to content

Commit 38ef017

Browse files
committed
Static library example
1 parent 510da00 commit 38ef017

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

docs/example/run.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import argparse
2+
3+
from robot import run_cli
4+
5+
parser = argparse.ArgumentParser("Runner for examples")
6+
parser.add_argument("type", help="Which example is run.")
7+
args = parser.parse_args()
8+
if args.type not in ["static", "dynamic"]:
9+
raise ValueError("Invalid value for library type.")
10+
run_cli([
11+
"--pythonpath",
12+
args.type,
13+
args.type
14+
])

docs/example/static/StaticLibrary.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import time
2+
from typing import Optional
3+
4+
from robot.api import logger
5+
6+
7+
class StaticLibrary:
8+
def __init__(self):
9+
self.separator = ";"
10+
11+
def join_strings(self, *strings: str) -> str:
12+
"""Joins args strings."""
13+
logger.info("Joining.")
14+
return " ".join(strings)
15+
16+
def sum(self, value1: int, value2: int) -> int:
17+
"""Do other thing."""
18+
logger.info(f"Calculating hard.")
19+
return value1 + value2
20+
21+
def wait_something_to_happen(self, arg1: str, arg2: int) -> str:
22+
self._waiter(0.3)
23+
arg1 = self.join_strings(arg1, arg1)
24+
self._waiter(0.2)
25+
arg2 = self.sum(arg2, arg2)
26+
self._waiter()
27+
logger.info("Waiting done")
28+
return f"{arg1} and {arg2}"
29+
30+
def join_string_with_separator(self, *strings, separator: Optional[str] =None):
31+
"""Joins strings with separator"""
32+
return f"{separator if separator else self.separator}".join(strings)
33+
34+
def _waiter(self, timeout: float = 0.1):
35+
logger.info(f"Waiting {timeout}")
36+
time.sleep(timeout)

docs/example/static/test.robot

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*** Settings ***
2+
Library StaticLibrary
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

0 commit comments

Comments
 (0)