Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logbreak("Appending to nested list")
sample.nested.items.append(2)
expect(read('tmp/sample.yml')) == dedent(
"""
item: 1
nested:
items:
- 2
"""
)
logbreak("Appending to nested list")
sample.nested.items.append(3)
expect(read('tmp/sample.yml')) == dedent(
"""
item: 1
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:
def with_append_on_nested_dataclass(expect):
sample = SampleWithNesting(1)
logbreak("Appending to nested list")
sample.nested.items.append(2)
expect(read('tmp/sample.yml')) == dedent(
"""
item: 1
nested:
items:
- 2
"""
)
logbreak("Appending to nested list")
sample.nested.items.append(3)
expect(read('tmp/sample.yml')) == dedent(
"""
item: 1
def with_initial_values(expect):
sample = SampleWithNesting('foo', 1.2, {'name': 'bar', 'score': 3.4})
sample.datafile.save()
with open('tmp/sample.yml') as f:
expect(f.read()) == dedent(
"""
name: foo
def without_initial_values(sample, expect):
sample.datafile.save()
with open('tmp/sample.yml') as f:
expect(f.read()) == dedent(
"""
bool_: false
def with_default_values(expect):
sample = SampleWithNestingAndDefaults('a')
sample.datafile.save()
with open('tmp/sample.yml') as f:
expect(f.read()) == dedent(
"""
name: a
sample.items.append(2)
expect(read('tmp/sample.yml')) == dedent(
"""
items:
- 1
- 2
"""
)
sample.datafile.load()
logbreak("Appending to list")
sample.items.append(3)
expect(read('tmp/sample.yml')) == dedent(
"""
items: