Esempio n. 1
0
    def test_malformatted_toml_raises_error(self, tmp_path):
        path = tmp_path / "config.toml"
        path.write_text(
            "[tool.black]\n{key}: I am not json:\n or yaml = false")

        with pytest.raises(MalformattedToml) as error:
            read_black_config(path)

        assert error.match("invalid character")
Esempio n. 2
0
    def test_skip_string_normalisation_handled_with_kebabcase(self, tmp_path):
        formatter = setup_formatter("")
        path = tmp_path / "config.toml"
        path.write_text("[tool.black]\nskip-string-normalization = 0")

        read_black_config(path)
        actual = formatter.black_mode
        expected = black.FileMode(line_length=DEFAULT_LINE_LENGTH,
                                  string_normalization=True)

        assert actual == expected
Esempio n. 3
0
    def test_unrecognised_black_options_in_config_ignored_and_default_line_length_used(
            self, tmp_path):
        formatter = setup_formatter("")
        path = tmp_path / "config.toml"
        path.write_text("[tool.black]\nfoo = false")

        read_black_config(path)
        actual = formatter.black_mode
        expected = black.FileMode(line_length=DEFAULT_LINE_LENGTH)

        assert actual == expected
Esempio n. 4
0
    def test_read_black_config_settings(self, tmp_path):
        path = tmp_path / "config.toml"
        black_line_length = 9
        path.write_text(f"[tool.black]\nline_length = {black_line_length}")

        actual = read_black_config(path)
        expected = black.FileMode(line_length=black_line_length)

        assert actual == expected
Esempio n. 5
0
    def __init__(
        self,
        snakefile: TokenIterator,
        line_length: Optional[int] = None,
        black_config_file: Optional[PathLike] = None,
    ):
        self.result: str = ""
        self.lagging_comments: str = ""
        self.no_formatting_yet: bool = True

        self.black_mode = read_black_config(black_config_file)

        if line_length is not None:
            self.black_mode.line_length = line_length

        super().__init__(snakefile)  # Call to parse snakefile
Esempio n. 6
0
 def test_config_doesnt_exist_raises_error(self, tmp_path):
     path = tmp_path / "config.toml"
     with pytest.raises(FileNotFoundError):
         read_black_config(path)