Skip to content

Commit

Permalink
Merge e2434f6 into ae015ca
Browse files Browse the repository at this point in the history
  • Loading branch information
cenouralm committed Oct 23, 2020
2 parents ae015ca + e2434f6 commit 5a68bbf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 0 additions & 2 deletions marshmallow_utils/fields/edtfdatestring.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def _parse_date_string(self, datestring):
parser = level0Expression("level0")
try:
result = parser.parseString(datestring)
if not result:
raise ParseException()

# check it is chronological if interval
# NOTE: EDTF Date and Interval both have same interface
Expand Down
29 changes: 29 additions & 0 deletions tests/test_edtfdatestring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 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 marshmallow import Schema, ValidationError

from marshmallow_utils.fields import EDTFDateString


class MySchema(Schema):
edtfdate = EDTFDateString()


@pytest.mark.parametrize('date, expected_date',
[("2020-01-02garbage", "2020-01-02"),
("2020-01-45", "2020-01")])
def test_deserialize_assert(date, expected_date):
assert MySchema().load({'edtfdate': date}) == {'edtfdate': expected_date}


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

0 comments on commit 5a68bbf

Please sign in to comment.