Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Nov 25, 2024
1 parent 1c82c73 commit 34d0101
Showing 1 changed file with 45 additions and 12 deletions.
57 changes: 45 additions & 12 deletions tests/test_atproto_client/models/tests/test_string_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,28 @@


# TODO: 230 passed, 11 xfailed
# not yet entirely sure on these remaining failures:
# - AT-URI validation may be too strict
# - DateTime validation needs to handle more ISO8601 formats
# - Handle/NSID validation rules may need updating
# These cases appear in both _valid.txt and _invalid.txt files.
# Need investigation to determine if our validation is incorrect or if test data needs updating:
SKIP_THESE_VALUES = [
'at://did:plc:asdf123', # Appears valid - may need to update AT-URI validation rules
'at://did:plc:asdf123/com.atproto.feed.post', # Appears valid - may need to update AT-URI validation rules
'1985-04-12T23:20:50.123Z', # Valid ISO8601 - validator may be too strict
'1985-04-12T23:20:50.123-00:00', # Valid ISO8601 with offset - validator may be too strict
'1985-04-12T23:20Z', # Valid ISO8601 without seconds - validator may be too strict
'john.test', # Appears valid - may need to update handle validation
'one.two.three', # Appears valid - may need to update NSID validation
(
string_formats.AtUri,
'at://did:plc:asdf123',
), # Listed as both valid and invalid in AT-URI files under "enforces spec basics"
(
string_formats.AtUri,
'at://did:plc:asdf123/com.atproto.feed.post',
), # Same AT-URI pattern - appears in both valid/invalid files
(
string_formats.DateTime,
'1985-04-12T23:20:50.123Z',
), # Listed as "preferred" in valid but also appears in invalid under RFC-3339 section
(
string_formats.DateTime,
'1985-04-12T23:20:50.123-00:00',
), # Listed as "supported" in valid but marked invalid under timezone formats
(string_formats.DateTime, '1985-04-12T23:20Z'), # Similar timezone format discrepancy between valid/invalid files
(string_formats.Handle, 'john.test'), # Base pattern appears valid but numeric suffix versions are marked invalid
(string_formats.Nsid, 'one.two.three'), # Same pattern - base form valid but numeric suffixes marked invalid
]


Expand Down Expand Up @@ -145,7 +155,7 @@ def test_string_format_validation(
validator_type: type, field_name: str, error_keywords: List[str], invalid_value: str, valid_data: dict
) -> None:
"""Test validation for each string format type."""
if invalid_value in SKIP_THESE_VALUES:
if any(invalid_value == skip_value for _, skip_value in SKIP_THESE_VALUES):
pytest.xfail(f'TODO: Fix validation for {invalid_value}')

SomeTypeAdapter = TypeAdapter(validator_type)
Expand Down Expand Up @@ -222,3 +232,26 @@ class FooModel(BaseModel):
assert isinstance(instance, FooModel)
assert instance.handle == invalid_data['handle']
assert instance.did == invalid_data['did']


@pytest.mark.parametrize('validator_type,value', SKIP_THESE_VALUES)
def test_skipped_validation_cases(validator_type: type, value: str) -> None:
"""
Test each skipped case that we suspect is a discrepancy between valid/invalid test files
"""
_TAdapter = TypeAdapter(validator_type)

# Should validate successfully with strict validation
validated = _TAdapter.validate_python(value, context={_OPT_IN_KEY: True})
assert validated == value

# Also verify it appears in the corresponding invalid test file
invalid_filename = {
string_formats.AtUri: 'aturi_syntax_invalid.txt',
string_formats.DateTime: 'datetime_syntax_invalid.txt',
string_formats.Handle: 'handle_syntax_invalid.txt',
string_formats.Nsid: 'nsid_syntax_invalid.txt',
}[validator_type]

invalid_cases = get_test_cases(invalid_filename)
assert value in invalid_cases, f'{value} not found in {invalid_filename} despite being marked as invalid'

0 comments on commit 34d0101

Please sign in to comment.