Skip to content

Commit

Permalink
Clean up and PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan343 committed Feb 3, 2025
1 parent 5d9bb32 commit 843f61c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
8 changes: 4 additions & 4 deletions botocore/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class ResponseParser:
EVENT_STREAM_PARSER_CLS = None
# This is a list of known values for the "location" key in the
# serialization dict. The location key tells us where in the response
# to parse the value.
# to parse the value. Locations not in this list will be ignored.
KNOWN_LOCATIONS = ('statusCode', 'header', 'headers')

def __init__(self, timestamp_parser=None, blob_parser=None):
Expand Down Expand Up @@ -590,7 +590,7 @@ def _do_parse(self, response, shape):
return self._parse_body_as_xml(response, shape, inject_metadata=True)

def _parse_body_as_xml(self, response, shape, inject_metadata=True):
xml_contents = response['body'] or b'<xml/>'
xml_contents = response['body']
root = self._parse_xml_string_to_dom(xml_contents)
parsed = {}
if shape is not None:
Expand Down Expand Up @@ -723,7 +723,7 @@ def _do_error_parse(self, response, shape):
if ':' in code:
code = code.split(':', 1)[0]
if '#' in code:
code = code.split('#', 1)[1]
code = code.rsplit('#', 1)[1]
if 'x-amzn-query-error' in headers:
code = self._do_query_compatible_error_parse(
code, headers, error
Expand Down Expand Up @@ -1044,7 +1044,7 @@ def _inject_error_code(self, error, response):
if ':' in code:
code = code.split(':', 1)[0]
if '#' in code:
code = code.split('#', 1)[1]
code = code.rsplit('#', 1)[1]
error['Error']['Code'] = code

def _handle_boolean(self, shape, value):
Expand Down
39 changes: 21 additions & 18 deletions tests/unit/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
To run a single test case in a suite (useful when debugging a single test), you
can set the BOTOCORE_TEST_ID env var with the ``suite_id:test_id`` syntax.
BOTOCORE_TEST_ID=5:1 pytest test/unit/test_protocols.py
BOTOCORE_TEST_ID=5:1 pytest tests/unit/test_protocols.py
"""

Expand Down Expand Up @@ -99,9 +99,6 @@
}
PROTOCOL_TEST_BLACKLIST = ['Idempotency token auto fill']
IGNORE_LIST_FILENAME = "protocol-tests-ignore-list.json"
PROTOCOL_TEST_IGNORE_LIST_PATH = os.path.join(TEST_DIR, IGNORE_LIST_FILENAME)
with open(PROTOCOL_TEST_IGNORE_LIST_PATH) as f:
PROTOCOL_TEST_IGNORE_LIST = json.load(f)


class TestType(Enum):
Expand All @@ -112,6 +109,12 @@ class TestType(Enum):
OUTPUT = "output"


def get_protocol_test_ignore_list():
ignore_list_path = os.path.join(TEST_DIR, IGNORE_LIST_FILENAME)
with open(ignore_list_path) as f:
return json.load(f)


def _compliance_tests(test_type=None):
inp = test_type is None or test_type is TestType.INPUT
out = test_type is None or test_type is TestType.OUTPUT
Expand Down Expand Up @@ -211,7 +214,9 @@ def test_output_compliance(json_description, case, basename):
body_bytes = case['response']['body'].encode('utf-8')
case['response']['body'] = body_bytes
else:
case['response']['body'] = b''
case['response']['body'] = (
b'' if protocol != "query" else b'<xml/>'
)
# We need the headers to be case insensitive
# If a test case doesn't define response headers, set it to an empty `HeadersDict`.
case['response']['headers'] = HeadersDict(
Expand Down Expand Up @@ -534,20 +539,18 @@ def _should_ignore_test(protocol, test_type, suite, case):
:return: True if the protocol test should be ignored, False otherwise.
:rtype: bool
"""
ignore_list = PROTOCOL_TEST_IGNORE_LIST.get('general', {}).get(
test_type, {}
)
ignore_suites = ignore_list.get('suites', [])
ignore_cases = ignore_list.get('cases', [])

if suite in ignore_suites or case in ignore_cases:
# Get test suites and cases to ignore for all protocols.
ignore_list = get_protocol_test_ignore_list()
general_ignore_list = ignore_list.get('general', {}).get(test_type, {})
general_suites = general_ignore_list.get('suites', [])
general_cases = general_ignore_list.get('cases', [])
if suite in general_suites or case in general_cases:
return True

# Get test suites and cases to ignore for a specific protocol.
protocol_ignore_list = (
PROTOCOL_TEST_IGNORE_LIST.get('protocols', {})
.get(protocol, {})
.get(test_type, {})
ignore_list.get('protocols', {}).get(protocol, {}).get(test_type, {})
)
protocol_ignore_suites = protocol_ignore_list.get('suites', [])
protocol_ignore_cases = protocol_ignore_list.get('cases', [])
return suite in protocol_ignore_suites or case in protocol_ignore_cases
protocol_suites = protocol_ignore_list.get('suites', [])
protocol_cases = protocol_ignore_list.get('cases', [])
return suite in protocol_suites or case in protocol_cases

0 comments on commit 843f61c

Please sign in to comment.