Created
May 11, 2020 15:41
-
-
Save 4OH4/7d75122b813e977be269f22c474b08ce to your computer and use it in GitHub Desktop.
Using Hypothesis to generate date objects and strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from hypothesis.strategies import dates | |
from hypothesis import given | |
from truth.truth import AssertThat | |
# Module under test | |
from app.core.worker import Worker | |
# Generate dates within the four digit year range | |
@given(input_date=dates(min_value=datetime.date(1000, 1, 1), max_value=datetime.date(9999, 1, 1))) | |
def test_worker_parseDate1_generative(mocker, input_date): | |
# given | |
input_string = input_date.strftime(format="%d%b%Y") # e.g. 01Jan2000 | |
worker = Worker() | |
# when | |
result = worker.parseDate(input_string) | |
# then: assert ISO8601 date format | |
AssertThat(result).IsInstanceOf(str) | |
AssertThat(result).HasSize(10) | |
AssertThat(result.split('-')).HasSize(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment