Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for known future annotations failure #132

Merged
merged 1 commit into from Oct 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions tests/test_custom_converters_future.py
@@ -1,27 +1,31 @@
# pylint: disable=arguments-differ
# pylint: disable=arguments-differ,no-member

from __future__ import annotations # this breaks custom converter lookup

from datetime import datetime
from typing import Optional

import pytest

from datafiles import Missing, datafile
from datafiles import datafile

from .test_custom_converters import MyDateTime


@pytest.mark.flaky
def test_extension(expect):
@datafile("../tmp/sample.yml")
class Timestamp:
dt: MyDateTime
class MyObject:
value: MyDateTime

ts = Timestamp(MyDateTime(2019, 1, 29))
expect(ts.datafile.text) == "dt: '2019-01-29T00:00:00'\n"
x = MyObject(MyDateTime(2019, 1, 29))
expect(x.datafile.text) == "value: '2019-01-29T00:00:00'\n"

ts = Timestamp(Missing) # type: ignore
expect(ts.dt) == datetime(2019, 1, 29)

ts.datafile.text = "dt: '2019-01-11T00:00:00'\n"
expect(ts.dt.day) == 11
@pytest.mark.xfail(reason='https://github.com/jacebrowning/datafiles/issues/131')
def test_optional(expect):
@datafile("../tmp/sample.yml")
class MyObject:
value: Optional[int]

x = MyObject(42)
expect(x.datafile.text) == "value: 42'\n"