Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions protovalidate/internal/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,9 @@ class RuleContext:

_violations: list[Violation]

def __init__(self, *, fail_fast: bool = False, violations: typing.Optional[list[Violation]] = None):
def __init__(self, *, fail_fast: bool = False):
self._fail_fast = fail_fast
if violations is None:
violations = []
self._violations = violations
self._violations = []

@property
def violations(self) -> list[Violation]:
Expand Down
7 changes: 1 addition & 6 deletions protovalidate/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import typing

from google.protobuf import message

from buf.validate import validate_pb2
Expand Down Expand Up @@ -63,7 +61,6 @@ def collect_violations(
message: message.Message,
*,
fail_fast: bool = False,
into: typing.Optional[list[Violation]] = None,
) -> list[Violation]:
"""
Validates the given message against the static rules defined in
Expand All @@ -77,12 +74,10 @@ def collect_violations(
Parameters:
message: The message to validate.
fail_fast: If true, validation will stop after the first iteration.
into: If provided, any violations will be appended to the
Violations object and the same object will be returned.
Raises:
CompilationError: If the static rules could not be compiled.
"""
ctx = _rules.RuleContext(fail_fast=fail_fast, violations=into)
ctx = _rules.RuleContext(fail_fast=fail_fast)
for rule in self._factory.get(message.DESCRIPTOR):
rule.validate(ctx, message)
if ctx.done:
Expand Down
14 changes: 0 additions & 14 deletions test/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,6 @@ def test_oneofs(self):

self._run_valid_tests(msg)

def test_collect_violations_into(self):
msg1 = validations_pb2.Oneof()
msg1.y = 123

msg2 = validations_pb2.Oneof()
msg2.z.val = True

for label, v in get_default_validator():
with self.subTest(label=label):
# Test collect_violations into
violations = v.collect_violations(msg1)
v.collect_violations(msg2, into=violations)
self.assertEqual(len(violations), 0)

def test_protovalidate_oneof_valid(self):
msg = validations_pb2.ProtovalidateOneof()
msg.a = "A"
Expand Down