Skip to content

Commit 018077d

Browse files
committed
Fix WITH NAME with embedded args and library state
Fixes robotframework#3181.
1 parent 52c388d commit 018077d

4 files changed

Lines changed: 39 additions & 3 deletions

File tree

atest/robot/test_libraries/with_name.robot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Embedded Arguments
4444
Check Log Message ${tc.kws[0].msgs[0]} arg
4545
Check Log Message ${tc.kws[1].msgs[0]} --args--
4646

47+
Embedded Arguments With Library Having State
48+
Check Test Case ${TEST NAME}
49+
4750
Arguments Containing Variables And Import Same Library Twice
4851
${tc} = Check Test Case ${TEST NAME}
4952
Check Keyword Data ${tc.kws[0]} Param1.Parameters Should Be args=1, 2
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from robot.api.deco import keyword
2+
3+
4+
class Embedded(object):
5+
6+
def __init__(self):
7+
self.called = 0
8+
9+
@keyword('Called ${times} time(s)', types={'times': int})
10+
def called_times(self, times):
11+
self.called += 1
12+
if self.called != times:
13+
raise AssertionError('Called %s time(s), expected %s time(s).'
14+
% (self.called, times))

atest/testdata/test_libraries/with_name_2.robot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Library pythonmodule.library WITH NAME mod 2
1010
Library ExampleJavaLibrary WITH NAME Java Lib
1111
Library javapkg.JavaPackageExample WITH NAME Java Pkg
1212
Library MyLibFile.py WITH NAME Params
13+
Library Embedded.py WITH NAME Embedded1
14+
Library Embedded.py WITH NAME Embedded2
1315
Library RunKeywordLibrary WITH NAME dynamic
1416
Library RunKeywordLibraryJava WITH NAME dynamicJava
1517
Library libraryscope.Global WITH NAME G Scope
@@ -30,6 +32,13 @@ Embedded Arguments
3032
Keyword with embedded arg in MyLibFile
3133
Params.Keyword With Embedded --args-- in MyLibFile
3234

35+
Embedded Arguments With Library Having State
36+
Embedded1.Called 1 time(s)
37+
Embedded1.Called 2 time(s)
38+
Embedded2.Called 1 time(s)
39+
Embedded1.Called 3 time(s)
40+
Embedded2.Called 2 time(s)
41+
3342
Arguments Containing Variables And Import Same Library Twice
3443
Param1.Parameters should be 1 2
3544
par am 2 . par A meter S should BE VAR ${42}

src/robot/running/handlers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
from copy import copy
17+
1618
from robot.utils import (getdoc, getshortdoc, is_java_init, is_java_method,
1719
is_list_like, printable_name, split_tags_from_doc,
1820
type_name)
@@ -262,18 +264,26 @@ class EmbeddedArgumentsHandler(object):
262264

263265
def __init__(self, name_regexp, orig_handler):
264266
self.arguments = ArgumentSpec() # Show empty argument spec for Libdoc
265-
self._orig_handler = orig_handler
266267
self.name_regexp = name_regexp
268+
self._orig_handler = orig_handler
267269

268270
def __getattr__(self, item):
269271
return getattr(self._orig_handler, item)
270272

273+
@property
274+
def library(self):
275+
return self._orig_handler.library
276+
277+
@library.setter
278+
def library(self, library):
279+
self._orig_handler.library = library
280+
271281
def matches(self, name):
272282
return self.name_regexp.match(name) is not None
273283

274284
def create_runner(self, name):
275285
return EmbeddedArgumentsRunner(self, name)
276286

277287
def __copy__(self):
278-
# Needed due to https://github.com/IronLanguages/main/issues/1192
279-
return EmbeddedArgumentsHandler(self.name_regexp, self._orig_handler)
288+
orig_handler = copy(self._orig_handler)
289+
return EmbeddedArgumentsHandler(self.name_regexp, orig_handler)

0 commit comments

Comments
 (0)