Skip to content

Commit defc7e5

Browse files
committed
test: Remove negative QName single arg test altogether
Too many false positives, even something like QName(TypeError('foo')) works
1 parent 87e6697 commit defc7e5

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

tests/runtime/test_helper.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from __future__ import annotations
22

3-
import re
43
import sys
54
from contextlib import nullcontext
65
from itertools import product
7-
from pathlib import PurePath
86
from types import NoneType
97
from typing import Any
108

119
import pytest
12-
from hypothesis import example, given, settings
10+
from hypothesis import given, settings
1311
from lxml.etree import Element, QName, _Element
1412

1513
from ._testutils import strategy as _st
@@ -88,35 +86,18 @@ def test_single_arg_ok(self, arg: Any) -> None:
8886
with raise_attr_not_writable:
8987
delattr(qn, attr)
9088

91-
# Path and Exception can stringify to anything, and QName
92-
# construction really succeed with them. Other offending
93-
# types handled in regex below
94-
@settings(max_examples=300)
95-
@given(
96-
thing=_st.all_instances_except_of_type(
97-
str, bytes, QName, _Element, NoneType, PurePath, Exception
98-
)
99-
)
100-
@example(thing=bytearray(b"foo"))
101-
def test_single_arg_bad(self, thing: Any) -> None:
102-
if len(str(thing)) == 0 or str(thing).endswith("}"):
103-
raise_cm = pytest.raises(ValueError, match=r"Empty tag name")
104-
elif re.match(r"^[A-Za-z_]([\w\.-])*$", str(thing)):
105-
# UUID, timezones, literal constants etc
106-
raise_cm = nullcontext()
107-
else:
108-
raise_cm = pytest.raises(
109-
ValueError,
110-
match=r"(Invalid tag name|All strings must be XML compatible)",
111-
)
112-
with raise_cm:
113-
_ = QName(thing)
114-
with raise_cm:
115-
_ = QName(None, thing)
89+
# Negative test for single arg is removed altogether, as there are too many
90+
# exceptions. Absurdities like QName(Path("Á")) or QName(TypeError("foo"))
91+
# works fine, not to mention True, False, Ellipsis etc which stringify to
92+
# valid XML tag names.
11693

11794
# Proves following rules:
11895
# - 2nd arg can't be QName or _Element if 1st non-empty
119-
# - Only 2nd arg can be bytearray when 1st is non-empty
96+
# - 2nd arg can be bytearray when 1st is non-empty
97+
#
98+
# As a side note, supplying bytearray as 1st arg works when 2nd arg is
99+
# non-empty, but it is almost absolutely certain users don't want to have
100+
# qualified names like {bytearray(b"foo")}bar
120101
@pytest.mark.parametrize(
121102
("arg1", "arg2"),
122103
product(arg1_choice, arg2_choice),

0 commit comments

Comments
 (0)