当前位置: 首页>>代码示例>>Python>>正文


Python black.main方法代码示例

本文整理汇总了Python中black.main方法的典型用法代码示例。如果您正苦于以下问题:Python black.main方法的具体用法?Python black.main怎么用?Python black.main使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在black的用法示例。


在下文中一共展示了black.main方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_black

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def run_black(paths):
    if black_main is None:
        return 0

    print("Running black check")
    exit_code = 0
    try:
        black_main(["--check"] + paths)
    except SystemExit as exc:
        exit_code = exc.code

    if exit_code:
        print("black failed")
    else:
        print("black passed")
    return exit_code 
开发者ID:adamchainz,项目名称:multilint,代码行数:18,代码来源:__init__.py

示例2: invokeBlack

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def invokeBlack(
        self, args: List[str], exit_code: int = 0, ignore_config: bool = True
    ) -> None:
        runner = BlackRunner()
        if ignore_config:
            args = ["--verbose", "--config", str(THIS_DIR / "empty.toml"), *args]
        result = runner.invoke(black.main, args)
        self.assertEqual(
            result.exit_code,
            exit_code,
            msg=(
                f"Failed with args: {args}\n"
                f"stdout: {runner.stdout_bytes.decode()!r}\n"
                f"stderr: {runner.stderr_bytes.decode()!r}\n"
                f"exception: {result.exception}"
            ),
        ) 
开发者ID:psf,项目名称:black,代码行数:19,代码来源:test_black.py

示例3: test_piping_diff

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_piping_diff(self) -> None:
        diff_header = re.compile(
            r"(STDIN|STDOUT)\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d\d\d\d "
            r"\+\d\d\d\d"
        )
        source, _ = read_data("expression.py")
        expected, _ = read_data("expression.diff")
        config = THIS_DIR / "data" / "empty_pyproject.toml"
        args = [
            "-",
            "--fast",
            f"--line-length={black.DEFAULT_LINE_LENGTH}",
            "--diff",
            f"--config={config}",
        ]
        result = BlackRunner().invoke(
            black.main, args, input=BytesIO(source.encode("utf8"))
        )
        self.assertEqual(result.exit_code, 0)
        actual = diff_header.sub(DETERMINISTIC_HEADER, result.output)
        actual = actual.rstrip() + "\n"  # the diff output has a trailing space
        self.assertEqual(expected, actual) 
开发者ID:psf,项目名称:black,代码行数:24,代码来源:test_black.py

示例4: test_piping_diff_with_color

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_piping_diff_with_color(self) -> None:
        source, _ = read_data("expression.py")
        config = THIS_DIR / "data" / "empty_pyproject.toml"
        args = [
            "-",
            "--fast",
            f"--line-length={black.DEFAULT_LINE_LENGTH}",
            "--diff",
            "--color",
            f"--config={config}",
        ]
        result = BlackRunner().invoke(
            black.main, args, input=BytesIO(source.encode("utf8"))
        )
        actual = result.output
        # Again, the contents are checked in a different test, so only look for colors.
        self.assertIn("\033[1;37m", actual)
        self.assertIn("\033[36m", actual)
        self.assertIn("\033[32m", actual)
        self.assertIn("\033[31m", actual)
        self.assertIn("\033[0m", actual) 
开发者ID:psf,项目名称:black,代码行数:23,代码来源:test_black.py

示例5: test_expression_diff

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_expression_diff(self) -> None:
        source, _ = read_data("expression.py")
        expected, _ = read_data("expression.diff")
        tmp_file = Path(black.dump_to_file(source))
        diff_header = re.compile(
            rf"{re.escape(str(tmp_file))}\t\d\d\d\d-\d\d-\d\d "
            r"\d\d:\d\d:\d\d\.\d\d\d\d\d\d \+\d\d\d\d"
        )
        try:
            result = BlackRunner().invoke(black.main, ["--diff", str(tmp_file)])
            self.assertEqual(result.exit_code, 0)
        finally:
            os.unlink(tmp_file)
        actual = result.output
        actual = diff_header.sub(DETERMINISTIC_HEADER, actual)
        actual = actual.rstrip() + "\n"  # the diff output has a trailing space
        if expected != actual:
            dump = black.dump_to_file(actual)
            msg = (
                "Expected diff isn't equal to the actual. If you made changes to"
                " expression.py and this is an anticipated difference, overwrite"
                f" tests/data/expression.diff with {dump}"
            )
            self.assertEqual(expected, actual, msg) 
开发者ID:psf,项目名称:black,代码行数:26,代码来源:test_black.py

示例6: test_black

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_black():
    runner = CliRunner()
    result = runner.invoke(black.main, [str(code_root), "--check"])
    assert result.exit_code == 0, result.output 
开发者ID:simonw,项目名称:datasette,代码行数:6,代码来源:test_black.py

示例7: black_wrapper

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def black_wrapper(writeback):
    """ Helper function to invoke black programatically.
    """

    check = [] if writeback else ["--check"]
    exclude = "|".join(["cangivefilenameshere"])
    sys.argv[1:] = check + ["--exclude", exclude, ROOT_DIR]

    import black

    black.main() 
开发者ID:imageio,项目名称:imageio-ffmpeg,代码行数:13,代码来源:tasks.py

示例8: test_black

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_black():
    runner = CliRunner()
    result = runner.invoke(
        black.main,
        [str(code_root / "tests"), str(code_root / "sqlite_utils"), "--check"],
    )
    assert result.exit_code == 0, result.output 
开发者ID:simonw,项目名称:sqlite-utils,代码行数:9,代码来源:test_black.py

示例9: test_piping

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_piping(self) -> None:
        source, expected = read_data("src/black/__init__", data=False)
        result = BlackRunner().invoke(
            black.main,
            ["-", "--fast", f"--line-length={black.DEFAULT_LINE_LENGTH}"],
            input=BytesIO(source.encode("utf8")),
        )
        self.assertEqual(result.exit_code, 0)
        self.assertFormatEqual(expected, result.output)
        black.assert_equivalent(source, result.output)
        black.assert_stable(source, result.output, black.FileMode()) 
开发者ID:psf,项目名称:black,代码行数:13,代码来源:test_black.py

示例10: test_no_cache_when_stdin

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_no_cache_when_stdin(self) -> None:
        mode = black.FileMode()
        with cache_dir():
            result = CliRunner().invoke(
                black.main, ["-"], input=BytesIO(b"print('hello')")
            )
            self.assertEqual(result.exit_code, 0)
            cache_file = black.get_cache_file(mode)
            self.assertFalse(cache_file.exists()) 
开发者ID:psf,项目名称:black,代码行数:11,代码来源:test_black.py

示例11: test_pipe_force_pyi

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_pipe_force_pyi(self) -> None:
        source, expected = read_data("force_pyi")
        result = CliRunner().invoke(
            black.main, ["-", "-q", "--pyi"], input=BytesIO(source.encode("utf8"))
        )
        self.assertEqual(result.exit_code, 0)
        actual = result.output
        self.assertFormatEqual(actual, expected) 
开发者ID:psf,项目名称:black,代码行数:10,代码来源:test_black.py

示例12: test_pipe_force_py36

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_pipe_force_py36(self) -> None:
        source, expected = read_data("force_py36")
        result = CliRunner().invoke(
            black.main,
            ["-", "-q", "--target-version=py36"],
            input=BytesIO(source.encode("utf8")),
        )
        self.assertEqual(result.exit_code, 0)
        actual = result.output
        self.assertFormatEqual(actual, expected) 
开发者ID:psf,项目名称:black,代码行数:12,代码来源:test_black.py

示例13: test_preserves_line_endings_via_stdin

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_preserves_line_endings_via_stdin(self) -> None:
        for nl in ["\n", "\r\n"]:
            contents = nl.join(["def f(  ):", "    pass"])
            runner = BlackRunner()
            result = runner.invoke(
                black.main, ["-", "--fast"], input=BytesIO(contents.encode("utf8"))
            )
            self.assertEqual(result.exit_code, 0)
            output = runner.stdout_bytes
            self.assertIn(nl.encode("utf8"), output)
            if nl == "\n":
                self.assertNotIn(b"\r\n", output) 
开发者ID:psf,项目名称:black,代码行数:14,代码来源:test_black.py

示例14: test_blackd_main

# 需要导入模块: import black [as 别名]
# 或者: from black import main [as 别名]
def test_blackd_main(self) -> None:
        with patch("blackd.web.run_app"):
            result = CliRunner().invoke(blackd.main, [])
            if result.exception is not None:
                raise result.exception
            self.assertEqual(result.exit_code, 0) 
开发者ID:psf,项目名称:black,代码行数:8,代码来源:test_black.py


注:本文中的black.main方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。