-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from jacebrowning/restore-type-tests
Restore type integration tests
- Loading branch information
Showing
4 changed files
with
120 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
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" |