Projects
Eulaceura:Factory
python-pytest-xprocess
_service:obs_scm:0002-remove-support-for-callba...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:0002-remove-support-for-callback.patch of Package python-pytest-xprocess
From d8f714c005a13cc3b1a00f6b65c53f63ca0e03c4 Mon Sep 17 00:00:00 2001 From: wang__ge <wang__ge@126.com> Date: Thu, 29 Aug 2024 11:36:14 +0800 Subject: [PATCH] remove support for callback --- tests/test_process_initialization.py | 106 +++++++++++++-------------- xprocess/xprocess.py | 56 +++++++------- 2 files changed, 83 insertions(+), 79 deletions(-) diff --git a/tests/test_process_initialization.py b/tests/test_process_initialization.py index 03a7c49..8567f97 100644 --- a/tests/test_process_initialization.py +++ b/tests/test_process_initialization.py @@ -118,56 +118,56 @@ def test_popen_kwargs(tcp_port, proc_name, xprocess): info.terminate() -@pytest.mark.parametrize("proc_name", ["s1", "s2", "s3"]) -def test_startup_without_pattern(tcp_port, proc_name, xprocess): - data = "bacon\n" - - class Starter(ProcessStarter): - args = [sys.executable, server_path, tcp_port, "--no-children"] - - def startup_check(self): - return request_response_cycle(tcp_port, data) - - xprocess.ensure(proc_name, Starter) - info = xprocess.getinfo(proc_name) - assert info.isrunning() - info.terminate() - - -@pytest.mark.parametrize( - "proc_name,proc_pttrn,lines", - [ - ("s1", "will not match", 21), - ("s2", "spam, bacon, eggs", 30), - ("s3", "finally started", 130), - ], -) -def test_startup_with_pattern_and_callback( - tcp_port, proc_name, proc_pttrn, lines, xprocess -): - data = "bacon\n" - - class Starter(ProcessStarter): - pattern = proc_pttrn - max_read_lines = lines - args = [sys.executable, server_path, tcp_port, "--no-children"] - - def startup_check(self): - return request_response_cycle(tcp_port, data) - - if proc_name == "s1": - with pytest.raises(RuntimeError): - xprocess.ensure(proc_name, Starter) - # since we made xprocess fail to start the server on purpose, we cannot - # terminate it using XProcessInfo.terminate method once it does not - # know the PID, process name or even that it is running, so we tell the - # server to terminate itself. - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: - sock.connect(("localhost", tcp_port)) - sock.sendall(bytes("exit\n", "utf-8")) - else: - xprocess.ensure(proc_name, Starter) - info = xprocess.getinfo(proc_name) - assert info.isrunning() - assert request_response_cycle(tcp_port, data) - info.terminate() +#@pytest.mark.parametrize("proc_name", ["s1", "s2", "s3"]) +#def test_startup_without_pattern(tcp_port, proc_name, xprocess): +# data = "bacon\n" + +# class Starter(ProcessStarter): +# args = [sys.executable, server_path, tcp_port, "--no-children"] + +# def startup_check(self): +# return request_response_cycle(tcp_port, data) + +# xprocess.ensure(proc_name, Starter) +# info = xprocess.getinfo(proc_name) +# assert info.isrunning() +# info.terminate() + + +#@pytest.mark.parametrize( +# "proc_name,proc_pttrn,lines", +# [ +# ("s1", "will not match", 21), +# ("s2", "spam, bacon, eggs", 30), +# ("s3", "finally started", 130), +# ], +#) +#def test_startup_with_pattern_and_callback( +# tcp_port, proc_name, proc_pttrn, lines, xprocess +#): +# data = "bacon\n" + +# class Starter(ProcessStarter): +# pattern = proc_pttrn +# max_read_lines = lines +# args = [sys.executable, server_path, tcp_port, "--no-children"] + +# def startup_check(self): +# return request_response_cycle(tcp_port, data) + +# if proc_name == "s1": +# with pytest.raises(RuntimeError): +# xprocess.ensure(proc_name, Starter) +# # since we made xprocess fail to start the server on purpose, we cannot +# # terminate it using XProcessInfo.terminate method once it does not +# # know the PID, process name or even that it is running, so we tell the +# # server to terminate itself. +# with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: +# sock.connect(("localhost", tcp_port)) +# sock.sendall(bytes("exit\n", "utf-8")) +# else: +# xprocess.ensure(proc_name, Starter) +# info = xprocess.getinfo(proc_name) +# assert info.isrunning() +# assert request_response_cycle(tcp_port, data) +# info.terminate() diff --git a/xprocess/xprocess.py b/xprocess/xprocess.py index 0df85f4..98388bc 100644 --- a/xprocess/xprocess.py +++ b/xprocess/xprocess.py @@ -360,7 +360,7 @@ class ProcessStarter(ABC): terminate_on_interrupt = False def __init__(self, control_dir, process): - self._max_time = None + #self._max_time = None self.control_dir = control_dir self.process = process @@ -368,12 +368,13 @@ class ProcessStarter(ABC): @abstractmethod def args(self): """The args to start the process.""" - pass + #pass @property + @abstractmethod def pattern(self): """The pattern to match when the process has started.""" - return None + #return None def startup_check(self): """Used to assert process responsiveness after pattern match""" @@ -398,31 +399,34 @@ class ProcessStarter(ABC): def wait(self, log_file): """Wait until the pattern is matched or callback returns successful.""" - has_callback = type(self).startup_check != ProcessStarter.startup_check - has_pattern = self.pattern is not None - # cut it short, at least one provided way to - # know if the process has started - if not has_callback and not has_pattern: - return False - # here we know that at least one of them has been provided - pattern_ok, callback_ok = False, False + #has_callback = type(self).startup_check != ProcessStarter.startup_check + #has_pattern = self.pattern is not None + ## cut it short, at least one provided way to + ## know if the process has started + #if not has_callback and not has_pattern: + # return False + ## here we know that at least one of them has been provided + #pattern_ok, callback_ok = False, False self._max_time = datetime.now() + timedelta(seconds=self.timeout) - if has_pattern: - pattern_ok = self.wait_pattern(log_file) - if has_callback: - callback_ok = self.wait_callback() - # when both provided, both should be checked - if has_callback and has_pattern: - return pattern_ok and callback_ok - # one or the other - return pattern_ok or callback_ok - - def wait_pattern(self, log_file): - """Wait until the pattern is mached and callback returns successful.""" - raw_lines = self.get_lines(log_file) - lines = map(self.log_line, self.filter_lines(raw_lines)) + lines = map(self.log_line, self.filter_lines(self.get_lines(log_file))) + #if has_pattern: + # pattern_ok = self.wait_pattern(log_file) + #if has_callback: + # callback_ok = self.wait_callback() + ## when both provided, both should be checked + #if has_callback and has_pattern: + # return pattern_ok and callback_ok + ## one or the other + #return pattern_ok or callback_ok + + #def wait_pattern(self, log_file): + #"""Wait until the pattern is mached and callback returns successful.""" + #raw_lines = self.get_lines(log_file) + #lines = map(self.log_line, self.filter_lines(raw_lines)) has_match = any(re.search(self.pattern, line) for line in lines) - return has_match + process_ready = self.wait_callback() + return has_match and process_ready + #return has_match def filter_lines(self, lines): """fetch first <max_read_lines>, ignoring blank lines.""" -- 2.43.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2