def test_protocol_not_supported(tmp_path): """Test unsupported protocols.""" project = ProjectMock(tmp_path).pyproject_toml(""" [tool.nitpick] style = ["abc://www.example.com/style.toml"] """) with pytest.raises(RuntimeError) as exc_info: project.api_check() assert str(exc_info.value) == "URL protocol 'abc' is not supported"
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()
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()
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()