Codebase list python-procrunner / 2b81c43
Deprecate the debug= parameter (#63) Markus Gerstel authored 3 years ago GitHub committed 3 years ago
3 changed file(s) with 27 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
77 list as the first argument) is now deprecated. As a number of arguments
88 will be removed in a future version the use of unnamed arguments will
99 cause future confusion. `Use explicit keyword arguments instead (#62). <https://github.com/DiamondLightSource/python-procrunner/pull/62>`_
10 * The run() function debug argument has been deprecated. This is only
11 only used to debug the NonBlockingStream* classes. Those are due to be
12 replaced in a future release, so the argument will no longer serve a
13 purpose. Debugging information remains available via standard logging
14 mechanisms.
1015
1116 2.1.0 (2020-09-05)
1217 ------------------
209209 self._buffer = data
210210 self._buffer_len = len(data)
211211 self._buffer_pos = 0
212 self._debug = debug
213212 self._max_block_len = 4096
214213 self._stream = stream
215214 self._terminated = False
432431 def run(
433432 command,
434433 timeout=None,
435 debug=False,
434 debug=None,
436435 stdin=None,
437436 print_stdout=True,
438437 print_stderr=True,
452451
453452 :param array command: Command line to be run, specified as array.
454453 :param timeout: Terminate program execution after this many seconds.
455 :param boolean debug: Enable further debug messages.
454 :param boolean debug: Enable further debug messages. (deprecated)
456455 :param stdin: Optional bytestring that is passed to command stdin.
457456 :param boolean print_stdout: Pass stdout through to sys.stdout.
458457 :param boolean print_stderr: Pass stderr through to sys.stderr.
486485 else:
487486 assert sys.platform != "win32", "stdin argument not supported on Windows"
488487 stdin_pipe = subprocess.PIPE
488 if debug is not None:
489 warnings.warn(
490 "Use of the debug parameter is deprecated", DeprecationWarning, stacklevel=3
491 )
489492
490493 start_time = timeit.default_timer()
491494 if timeout is not None:
494497 warnings.warn(
495498 "Using procrunner with timeout and without raise_timeout_exception set is deprecated",
496499 DeprecationWarning,
497 stacklevel=2,
500 stacklevel=3,
498501 )
499502
500503 if environment is not None:
4141 task = ["___"]
4242
4343 with pytest.raises(RuntimeError):
44 procrunner.run(task, timeout=-1, debug=False, raise_timeout_exception=True)
44 procrunner.run(task, timeout=-1, raise_timeout_exception=True)
4545
4646 assert mock_subprocess.Popen.called
4747 assert mock_process.terminate.called
8383 actual = procrunner.run(
8484 command,
8585 timeout=0.5,
86 debug=False,
8786 callback_stdout=mock.sentinel.callback_stdout,
8887 callback_stderr=mock.sentinel.callback_stderr,
8988 working_directory=mock.sentinel.cwd,
9897 mock.call(
9998 stream_stdout,
10099 output=mock.ANY,
101 debug=mock.ANY,
100 debug=None,
102101 notify=mock.ANY,
103102 callback=mock.sentinel.callback_stdout,
104103 ),
105104 mock.call(
106105 stream_stderr,
107106 output=mock.ANY,
108 debug=mock.ANY,
107 debug=None,
109108 notify=mock.ANY,
110109 callback=mock.sentinel.callback_stderr,
111110 ),
127126 def test_default_process_environment_is_parent_environment(mock_subprocess):
128127 mock_subprocess.Popen.side_effect = NotImplementedError() # cut calls short
129128 with pytest.raises(NotImplementedError):
130 procrunner.run(
131 [mock.Mock()], timeout=-1, debug=False, raise_timeout_exception=True
132 )
129 procrunner.run([mock.Mock()], timeout=-1, raise_timeout_exception=True)
133130 assert mock_subprocess.Popen.call_args[1]["env"] == os.environ
131
132
133 @mock.patch("procrunner.subprocess")
134 def test_using_debug_parameter_raises_warning(mock_subprocess):
135 mock_subprocess.Popen.side_effect = NotImplementedError() # cut calls short
136 with pytest.warns(DeprecationWarning, match="debug"):
137 with pytest.raises(NotImplementedError):
138 procrunner.run([mock.Mock()], debug=True)
139 with pytest.warns(DeprecationWarning, match="debug"):
140 with pytest.raises(NotImplementedError):
141 procrunner.run([mock.Mock()], debug=False)
134142
135143
136144 @mock.patch("procrunner.subprocess")
142150 procrunner.run(
143151 [mock.Mock()],
144152 timeout=-1,
145 debug=False,
146153 environment=copy.copy(mock_env),
147154 raise_timeout_exception=True,
148155 )
159166 procrunner.run(
160167 [mock.Mock()],
161168 timeout=-1,
162 debug=False,
163169 environment=copy.copy(mock_env1),
164170 environment_override=copy.copy(mock_env2),
165171 raise_timeout_exception=True,
177183 procrunner.run(
178184 [mock.Mock()],
179185 timeout=-1,
180 debug=False,
181186 environment_override=copy.copy(mock_env2),
182187 raise_timeout_exception=True,
183188 )
206211 procrunner.run(
207212 [mock.Mock()],
208213 timeout=-1,
209 debug=False,
210214 environment_override={
211215 random_environment_variable: "X" + random_environment_value
212216 },