Skip to content

Commit 804fccf

Browse files
committed
Fix source path with decorator
Fixes robotframework#99
1 parent 37768bf commit 804fccf

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

atest/custon_deco.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import functools
2+
3+
4+
def custom_deco(arg1, arg2):
5+
print(arg1, arg2)
6+
7+
def actual_decorator(func):
8+
@functools.wraps(func)
9+
def wrapper(*args, **kwargs):
10+
print("BEFORE")
11+
value = func(*args, **kwargs)
12+
print("AFTER")
13+
return value
14+
return wrapper
15+
return actual_decorator

atest/librarycomponents.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from custon_deco import custom_deco
12
from robotlibcore import keyword
23

34

@@ -13,8 +14,9 @@ class Names:
1314
def method(self):
1415
return 2
1516

17+
@custom_deco("foo", "bar")
1618
@keyword('Custom name')
17-
def _custom_name(self):
19+
def _other_name_here(self):
1820
return 3
1921

2022
def not_keyword(self):

src/robotlibcore.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __get_keyword_line(self, method):
157157

158158
def __get_keyword_path(self, method):
159159
try:
160-
return os.path.normpath(inspect.getfile(method))
160+
return os.path.normpath(inspect.getfile(inspect.unwrap(method)))
161161
except TypeError:
162162
return None
163163

utest/test_get_keyword_source.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_location_in_main(lib, lib_path):
4545

4646
def test_location_in_class(lib, lib_path_components):
4747
source = lib.get_keyword_source("method")
48-
assert source == "%s:13" % lib_path_components
48+
assert source == f"{lib_path_components}:14"
4949

5050

5151
def test_decorator_wrapper(lib_types, lib_path_types):
@@ -55,7 +55,7 @@ def test_decorator_wrapper(lib_types, lib_path_types):
5555

5656
def test_location_in_class_custom_keyword_name(lib, lib_path_components):
5757
source = lib.get_keyword_source("Custom name")
58-
assert source == "%s:17" % lib_path_components
58+
assert source == f"{lib_path_components}:19"
5959

6060

6161
def test_no_line_number(lib, lib_path, when):

utest/test_robotlibcore.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_dir():
4141
"_DynamicCore__get_keyword_path",
4242
"_HybridCore__get_members",
4343
"_HybridCore__get_members_from_instance",
44-
"_custom_name",
44+
"_other_name_here",
4545
"add_library_components",
4646
"all_arguments",
4747
"attributes",
@@ -99,7 +99,7 @@ def test_getattr():
9999
assert lib.instance_attribute == "not keyword"
100100
assert lib.function() == 1
101101
assert lib.method() == 2
102-
assert lib._custom_name() == 3
102+
assert lib._other_name_here() == 3
103103
assert getattr(lib, "Custom name")() == 3
104104
with pytest.raises(AttributeError) as exc_info:
105105
lib.non_existing

0 commit comments

Comments
 (0)