From 6b90327f4b1cb87252dda3342384b840593e1f5e Mon Sep 17 00:00:00 2001 From: Adrian Blasiak Date: Mon, 9 Sep 2024 12:36:31 +0200 Subject: [PATCH] check for __init__.robot files when listener API passes directory instead of a file --- DebugLibrary/steplistener.py | 8 ++++++++ tests/robot/__init__.robot | 11 +++++++++++ tests/{ => robot}/step.robot | 0 tests/test_debuglibrary.py | 26 +++++++++++++++++++++----- 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 tests/robot/__init__.robot rename tests/{ => robot}/step.robot (100%) diff --git a/DebugLibrary/steplistener.py b/DebugLibrary/steplistener.py index 7d803ca..e7c4b88 100644 --- a/DebugLibrary/steplistener.py +++ b/DebugLibrary/steplistener.py @@ -1,4 +1,5 @@ import inspect +import os from .globals import context @@ -28,6 +29,13 @@ def _start_keyword(self, name, attrs): path = attrs['source'] lineno = attrs['lineno'] + if path and os.path.isdir(path): + # we might be in folder-wide __init__.robot, but listener args are not telling us that + # - gives us only the folder path. + init_path = os.path.join(path, '__init__.robot') + if os.path.exists(init_path): + path = init_path + if path: lineno_0_based = lineno - 1 context.current_source_path = path diff --git a/tests/robot/__init__.robot b/tests/robot/__init__.robot new file mode 100644 index 0000000..103f2f5 --- /dev/null +++ b/tests/robot/__init__.robot @@ -0,0 +1,11 @@ +*** Settings *** +Library DebugLibrary + +Suite Setup Setup + + +*** Keywords *** +Setup + debug + log to console __init__ working + @{list} = Create List __init__ hello world diff --git a/tests/step.robot b/tests/robot/step.robot similarity index 100% rename from tests/step.robot rename to tests/robot/step.robot diff --git a/tests/test_debuglibrary.py b/tests/test_debuglibrary.py index abfcb5f..f619f01 100644 --- a/tests/test_debuglibrary.py +++ b/tests/test_debuglibrary.py @@ -101,11 +101,11 @@ def base_functional_testing(): def step_functional_testing(): global child - # Command "coverage run robot tests/step.robot" does not work, + # Command "coverage run robot tests/robot/step.robot" does not work, # so start the program using DebugLibrary's shell instead of "robot". child = pexpect.spawn('coverage', ['run', '--append', 'DebugLibrary/shell.py', - 'tests/step.robot']) + 'tests/robot']) child.expect('Type "help" for more information.*>', timeout=TIMEOUT_SECONDS * 3) @@ -114,18 +114,34 @@ def step_functional_testing(): support_source_lineno = get_version() >= '3.2' if support_source_lineno: + + check_command('s', # step + '/tests/robot/__init__.robot.10.*' + '-> log to console __init__ working.*' + '=> BuiltIn.Log To Console __init__ working' + ) + check_command('s', # step + '/tests/robot/__init__.robot.11.*' + '@.* = Create List __init__ hello world.*' + '@.* = BuiltIn.Create List __init__ hello world') + check_command('n', # next + '/tests/robot/step.robot.6..*' + '-> debug.*' + '=> DebugLibrary.Debug') + check_command('s', # step + '') check_command('s', # step - '/tests/step.robot.7..*' + '/tests/robot/step.robot.7..*' '-> log to console working.*' '=> BuiltIn.Log To Console working') check_command('l', # list ' 7 -> log to console working') check_command('n', # next - '/tests/step.robot.8..*' + '/tests/robot/step.robot.8..*' '@.* = Create List hello world.*' '@.* = BuiltIn.Create List hello world') check_command('', # just repeat last command - '/tests/step.robot.11..*' + '/tests/robot/step.robot.11..*' '-> log to console another test case.*' '=> BuiltIn.Log To Console another test case') check_command('l', # list