skips.py
Go to the documentation of this file.
1 # Copyright 2022 The gRPC Authors
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 """The classes and predicates to assist validate test config for test cases."""
15 from dataclasses import dataclass
16 import enum
17 import logging
18 import re
19 from typing import Callable, Optional
20 import unittest
21 
22 from packaging import version as pkg_version
23 
24 from framework import xds_flags
25 from framework import xds_k8s_flags
26 
27 logger = logging.getLogger(__name__)
28 
29 
30 class Lang(enum.Flag):
31  UNKNOWN = enum.auto()
32  CPP = enum.auto()
33  GO = enum.auto()
34  JAVA = enum.auto()
35  PYTHON = enum.auto()
36  NODE = enum.auto()
37 
38  def __str__(self):
39  return str(self.name).lower()
40 
41  @classmethod
42  def from_string(cls, lang: str):
43  try:
44  return cls[lang.upper()]
45  except KeyError:
46  return cls.UNKNOWN
47 
48 
49 @dataclass
50 class TestConfig:
51  """Describes the config for the test suite."""
52  client_lang: Lang
53  server_lang: Lang
54  version: Optional[str]
55 
56  def version_gte(self, another: str) -> bool:
57  """Returns a bool for whether the version is >= another one.
58 
59  A version is greater than or equal to another version means its version
60  number is greater than or equal to another version's number. Version
61  "master" is always considered latest.
62  E.g., master >= v1.41.x >= v1.40.x >= v1.9.x.
63 
64  Unspecified version is treated as 'master', but isn't explicitly set.
65  """
66  if self.version == 'master' or self.version is None:
67  return True
68  if another == 'master':
69  return False
70  return self._parse_version(self.version) >= self._parse_version(another)
71 
72  def __str__(self):
73  return (f"TestConfig(client_lang='{self.client_lang}', "
74  f"server_lang='{self.server_lang}', version={self.version!r})")
75 
76  @staticmethod
77  def _parse_version(s: str) -> pkg_version.Version:
78  if s.endswith(".x"):
79  s = s[:-2]
80  return pkg_version.Version(s)
81 
82 
83 def _get_lang(image_name: str) -> Lang:
84  return Lang.from_string(
85  re.search(r'/(\w+)-(client|server):', image_name).group(1))
86 
87 
88 def evaluate_test_config(check: Callable[[TestConfig], bool]) -> None:
89  """Evaluates the test config check against Abseil flags."""
90  # NOTE(lidiz) a manual skip mechanism is needed because absl/flags
91  # cannot be used in the built-in test-skipping decorators. See the
92  # official FAQs:
93  # https://abseil.io/docs/python/guides/flags#faqs
94  test_config = TestConfig(
95  client_lang=_get_lang(xds_k8s_flags.CLIENT_IMAGE.value),
96  server_lang=_get_lang(xds_k8s_flags.SERVER_IMAGE.value),
97  version=xds_flags.TESTING_VERSION.value)
98  if not check(test_config):
99  logger.info('Skipping %s', test_config)
100  raise unittest.SkipTest(f'Unsupported test config: {test_config}')
101 
102  logger.info('Detected language and version: %s', test_config)
framework.helpers.skips.Lang
Definition: skips.py:30
xds_interop_client.str
str
Definition: xds_interop_client.py:487
framework.helpers.skips.TestConfig.__str__
def __str__(self)
Definition: skips.py:72
framework.helpers.skips.Lang.__str__
def __str__(self)
Definition: skips.py:38
framework.helpers.skips.TestConfig._parse_version
pkg_version.Version _parse_version(str s)
Definition: skips.py:77
framework.helpers.skips.TestConfig
Definition: skips.py:50
framework.helpers.skips.TestConfig.version_gte
bool version_gte(self, str another)
Definition: skips.py:56
framework.helpers.skips.Lang.UNKNOWN
UNKNOWN
Definition: skips.py:31
framework.helpers.skips.TestConfig.version
version
Definition: skips.py:66
upload.group
group
Definition: bloaty/third_party/googletest/googlemock/scripts/upload.py:397
framework.helpers.skips._get_lang
Lang _get_lang(str image_name)
Definition: skips.py:83
framework.helpers.skips.evaluate_test_config
None evaluate_test_config(Callable[[TestConfig], bool] check)
Definition: skips.py:88
check
static void check(upb_inttable *t)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:1715
framework.helpers.skips.Lang.from_string
def from_string(cls, str lang)
Definition: skips.py:42


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:18