示例#1
0
def test_missing_different_values(tmp_path, datadir):
    """Test different and missing values on any YAML."""
    filename = "me/deep/rooted.yaml"
    project = ProjectMock(tmp_path).save_file(filename,
                                              datadir / "existing-actual.yaml")
    project.style(datadir / "existing-desired.toml").api_check_then_fix(
        Fuss(
            True,
            filename,
            369,
            " has different values. Use this:",
            """
            python:
              version: '3.9'
            """,
        ),
        Fuss(
            True,
            filename,
            368,
            " has missing values:",
            """
            python:
              install:
                - extra_requirements:
                    - some
                    - nice
                    - package
            root_key:
              a_dict:
                - c: '3.1'
                - b: 2
                - a: string value
              a_nested:
                list:
                  - 0
                  - 2
                  - 1
                int: 10
            mixed:
              - lets:
                  ruin: this
                  with:
                    - weird
                    - '1'
                    - crap
              - second item: also a dict
            """,
        ),
    ).assert_file_contents(filename, datadir / "existing-expected.yaml")
    project.api_check().assert_violations()
示例#2
0
def test_duplicated_option(tmp_path):
    """Test a violation is raised if a file has a duplicated option."""
    original_file = """
        [abc]
        easy = 123
        easy = as sunday morning
        """
    project = ProjectMock(tmp_path)
    project.style(f"""
        ["{SETUP_CFG}".abc]
        hard = "as a rock"
        """).setup_cfg(original_file).api_fix().assert_violations(
        Fuss(
            False,
            SETUP_CFG,
            Violations.PARSING_ERROR.code,
            f": parsing error (DuplicateOptionError): While reading from {project.path_for(SETUP_CFG)!r} "
            f"[line  3]: option 'easy' in section 'abc' already exists",
        )).assert_file_contents(SETUP_CFG, original_file)
示例#3
0
def test_objects_are_compared_by_hash_on_list_of_dicts_and_new_ones_are_added(
        tmp_path, datadir):
    """Test list of dicts: by default, objects are compared by hash and new ones are added."""
    filename = "some/nice/config.yaml"
    project = ProjectMock(tmp_path).save_file(filename,
                                              datadir / "multiple-lists.yaml")
    project.style(datadir / "list-by-hash-desired.toml").api_check_then_fix(
        Fuss(
            True,
            filename,
            368,
            " has missing values:",
            """
            my:
              list:
                with:
                  dicts:
                    - age: 35
                      name: Silly
            """,
        ), ).assert_file_contents(filename,
                                  datadir / "list-by-hash-expected.yaml")
    project.api_check().assert_violations()
示例#4
0
def test_maximum_two_level_nesting_on_lists_using_jmes_expression_as_list_key_fails(
        tmp_path, datadir):
    """Test a maximum of two-level nesting on lists. Using a JMES expression as a list key will fail.

    Keys must have a maximum of 2 level for now: parent and nested keys.
    """
    filename = "an/arbitrary/file.yaml"
    project = ProjectMock(tmp_path).save_file(filename,
                                              datadir / "multiple-lists.yaml")
    project.style(datadir / "jmes-list-key-desired.toml").api_check_then_fix(
        Fuss(
            True,
            filename,
            368,
            " has missing values:",
            """
            my:
              list:
                with:
                  dicts:
                    - name: Will
                      age: 50
            root:
              - country: ENG
                regions:
                  - region: West Midlands
                    cities:
                      - city: Birmingham
                        people:
                          - name: Ann
                            age: 27
                            from: Liverpool
            """,
        ), ).assert_file_contents(filename,
                                  datadir / "jmes-list-key-expected.yaml")
    project.api_check().assert_violations()