How to use the datafiles.utils.read function in datafiles

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_patched_methods.py View on Github external
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:
github jacebrowning / datafiles / tests / test_saving.py View on Github external
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
github jacebrowning / datafiles / tests / test_saving.py View on Github external
def with_custom_values(expect):
        sample = SampleWithDefaults('a', 'b')

        sample.datafile.save()

        expect(read('tmp/sample.yml')) == dedent(
            """
            without_default: a
github jacebrowning / datafiles / tests / test_patched_methods.py View on Github external
def with_delitem(expect):
        sample = Sample()

        del sample.items[0]

        expect(read('tmp/sample.yml')) == dedent(
            """
            items:
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_saving.py View on Github external
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
github jacebrowning / datafiles / tests / test_patched_methods.py View on Github external
def with_setitem(expect):
        sample = Sample()

        sample.items[0] = 2

        expect(read('tmp/sample.yml')) == dedent(
            """
            items:
github jacebrowning / datafiles / tests / test_saving.py View on Github external
def with_default_values(expect):
        sample = SampleWithDefaults('a')

        sample.datafile.save()

        expect(read('tmp/sample.yml')) == dedent(
            """
            without_default: a
github jacebrowning / datafiles / tests / test_saving.py View on Github external
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
github jacebrowning / datafiles / tests / test_saving.py View on Github external
# 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