Skip to content

Commit f36a9bd

Browse files
committed
test: revert assertStartsWith and clean up pre-existing flake8 lints
- Revert assertStartsWith (Python 3.13+ only) back to self.assertTrue(msg.startswith(...), msg) at all 5 call sites so the shutdown checks work on the current test environment. - Drop the file-level "# flake8: noqa" and fix the pre-existing lints in lifecycle_test.py that surfaced after #8897 corrected pre-commit flake8 arg parsing: * E402: add per-import "# noqa: E402" to imports that must live after sys.path.append("../common") * F841: drop unused "md" and "tensor_shape" locals * E266: normalize "##" block comments to "#" * E721: replace "type(x) == T" with isinstance(x, T) * E712: replace "== False" with "is False" * E711: replace "!= None" with "is not None" * F401: drop unused "HTTPConnectionClosed" local import
1 parent 9165630 commit f36a9bd

1 file changed

Lines changed: 37 additions & 37 deletions

File tree

qa/L0_lifecycle/lifecycle_test.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,30 @@
2626
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

29-
# flake8: noqa
30-
3129
import sys
3230

3331
sys.path.append("../common")
3432

35-
import base64
36-
import concurrent.futures
37-
import json
38-
import multiprocessing
39-
import os
40-
import shutil
41-
import signal
42-
import threading
43-
import time
44-
import unittest
45-
from builtins import range
46-
from functools import partial
47-
from pathlib import Path
48-
49-
import infer_util as iu
50-
import numpy as np
51-
import test_util as tu
52-
import tritonclient.grpc as grpcclient
53-
import tritonclient.http as httpclient
54-
from tritonclient.utils import InferenceServerException
33+
import base64 # noqa: E402
34+
import concurrent.futures # noqa: E402
35+
import json # noqa: E402
36+
import multiprocessing # noqa: E402
37+
import os # noqa: E402
38+
import shutil # noqa: E402
39+
import signal # noqa: E402
40+
import threading # noqa: E402
41+
import time # noqa: E402
42+
import unittest # noqa: E402
43+
from builtins import range # noqa: E402
44+
from functools import partial # noqa: E402
45+
from pathlib import Path # noqa: E402
46+
47+
import infer_util as iu # noqa: E402
48+
import numpy as np # noqa: E402
49+
import test_util as tu # noqa: E402
50+
import tritonclient.grpc as grpcclient # noqa: E402
51+
import tritonclient.http as httpclient # noqa: E402
52+
from tritonclient.utils import InferenceServerException # noqa: E402
5553

5654

5755
class LifeCycleTest(tu.TestResultCollector):
@@ -310,7 +308,7 @@ def test_parse_error_no_model_config(self):
310308
self.assertTrue(triton_client.is_server_live())
311309
self.assertTrue(triton_client.is_server_ready())
312310

313-
md = triton_client.get_model_metadata(model_name, "1")
311+
triton_client.get_model_metadata(model_name, "1")
314312
self.assertTrue(
315313
False,
316314
"expected model '"
@@ -2258,7 +2256,6 @@ def test_multiple_model_repository_control_startup_models(self):
22582256
def test_model_repository_index(self):
22592257
# use model control EXPLICIT and --load-model to load a subset of models
22602258
# in model repository
2261-
tensor_shape = (1, 16)
22622259
model_bases = ["plan", "libtorch", "simple_libtorch"]
22632260

22642261
# Sanity check on loaded models
@@ -2580,8 +2577,8 @@ def test_file_override_security(self):
25802577
self.assertTrue(os.path.exists(os.path.join(model_basepath, existing_file_rel)))
25812578

25822579
# Symlinks
2583-
## No easy way to inject symlink into generated temp model dir, so for
2584-
## testing sake, make a fixed symlink path in /tmp.
2580+
# No easy way to inject symlink into generated temp model dir, so for
2581+
# testing sake, make a fixed symlink path in /tmp.
25852582
escape_dir_symlink_rel = os.path.join("..", "escape_symlink")
25862583
escape_dir_symlink_full = "/tmp/escape_symlink"
25872584
self.assertEqual(
@@ -2676,7 +2673,7 @@ def callback(user_data, result, error):
26762673
self.assertTrue(False, "expected error for new inference during shutdown")
26772674
except InferenceServerException as ex:
26782675
msg = ex.message()
2679-
self.assertStartsWith(self._GRPC_CONNECTION_REFUSED_PREFIX, msg)
2676+
self.assertTrue(msg.startswith(self._GRPC_CONNECTION_REFUSED_PREFIX), msg)
26802677

26812678
# Wait until the results are available in user_data
26822679
time_out = 30
@@ -2686,7 +2683,7 @@ def callback(user_data, result, error):
26862683

26872684
# Previous requests should succeed
26882685
for result in async_results:
2689-
if type(result) == InferenceServerException:
2686+
if isinstance(result, InferenceServerException):
26902687
raise result
26912688
output_data = result.as_numpy("OUTPUT0")
26922689
np.testing.assert_allclose(
@@ -2740,21 +2737,23 @@ def callback(user_data, result, error):
27402737
# each subsequent request returns Connection refused
27412738
msg = ex.message()
27422739
if "CANCELLED" not in msg:
2743-
self.assertStartsWith(self._GRPC_CONNECTION_REFUSED_PREFIX, msg)
2740+
self.assertTrue(
2741+
msg.startswith(self._GRPC_CONNECTION_REFUSED_PREFIX), msg
2742+
)
27442743
# 2: New sequence with existing sequence ID
27452744
try:
27462745
triton_client.infer(model_name, inputs, sequence_id=1, sequence_start=True)
27472746
self.assertTrue(False, "expected error for new inference during shutdown")
27482747
except InferenceServerException as ex:
27492748
msg = ex.message()
2750-
self.assertStartsWith(self._GRPC_CONNECTION_REFUSED_PREFIX, msg)
2749+
self.assertTrue(msg.startswith(self._GRPC_CONNECTION_REFUSED_PREFIX), msg)
27512750
# 3: Continuing sequence after shutdown
27522751
try:
27532752
triton_client.infer(model_name, inputs, sequence_id=2, sequence_end=True)
27542753
self.assertTrue(False, "expected error for new inference during shutdown")
27552754
except InferenceServerException as ex:
27562755
msg = ex.message()
2757-
self.assertStartsWith(self._GRPC_CONNECTION_REFUSED_PREFIX, msg)
2756+
self.assertTrue(msg.startswith(self._GRPC_CONNECTION_REFUSED_PREFIX), msg)
27582757

27592758
# Wait until the results are available in user_data
27602759
time_out = 30
@@ -2764,7 +2763,7 @@ def callback(user_data, result, error):
27642763

27652764
# Previous requests should succeed
27662765
for result in async_results:
2767-
if type(result) == InferenceServerException:
2766+
if isinstance(result, InferenceServerException):
27682767
raise result
27692768
output_data = result.as_numpy("OUTPUT")
27702769
np.testing.assert_allclose(
@@ -2814,7 +2813,7 @@ def callback(user_data, result, error):
28142813
self.assertTrue(False, "expected error for new inference during shutdown")
28152814
except InferenceServerException as ex:
28162815
msg = ex.message()
2817-
self.assertStartsWith(self._GRPC_CONNECTION_REFUSED_PREFIX, msg)
2816+
self.assertTrue(msg.startswith(self._GRPC_CONNECTION_REFUSED_PREFIX), msg)
28182817

28192818
# Wait until the results are available in user_data
28202819
time_out = 10
@@ -2824,7 +2823,7 @@ def callback(user_data, result, error):
28242823

28252824
# Previous requests should succeed
28262825
for result in async_results:
2827-
if type(result) == InferenceServerException:
2826+
if isinstance(result, InferenceServerException):
28282827
raise result
28292828
output_data = result.as_numpy("OUTPUT0")
28302829
np.testing.assert_allclose(
@@ -3070,7 +3069,7 @@ def _load_unload():
30703069
# This test can replicate a load while async unloading on machines with
30713070
# sufficient concurrency. Regardless on whether it is replicated or not,
30723071
# the server must not crash.
3073-
if load_before_unload_finish[0] == False:
3072+
if load_before_unload_finish[0] is False:
30743073
# Track non-replication on test printout via statistics.
30753074
warning_msg = "Cannot replicate a load while async unloading. CPU count: {}. num_threads: {}.".format(
30763075
multiprocessing.cpu_count(), num_threads
@@ -3296,7 +3295,9 @@ def test_model_config_overwite(self):
32963295
"""
32973296

32983297
# Ensure the model has been loaded w/ the expected (different from override) config.
3299-
self.assertTrue(original_config != None and original_config != override_config)
3298+
self.assertTrue(
3299+
original_config is not None and original_config != override_config
3300+
)
33003301

33013302
# Reload the model with the overriding configuration value.
33023303
triton_client.load_model(model_name, config=override_config)
@@ -3359,7 +3360,6 @@ def test_shutdown_while_loading(self):
33593360
def test_shutdown_with_live_connection(self):
33603361
model_name = "add_sub"
33613362
model_shape = (16,)
3362-
from geventhttpclient.response import HTTPConnectionClosed
33633363

33643364
input_data = np.ones(shape=model_shape, dtype=np.float32)
33653365
inputs = [

0 commit comments

Comments
 (0)