How to use the datafiles.utils.logbreak 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_automatic_attributes.py View on Github external
def with_empty_list(expect):
        sample = Sample('abc')

        sample.datafile.text = "empty_items: []"

        logbreak("Getting attribute")
        expect(sample.empty_items) == []

        logbreak("Setting attribute")
        sample.empty_items.append(4.2)
        sample.empty_items.append("abc")

        logbreak("Getting attribute")
        expect(sample.empty_items) == [4.2, "abc"]
github jacebrowning / datafiles / tests / test_saving.py View on Github external
write(
            'tmp/sample.yml',
            """
            # Heading
            name: a
            score: 1.0  # Line

            nested:
              # Nested heading
              name: n
              score: 2
            """,
        )

        logbreak("Loading")
        sample.datafile.load()

        sample.score = 3
        sample.nested.score = 4

        logbreak("Saving")
        sample.datafile.save()

        expect(read('tmp/sample.yml')) == dedent(
            """
            # Heading
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'
github jacebrowning / datafiles / tests / test_file_inference.py View on Github external
'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")
    expect(read('tmp/sample.yml')) == dedent(
        """
        language: python
github jacebrowning / datafiles / tests / test_loading.py View on Github external
[a]
            level = 10

            [a.b]
            level = 20

            [a.b.c]
            level = 30

            [a.b.c.d]
            level = 40
            """,
        )

        logbreak("Reading attribute")
        expect(sample.a.level) == 10
        expect(sample.a.b.level) == 20
        expect(sample.a.b.c.level) == 30

        expect(sample.a.b.c.d.level) == 40
github jacebrowning / datafiles / tests / test_saving.py View on Github external
score: 1.0  # Line

            nested:
              # Nested heading
              name: n
              score: 2
            """,
        )

        logbreak("Loading")
        sample.datafile.load()

        sample.score = 3
        sample.nested.score = 4

        logbreak("Saving")
        sample.datafile.save()

        expect(read('tmp/sample.yml')) == dedent(
            """
            # Heading
github jacebrowning / datafiles / tests / test_loading.py View on Github external
[a]
            level = 1

            [a.b]
            level = 2

            [a.b.c]
            level = 3

            [a.b.c.d]
            level = 4
            """
        )

        logbreak("Modifying attribute")
        sample.a.b.c.d.level = 99

        expect(read('tmp/sample.toml')) == dedent(
            """
            level = 0

            [a]
            level = 1

            [a.b]
            level = 2

            [a.b.c]
            level = 3

            [a.b.c.d]
github jacebrowning / datafiles / tests / test_automatic_attributes.py View on Github external
def with_builtin(expect):
        sample = Sample('abc')

        sample.datafile.text = "count: 1"

        logbreak("Getting attribute")
        expect(sample.count) == 1

        logbreak("Setting attribute")
        sample.count = 4.2

        logbreak("Getting attribute")
        expect(sample.count) == 4
github jacebrowning / datafiles / tests / test_automatic_attributes.py View on Github external
def with_empty_list(expect):
        sample = Sample('abc')

        sample.datafile.text = "empty_items: []"

        logbreak("Getting attribute")
        expect(sample.empty_items) == []

        logbreak("Setting attribute")
        sample.empty_items.append(4.2)
        sample.empty_items.append("abc")

        logbreak("Getting attribute")
        expect(sample.empty_items) == [4.2, "abc"]
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")
    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: