Coverage for src/robotide/contrib/testrunner/CommandArgs.py: 98%

65 statements  

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

1# Copyright 2010 Orbitz WorldWide 

2# 

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

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

5# You may obtain a copy of the License at 

6# 

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

8# 

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

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

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

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

13# limitations under the License. 

14 

15# Modified by NSN 

16# Copyright 2010-2012 Nokia Solutions and Networks 

17# Copyright 2013-2015 Nokia Networks 

18# Copyright 2016- Robot Framework Foundation 

19# 

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

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

22# You may obtain a copy of the License at 

23# 

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

25# 

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

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

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

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

30# limitations under the License. 

31 

32# Have to use short options in some methods, because of long option was changed 

33# in RF 2.8 -> 2.9, and we don't necessarily know the installed version. 

34 

35 

36class CommandArgs: 

37 def __init__(self): 

38 self._existing_args = [] 1fdbegach

39 self._args = [] 1fdbegach

40 self._without_console_color = False 1fdbegach

41 self._tests_to_run = [] 1fdbegach

42 self._python_paths = [] 1fdbegach

43 self._console_width = '' 1fdbegach

44 self._output_directory = '' 1fdbegach

45 self._log_level = '' 1fdbegach

46 

47 def with_existing_args(self, args): 

48 self._existing_args = args 1dbac

49 return self 1dbac

50 

51 def with_python_path(self, paths): 

52 self._python_paths = paths 1dbac

53 return self 1dbac

54 

55 def with_log_level(self, log_level): 

56 self._log_level = log_level 1dbeac

57 return self 1dbeac

58 

59 def with_output_directory(self, output_directory): 

60 self._output_directory = output_directory 1dbac

61 return self 1dbac

62 

63 def with_runnable_tests(self, tests): 

64 self._tests_to_run.clear() 1a

65 for suite, test in tests: 1a

66 self._tests_to_run += ['--suite', suite, '--test', test] 1a

67 return self 1a

68 

69 def without_console_color(self, without_colors=True): 

70 self._without_console_color = without_colors 1fdbegach

71 return self 1fdbegach

72 

73 def with_console_width(self, console_width): 

74 self._console_width = console_width 1dbac

75 return self 1dbac

76 

77 def build(self): 

78 if self._existing_args: 1fdbegach

79 self._args.extend(self._existing_args) 1dbc

80 

81 if self._is_necessary_disable_console_color(): 1fdbegach

82 self._args.extend(['-C', 'off']) 1egach

83 

84 if self._is_necessary_add_console_color(): 1fdbegach

85 from sys import platform 1fb

86 if platform.endswith('win32'): 86 ↛ 87line 86 didn't jump to line 87 because the condition on line 86 was never true1fb

87 self._args.extend(['-C', 'ansi']) 

88 else: 

89 self._args.extend(['-C', 'on']) 1fb

90 

91 if self._is_necessary_add_console_width(): 1fdbegach

92 self._args.extend(['-W', self._console_width]) 1a

93 

94 if self._is_necessary_add_python_paths(): 1fdbegach

95 self._args.extend( 1a

96 ['-P', ':'.join(self._python_paths)]) 

97 

98 if self._is_necessary_add_output_dir(): 1fdbegach

99 self._args.extend(['-d', self._output_directory]) 1a

100 

101 if self._is_necessary_add_log_level(): 1fdbegach

102 self._args.extend(['-L', self._log_level]) 1ea

103 

104 self._args.extend(self._tests_to_run) 1fdbegach

105 

106 return self._args 1fdbegach

107 

108 def _is_necessary_disable_console_color(self): 

109 return self._without_console_color and \ 1fdbegach

110 '-C' not in self._args and \ 

111 '--consolecolors' not in self._args 

112 

113 def _is_necessary_add_console_color(self): 

114 return not self._without_console_color and \ 1fdbegach

115 '-C' not in self._args and \ 

116 '--consolecolors' not in self._args 

117 

118 def _is_necessary_add_console_width(self): 

119 return self._console_width and \ 1fdbegach

120 '-W' not in self._args and \ 

121 '--consolewidth' not in self._args 

122 

123 def _is_necessary_add_python_paths(self): 

124 return self._python_paths and \ 1fdbegach

125 '-P' not in self._args and \ 

126 '--pythonpath' not in self._args 

127 

128 def _is_necessary_add_output_dir(self): 

129 return self._output_directory and \ 1fdbegach

130 '-d' not in self._args and \ 

131 '--outputdir' not in self._args 

132 

133 def _is_necessary_add_log_level(self): 

134 return self._log_level and \ 1fdbegach

135 '-L' not in self._args and \ 

136 '--loglevel' not in self._args