-
Notifications
You must be signed in to change notification settings - Fork 27
Support for get_keyword_source #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
73c6cf4
Support for get_keyword_source
aaltat 712b660
Path or line not found tests
aaltat 3c0399a
Fixed mocked return type
aaltat 8ff94e4
Simplied logic for get_keyword_source
aaltat 2655b0e
Support decorator with def in the method name
aaltat be66b5b
Unit test refactoring
aaltat cdf411b
Test errors in inspect
aaltat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| pytest | ||
| pytest-cov | ||
| pytest-mockito | ||
| robotstatuschecker | ||
| flake8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import inspect | ||
| from os import path | ||
|
|
||
| import pytest | ||
| from DynamicLibrary import DynamicLibrary | ||
| from DynamicTypesLibrary import DynamicTypesLibrary | ||
| from mockito.matchers import Any | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
| def lib(): | ||
| return DynamicLibrary() | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
| def lib_types(): | ||
| return DynamicTypesLibrary() | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
| def cur_dir(): | ||
| return path.dirname(__file__) | ||
|
|
||
| @pytest.fixture(scope='module') | ||
| def lib_path(cur_dir): | ||
| return path.normpath(path.join(cur_dir, '..', 'atest', 'DynamicLibrary.py')) | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
| def lib_path_components(cur_dir): | ||
| return path.normpath(path.join(cur_dir, '..', 'atest', 'librarycomponents.py')) | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
| def lib_path_types(cur_dir): | ||
| return path.normpath(path.join(cur_dir, '..', 'atest', 'DynamicTypesLibrary.py')) | ||
|
|
||
|
|
||
| def test_location_in_main(lib, lib_path): | ||
| source = lib.get_keyword_source('keyword_in_main') | ||
| assert source == '%s:20' % lib_path | ||
|
|
||
|
|
||
| def test_location_in_class(lib, lib_path_components): | ||
| source = lib.get_keyword_source('method') | ||
| assert source == '%s:15' % lib_path_components | ||
|
|
||
|
|
||
| def test_location_in_class_custom_keyword_name(lib, lib_path_components): | ||
| source = lib.get_keyword_source('Custom name') | ||
| assert source == '%s:19' % lib_path_components | ||
|
|
||
|
|
||
| def test_no_line_number(lib, lib_path, when): | ||
| when(lib)._DynamicCore__get_keyword_line(Any()).thenReturn(None) | ||
| source = lib.get_keyword_source('keyword_in_main') | ||
| assert source == lib_path | ||
|
|
||
|
|
||
| def test_no_path(lib, when): | ||
| when(lib)._DynamicCore__get_keyword_path(Any()).thenReturn(None) | ||
| source = lib.get_keyword_source('keyword_in_main') | ||
| assert source == ':20' | ||
|
|
||
|
|
||
| def test_no_path_and_no_line_number(lib, when): | ||
| when(lib)._DynamicCore__get_keyword_path(Any()).thenReturn(None) | ||
| when(lib)._DynamicCore__get_keyword_line(Any()).thenReturn(None) | ||
| source = lib.get_keyword_source('keyword_in_main') | ||
| assert source is None | ||
|
|
||
|
|
||
| def test_def_in_decorator(lib_types, lib_path_types): | ||
| source = lib_types.get_keyword_source('keyword_with_def_deco') | ||
| assert source == '%s:62' % lib_path_types | ||
|
|
||
|
|
||
| def test_error_in_getfile(lib, when): | ||
| when(inspect).getfile(Any()).thenRaise(TypeError('Some message')) | ||
| source = lib.get_keyword_source('keyword_in_main') | ||
| assert source is None | ||
|
|
||
|
|
||
| def test_error_in_line_number(lib, when, lib_path): | ||
| when(inspect).getsourcelines(Any()).thenRaise(IOError('Some message')) | ||
| source = lib.get_keyword_source('keyword_in_main') | ||
| assert source == lib_path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this doesn't work correctly if someone has a library like this:
Above is obviously rather strange but from RF point of view it's valid. I see two solutions:
line_numberifdefline isn't found at all.getsourcelinesreturns.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bigger problem is that decorators returning different function than the original aren't supported correctly. Same issue on Robot side that the moment:
robotframework/robotframework#3516 (comment)