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_extra_attributes(sample, expect):
write(
'tmp/sample.yml',
"""
name: 'a'
score: 1.2
nested:
name: 'b'
score: 3.4
extra: 5
""",
)
sample.datafile.load()
expect(sample.name) == 'a'
expect(sample.score) == 1.2
expect(sample.nested.name) == 'b'
def with_matching_types(sample, expect):
write(
'tmp/sample.yml',
"""
bool_: true
int_: 1
float_: 2.3
str_: 'foobar'
""",
)
sample.datafile.load()
expect(sample.bool_).is_(True)
expect(sample.int_) == 1
expect(sample.float_) == 2.3
expect(sample.str_) == 'foobar'
variant: str
value: int
write(
'tmp/routes/foo/public.yml',
"""
value: 2
""",
)
write(
'tmp/routes/foo/bar/public.yml',
"""
value: 2
""",
)
write(
'tmp/routes/foo/bar/private.yml',
"""
value: 2
""",
)
items = list(LegacyTemplate.objects.all())
expect(len(items)) == 3
expect(items[-1].path) == 'foo/bar'
def with_setattr(expect):
sample = Sample()
write(
'tmp/sample.yml',
"""
item: 42
""",
)
expect(sample.item) == '42'
expect(sample.datafile.text) == dedent(
"""
item: '42'
def with_conversion(expect):
write(
'tmp/sample.yml',
"""
items: 1, 2.3
""",
)
sample = SampleWithList(None)
expect(sample.items) == [1.0, 2.3]
def with_matching_types(expect):
write(
'tmp/sample.yml',
"""
items:
- 1.2
- 3.4
""",
)
sample = SampleWithList(None)
expect(sample.items) == [1.2, 3.4]
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")
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")
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"
def with_getattribute(expect):
sample = Sample()
write(
'tmp/sample.yml',
"""
item: b
""",
)
logbreak("Getting attribute")
expect(sample.item) == 'b'