Coverage for src/robotide/usages/commands.py: 63%

45 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-06 10:40 +0100

1# Copyright 2008-2015 Nokia Networks 

2# Copyright 2016- Robot Framework Foundation 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15 

16import os 1ab

17 

18from ..controller.ctrlcommands import FindOccurrences, FindVariableOccurrences, _Command 1ab

19 

20 

21class FindUsages(FindOccurrences): 1ab

22 

23 def execute(self, context): 1ab

24 from ..controller.macrocontrollers import KeywordNameController 1cdefgjkl

25 # print(f"DEBUG: usages/commands.py FindUsages execute context={context}") 

26 prev = None 1cdefgjkl

27 for occ in FindOccurrences.execute(self, context): 1cdefgjkl

28 # if hasattr(occ, 'item'): 

29 # print(f"DEBUG: usages/commands.py FindUsages execute in loop occ={occ.item}") 

30 # else: 

31 # print(f"DEBUG: usages/commands.py FindUsages execute in loop NOT occ.item occ={occ}") 

32 # continue 

33 if hasattr(occ, 'item') and isinstance(occ.item, KeywordNameController): 1cdefg

34 continue 1cdefg

35 if prev == occ: 35 ↛ 36line 35 didn't jump to line 36 because the condition on line 35 was never true1cdefg

36 prev.count += 1 

37 else: 

38 if prev: 38 ↛ 39line 38 didn't jump to line 39 because the condition on line 38 was never true1cdefg

39 yield prev 

40 prev = occ 1cdefg

41 if prev: 1cdefgjkl

42 yield prev 1cdefg

43 

44 

45class FindVariableUsages(FindVariableOccurrences): 1ab

46 

47 def execute(self, context): 1ab

48 prev = None 

49 for occ in FindVariableOccurrences.execute(self, context): 

50 if prev == occ: 

51 prev.count += 1 

52 else: 

53 if prev: 

54 yield prev 

55 prev = occ 

56 if prev: 

57 yield prev 

58 

59 

60class FindResourceUsages(_Command): 1ab

61 

62 def execute(self, context): 1ab

63 """from ..controller.filecontrollers import TestCaseFileController 

64 if isinstance(context, TestCaseFileController): 

65 return""" 

66 for imp in context.get_where_used(): 1hi

67 yield ResourceUsage(context, imp) 1hi

68 

69 

70class FindTestFolderUsages(_Command): 1ab

71 

72 def execute(self, context): 1ab

73 for imp in context.get_where_used(): 

74 yield ResourceUsage(*imp) 

75 

76 

77class ResourceUsage(object): 1ab

78 

79 def __init__(self, resource, imp): 1ab

80 self.res_name = resource.name 1hi

81 self.res_src = resource.source 1hi

82 user = imp.datafile_controller 1hi

83 self.location = user.filename 1hi

84 self.name = user.display_name 1hi

85 self.item = user.imports 1hi

86 self.parent = user 1hi

87 self.can_be_renamed = imp.contains_filename(os.path.basename(resource.filename)) 1hi