Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def with_update(expect):
sample = Sample()
logbreak()
sample.data.update({'b': 2})
expect(read('tmp/sample.yml')) == dedent(
"""
data:
a: 1
b: 2
"""
)
sample.datafile.load()
logbreak()
sample.data.update({'c': 3})
expect(read('tmp/sample.yml')) == dedent(
"""
data:
sample = SampleWithOptionals(1, 2)
write(
'tmp/sample.yml',
"""
# Heading
required: 1.0 # Line
optional: 2.0
""",
)
sample.datafile.load()
sample.required = 3
sample.datafile.save()
expect(read('tmp/sample.yml')) == dedent(
"""
# Heading
def with_custom_values(expect):
sample = SampleWithDefaults('a', 'b')
sample.datafile.save()
expect(read('tmp/sample.yml')) == dedent(
"""
without_default: a
def with_delitem(expect):
sample = Sample()
del sample.items[0]
expect(read('tmp/sample.yml')) == dedent(
"""
items:
def with_quotations(expect):
sample = Sample(None, None, None, "42")
write(
'tmp/sample.yml',
"""
str_: "42"
""",
)
sample.datafile.load()
sample.datafile.save()
expect(read('tmp/sample.yml')) == dedent(
"""
str_: "42"
sample = SampleWithOptionals(1, 2)
write(
'tmp/sample.yml',
"""
required: 1.0
optional: 2.0
""",
)
sample.datafile.load()
sample.optional = 3
sample.datafile.save()
expect(read('tmp/sample.yml')) == dedent(
"""
required: 1.0
def with_setitem(expect):
sample = Sample()
sample.items[0] = 2
expect(read('tmp/sample.yml')) == dedent(
"""
items:
def with_default_values(expect):
sample = SampleWithDefaults('a')
sample.datafile.save()
expect(read('tmp/sample.yml')) == dedent(
"""
without_default: a
def with_default_values_and_full_save(expect):
sample = SampleWithDefaults('a', 'foo')
sample.datafile.save(include_default_values=True)
expect(read('tmp/sample.yml')) == dedent(
"""
without_default: a
# Nested heading
name: n
score: 2 # Nested line
""",
)
logbreak("Loading")
sample.datafile.load()
sample.score = 3
sample.nested.score = 4
logbreak("Saving")
sample.datafile.save()
expect(read('tmp/sample.yml')) == dedent(
"""
# Heading