Skip to content

Commit

Permalink
Merge 068ff01 into 1f43dae
Browse files Browse the repository at this point in the history
  • Loading branch information
cenouralm committed Oct 21, 2020
2 parents 1f43dae + 068ff01 commit 52b13b6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
3 changes: 0 additions & 3 deletions marshmallow_utils/fields/edtfdatestring.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ def _deserialize(self, value, attr, data, **kwargs):
try:
result = parser.parseString(value)

if not result:
raise ParseException()

# check it is chronological if interval
# NOTE: EDTF Date and Interval both have same interface
# and date.lower_strict() <= date.upper_strict() is always
Expand Down
33 changes: 33 additions & 0 deletions tests/test_edtfdatestring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016-2020 CERN.
#
# Marshmallow-Utils is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

"""Test the marshmallow EDTF Date String."""

import pytest
from edtf.parser.grammar import ParseException, level0Expression
from marshmallow import Schema, ValidationError, fields

from marshmallow_utils.fields import EDTFDateString


class MySchema(Schema):
f = EDTFDateString()


@pytest.mark.parametrize('test_input, expected',
[("2020-01-02garbage", "2020-01-02"),
("2020-01-45", "2020-01")])
def test_deserialize_assert(test_input, expected):

assert MySchema().load({'f': test_input}) == {'f': expected}


@pytest.mark.parametrize('test_input_a',
[("2020-08/1998-08"),
("12-040-400")])
def test_deserialize_raiset(test_input_a):
pytest.raises(ValidationError, MySchema().load, {'f': test_input_a})

0 comments on commit 52b13b6

Please sign in to comment.