-
-
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 #245 from jacebrowning/handle-comment-blocks
Handle commented blocks in YAML
- Loading branch information
Showing
7 changed files
with
156 additions
and
116 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,112 +1,131 @@ | ||
from datafiles import auto | ||
from datafiles.utils import dedent, logbreak, read, write | ||
|
||
|
||
def test_auto_with_sample_file(expect): | ||
write( | ||
'tmp/sample.yml', | ||
""" | ||
homogeneous_list: | ||
- 1 | ||
- 2 | ||
heterogeneous_list: | ||
- 1 | ||
- 'abc' | ||
empty_list: [] | ||
""", | ||
) | ||
|
||
logbreak("Inferring object") | ||
sample = auto('tmp/sample.yml') | ||
|
||
logbreak("Reading attributes") | ||
expect(sample.homogeneous_list) == [1, 2] | ||
expect(sample.heterogeneous_list) == [1, 'abc'] | ||
expect(sample.empty_list) == [] | ||
|
||
logbreak("Updating attribute") | ||
sample.homogeneous_list.append(3.4) | ||
sample.heterogeneous_list.append(5.6) | ||
sample.empty_list.append(7.8) | ||
|
||
logbreak("Reading file") | ||
expect(read('tmp/sample.yml')) == dedent( | ||
""" | ||
homogeneous_list: | ||
- 1 | ||
- 2 | ||
- 3 | ||
heterogeneous_list: | ||
- 1 | ||
- 'abc' | ||
- 5.6 | ||
empty_list: | ||
- 7.8 | ||
""" | ||
) | ||
# pylint: disable=unused-variable | ||
|
||
import pytest | ||
|
||
def test_float_inference(expect): | ||
write( | ||
'tmp/sample.yml', | ||
""" | ||
language: python | ||
python: | ||
- 3.7 | ||
- 3.8 | ||
""", | ||
) | ||
|
||
logbreak("Inferring object") | ||
sample = auto('tmp/sample.yml') | ||
|
||
logbreak("Updating attribute") | ||
sample.python.append(4) | ||
|
||
logbreak("Reading file") | ||
expect(read('tmp/sample.yml')) == dedent( | ||
""" | ||
language: python | ||
python: | ||
- 3.7 | ||
- 3.8 | ||
- 4.0 | ||
""" | ||
) | ||
|
||
from datafiles import auto | ||
from datafiles.utils import dedent, logbreak, read, write | ||
|
||
def test_nested_mutables(expect): | ||
write( | ||
'tmp/sample.yml', | ||
""" | ||
name: Test | ||
roles: | ||
category1: | ||
- value1 | ||
- value2 | ||
category2: | ||
- something | ||
- else | ||
""", | ||
) | ||
|
||
logbreak("Inferring object") | ||
sample = auto('tmp/sample.yml') | ||
|
||
logbreak("Updating attributes") | ||
sample.roles['category1'].append('value3') | ||
|
||
logbreak("Reading file") | ||
expect(read('tmp/sample.yml')) == dedent( | ||
""" | ||
name: Test | ||
roles: | ||
category1: | ||
- value1 | ||
- value2 | ||
- value3 | ||
category2: | ||
- something | ||
- else | ||
""" | ||
def describe_auto(): | ||
@pytest.mark.parametrize( | ||
('filename', 'count'), | ||
[ | ||
('.appveyor.yml', 5), | ||
('.travis.yml', 9), | ||
('mkdocs.yml', 8), | ||
('pyproject.toml', 2), | ||
], | ||
) | ||
def with_real_file(expect, filename, count): | ||
logbreak("Inferring object") | ||
sample = auto(filename) | ||
|
||
logbreak("Reading attributes") | ||
expect(len(sample.datafile.data)) == count | ||
|
||
def with_sample_file(expect): | ||
write( | ||
'tmp/sample.yml', | ||
""" | ||
homogeneous_list: | ||
- 1 | ||
- 2 | ||
heterogeneous_list: | ||
- 1 | ||
- 'abc' | ||
empty_list: [] | ||
""", | ||
) | ||
|
||
logbreak("Inferring object") | ||
sample = auto('tmp/sample.yml') | ||
|
||
logbreak("Reading attributes") | ||
expect(sample.homogeneous_list) == [1, 2] | ||
expect(sample.heterogeneous_list) == [1, 'abc'] | ||
expect(sample.empty_list) == [] | ||
|
||
logbreak("Updating attribute") | ||
sample.homogeneous_list.append(3.4) | ||
sample.heterogeneous_list.append(5.6) | ||
sample.empty_list.append(7.8) | ||
|
||
logbreak("Reading file") | ||
expect(read('tmp/sample.yml')) == dedent( | ||
""" | ||
homogeneous_list: | ||
- 1 | ||
- 2 | ||
- 3 | ||
heterogeneous_list: | ||
- 1 | ||
- 'abc' | ||
- 5.6 | ||
empty_list: | ||
- 7.8 | ||
""" | ||
) | ||
|
||
def with_floats(expect): | ||
write( | ||
'tmp/sample.yml', | ||
""" | ||
language: python | ||
python: | ||
- 3.7 | ||
- 3.8 | ||
""", | ||
) | ||
|
||
logbreak("Inferring object") | ||
sample = auto('tmp/sample.yml') | ||
|
||
logbreak("Updating attribute") | ||
sample.python.append(4) | ||
|
||
logbreak("Reading file") | ||
expect(read('tmp/sample.yml')) == dedent( | ||
""" | ||
language: python | ||
python: | ||
- 3.7 | ||
- 3.8 | ||
- 4.0 | ||
""" | ||
) | ||
|
||
def with_nested_mutables(expect): | ||
write( | ||
'tmp/sample.yml', | ||
""" | ||
name: Test | ||
roles: | ||
category1: | ||
- value1 | ||
- value2 | ||
category2: | ||
- something | ||
- else | ||
""", | ||
) | ||
|
||
logbreak("Inferring object") | ||
sample = auto('tmp/sample.yml') | ||
|
||
logbreak("Updating attributes") | ||
sample.roles['category1'].append('value3') | ||
|
||
logbreak("Reading file") | ||
expect(read('tmp/sample.yml')) == dedent( | ||
""" | ||
name: Test | ||
roles: | ||
category1: | ||
- value1 | ||
- value2 | ||
- value3 | ||
category2: | ||
- something | ||
- else | ||
""" | ||
) |