Skip to content

Commit 5cf6006

Browse files
committed
Type converter
1 parent 05fe00a commit 5cf6006

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/SeleniumLibrary/utils/types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616
import os
1717
from datetime import timedelta
18+
from typing import Any
1819

1920
from robot.utils import is_string, timestr_to_secs
2021
from robot.utils import is_truthy, is_falsy # noqa
@@ -32,3 +33,7 @@ def _convert_timeout(timeout):
3233
if isinstance(timeout, timedelta):
3334
return timeout.total_seconds()
3435
return timestr_to_secs(timeout)
36+
37+
38+
def type_converter(argument: Any) -> str:
39+
return type(argument).__name__.lower()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
import pytest
4+
from approvaltests import verify_all
5+
from approvaltests.reporters import GenericDiffReporterFactory
6+
7+
from SeleniumLibrary.utils.types import type_converter
8+
9+
10+
@pytest.fixture(scope="module")
11+
def reporter():
12+
path = os.path.dirname(__file__)
13+
reporter_json = os.path.abspath(
14+
os.path.join(path, "..", "approvals_reporters.json")
15+
)
16+
factory = GenericDiffReporterFactory()
17+
factory.load(reporter_json)
18+
return factory.get_first_working()
19+
20+
21+
def test_type_converter(reporter):
22+
results = [
23+
type_converter("str"),
24+
type_converter(1),
25+
type_converter({"key": 1}),
26+
]
27+
verify_all("Type converter", results, reporter=reporter)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Type converter
2+
3+
0) str
4+
1) int
5+
2) dict

0 commit comments

Comments
 (0)