Skip to content

Commit

Permalink
Merge pull request #95 from jacebrowning/restore-type-tests
Browse files Browse the repository at this point in the history
Restore type integration tests
  • Loading branch information
jacebrowning committed Jan 13, 2019
2 parents b72a6a7 + 5da5ba6 commit 8ed5f37
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 6 deletions.
1 change: 1 addition & 0 deletions .pylint.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ disable=
# Handled by automatic formatting:
line-too-long,
# False positives:
no-member,
unsupported-membership-test,
cell-var-from-loop,
cyclic-import,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_auto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=unused-variable,no-member
# pylint: disable=unused-variable

import os
from dataclasses import dataclass, field
Expand Down Expand Up @@ -96,7 +96,7 @@ def with_delitem(expect, read):
def with_append(logbreak, expect, read, dedent):
sample = Sample()

logbreak()
logbreak("Appending to list")
sample.items.append(2)

expect(read('tmp/sample.yml')) == dedent(
Expand All @@ -109,7 +109,7 @@ def with_append(logbreak, expect, read, dedent):

sample.datafile.load()

logbreak()
logbreak("Appending to list")
sample.items.append(3)

expect(read('tmp/sample.yml')) == dedent(
Expand All @@ -124,7 +124,7 @@ def with_append(logbreak, expect, read, dedent):
def with_append_on_nested_dataclass(logbreak, expect, read, dedent):
sample = SampleWithNesting(1)

logbreak("Appending nested item")
logbreak("Appending to nested list")
sample.nested.items.append(2)

expect(read('tmp/sample.yml')) == dedent(
Expand All @@ -136,7 +136,7 @@ def with_append_on_nested_dataclass(logbreak, expect, read, dedent):
"""
)

logbreak("Appending nested item")
logbreak("Appending to nested list")
sample.nested.items.append(3)

expect(read('tmp/sample.yml')) == dedent(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_save.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=unused-variable,no-member,no-member,assigning-non-slot
# pylint: disable=unused-variable,assigning-non-slot

import pytest

Expand Down
113 changes: 113 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# pylint: disable=unused-variable

import os

import pytest

from datafiles import datafile
from datafiles.converters import Number, Text


@datafile('../tmp/sample.yml')
class Sample:
number: Number = 0
text: Text = ""


def describe_number():
@pytest.fixture
def sample():
return Sample()

def with_float_to_integer(sample, expect, read, dedent):
sample.number = 1.23

expect(read('tmp/sample.yml')) == dedent(
"""
number: 1.23
"""
)

sample.number = 4

expect(read('tmp/sample.yml')) == dedent(
"""
number: 4
"""
)

@pytest.mark.xfail(bool(os.getenv('CI')), reason="Flaky on CI")
def with_integer_to_float(sample, write, expect):
write(
'tmp/sample.yml',
"""
number: 5
""",
)

expect(sample.number) == 5

write(
'tmp/sample.yml',
"""
number: 6.78
""",
)

sample.number = 6.7


def describe_text():
@pytest.fixture
def sample():
return Sample()

def with_single_line(sample, expect, read, dedent):
sample.text = "Hello, world!"

expect(read('tmp/sample.yml')) == dedent(
"""
text: Hello, world!
"""
)

@pytest.mark.xfail(bool(os.getenv('CI')), reason="Flaky on CI")
def with_multiple_lines(sample, expect, read, dedent, write):
sample.text = '\n'.join(f'Line {i+1}' for i in range(3))

expect(read('tmp/sample.yml')) == dedent(
"""
text: |
Line 1
Line 2
Line 3
"""
)

write(
'tmp/sample.yml',
"""
text: |
Line 4
Line 5
Line 6
""",
)

expect(sample.text) == "Line 4\nLine 5\nLine 6\n"

def with_extra_newlines(sample, expect, read, dedent):
sample.text = "\nabc\ndef\n\n"

expect(read('tmp/sample.yml')) == dedent(
"""
text: |
abc
def
"""
)

sample.datafile.load()
sample.datafile.save()

expect(sample.text) == "abc\ndef\n"

0 comments on commit 8ed5f37

Please sign in to comment.