How to use datafiles - 10 common examples

To help you get started, we’ve selected a few datafiles examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jacebrowning / datafiles / tests / test_loading.py View on Github external
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'
github jacebrowning / datafiles / tests / test_loading.py View on Github external
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'
github jacebrowning / datafiles / tests / test_orm_usage.py View on Github external
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'
github jacebrowning / datafiles / tests / test_patched_methods.py View on Github external
def with_setattr(expect):
        sample = Sample()

        write(
            'tmp/sample.yml',
            """
            item: 42
            """,
        )

        expect(sample.item) == '42'

        expect(sample.datafile.text) == dedent(
            """
            item: '42'
github jacebrowning / datafiles / tests / test_loading.py View on Github external
def with_conversion(expect):
        write(
            'tmp/sample.yml',
            """
            items: 1, 2.3
            """,
        )

        sample = SampleWithList(None)

        expect(sample.items) == [1.0, 2.3]
github jacebrowning / datafiles / tests / test_loading.py View on Github external
def with_matching_types(expect):
        write(
            'tmp/sample.yml',
            """
            items:
            - 1.2
            - 3.4
            """,
        )

        sample = SampleWithList(None)

        expect(sample.items) == [1.2, 3.4]
github jacebrowning / datafiles / tests / test_file_inference.py View on Github external
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")
github jacebrowning / datafiles / tests / test_file_inference.py View on Github external
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")
github jacebrowning / datafiles / tests / test_saving.py View on Github external
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"
github jacebrowning / datafiles / tests / test_patched_methods.py View on Github external
def with_getattribute(expect):
        sample = Sample()

        write(
            'tmp/sample.yml',
            """
            item: b
            """,
        )

        logbreak("Getting attribute")
        expect(sample.item) == 'b'