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"
+ 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("simple_cases", "expression.py")
expected, _ = read_data("simple_cases", "expression.diff")
versions = black.detect_target_versions(root)
self.assertIn(black.TargetVersion.PY38, versions)
+ def test_pep_695_version_detection(self) -> None:
+ for file in ("type_aliases", "type_params"):
+ source, _ = read_data("py_312", file)
+ root = black.lib2to3_parse(source)
+ features = black.get_features_used(root)
+ self.assertIn(black.Feature.TYPE_PARAMS, features)
+ versions = black.detect_target_versions(root)
+ self.assertIn(black.TargetVersion.PY312, versions)
+
def test_expression_ff(self) -> None:
source, expected = read_data("simple_cases", "expression.py")
tmp_file = Path(black.dump_to_file(source))
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"
+ r"\d\d:\d\d:\d\d\.\d\d\d\d\d\d\+\d\d:\d\d"
)
try:
result = BlackRunner().invoke(
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"
+ r"\d\d:\d\d:\d\d\.\d\d\d\d\d\d\+\d\d:\d\d"
)
try:
result = BlackRunner().invoke(
self.assertEqual(err_lines[-1], "error: cannot format e1: boom")
self.assertEqual(
unstyle(str(report)),
- (
- "1 file reformatted, 2 files left unchanged, 1 file failed to"
- " reformat."
- ),
+ "1 file reformatted, 2 files left unchanged, 1 file failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f3"), black.Changed.YES)
self.assertEqual(out_lines[-1], "reformatted f3")
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 2 files left unchanged, 1 file failed to"
- " reformat."
- ),
+ "2 files reformatted, 2 files left unchanged, 1 file failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.failed(Path("e2"), "boom")
self.assertEqual(err_lines[-1], "error: cannot format e2: boom")
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 2 files left unchanged, 2 files failed to"
- " reformat."
- ),
+ "2 files reformatted, 2 files left unchanged, 2 files failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.path_ignored(Path("wat"), "no match")
self.assertEqual(out_lines[-1], "wat ignored: no match")
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 2 files left unchanged, 2 files failed to"
- " reformat."
- ),
+ "2 files reformatted, 2 files left unchanged, 2 files failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f4"), black.Changed.NO)
self.assertEqual(out_lines[-1], "f4 already well formatted, good job.")
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 3 files left unchanged, 2 files failed to"
- " reformat."
- ),
+ "2 files reformatted, 3 files left unchanged, 2 files failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.check = True
self.assertEqual(
unstyle(str(report)),
- (
- "2 files would be reformatted, 3 files would be left unchanged, 2"
- " files would fail to reformat."
- ),
+ "2 files would be reformatted, 3 files would be left unchanged, 2"
+ " files would fail to reformat.",
)
report.check = False
report.diff = True
self.assertEqual(
unstyle(str(report)),
- (
- "2 files would be reformatted, 3 files would be left unchanged, 2"
- " files would fail to reformat."
- ),
+ "2 files would be reformatted, 3 files would be left unchanged, 2"
+ " files would fail to reformat.",
)
def test_report_quiet(self) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e1: boom")
self.assertEqual(
unstyle(str(report)),
- (
- "1 file reformatted, 2 files left unchanged, 1 file failed to"
- " reformat."
- ),
+ "1 file reformatted, 2 files left unchanged, 1 file failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f3"), black.Changed.YES)
self.assertEqual(len(err_lines), 1)
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 2 files left unchanged, 1 file failed to"
- " reformat."
- ),
+ "2 files reformatted, 2 files left unchanged, 1 file failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.failed(Path("e2"), "boom")
self.assertEqual(err_lines[-1], "error: cannot format e2: boom")
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 2 files left unchanged, 2 files failed to"
- " reformat."
- ),
+ "2 files reformatted, 2 files left unchanged, 2 files failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.path_ignored(Path("wat"), "no match")
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 2 files left unchanged, 2 files failed to"
- " reformat."
- ),
+ "2 files reformatted, 2 files left unchanged, 2 files failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f4"), black.Changed.NO)
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 3 files left unchanged, 2 files failed to"
- " reformat."
- ),
+ "2 files reformatted, 3 files left unchanged, 2 files failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.check = True
self.assertEqual(
unstyle(str(report)),
- (
- "2 files would be reformatted, 3 files would be left unchanged, 2"
- " files would fail to reformat."
- ),
+ "2 files would be reformatted, 3 files would be left unchanged, 2"
+ " files would fail to reformat.",
)
report.check = False
report.diff = True
self.assertEqual(
unstyle(str(report)),
- (
- "2 files would be reformatted, 3 files would be left unchanged, 2"
- " files would fail to reformat."
- ),
+ "2 files would be reformatted, 3 files would be left unchanged, 2"
+ " files would fail to reformat.",
)
def test_report_normal(self) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e1: boom")
self.assertEqual(
unstyle(str(report)),
- (
- "1 file reformatted, 2 files left unchanged, 1 file failed to"
- " reformat."
- ),
+ "1 file reformatted, 2 files left unchanged, 1 file failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f3"), black.Changed.YES)
self.assertEqual(out_lines[-1], "reformatted f3")
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 2 files left unchanged, 1 file failed to"
- " reformat."
- ),
+ "2 files reformatted, 2 files left unchanged, 1 file failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.failed(Path("e2"), "boom")
self.assertEqual(err_lines[-1], "error: cannot format e2: boom")
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 2 files left unchanged, 2 files failed to"
- " reformat."
- ),
+ "2 files reformatted, 2 files left unchanged, 2 files failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.path_ignored(Path("wat"), "no match")
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 2 files left unchanged, 2 files failed to"
- " reformat."
- ),
+ "2 files reformatted, 2 files left unchanged, 2 files failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f4"), black.Changed.NO)
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
- (
- "2 files reformatted, 3 files left unchanged, 2 files failed to"
- " reformat."
- ),
+ "2 files reformatted, 3 files left unchanged, 2 files failed to"
+ " reformat.",
)
self.assertEqual(report.return_code, 123)
report.check = True
self.assertEqual(
unstyle(str(report)),
- (
- "2 files would be reformatted, 3 files would be left unchanged, 2"
- " files would fail to reformat."
- ),
+ "2 files would be reformatted, 3 files would be left unchanged, 2"
+ " files would fail to reformat.",
)
report.check = False
report.diff = True
self.assertEqual(
unstyle(str(report)),
- (
- "2 files would be reformatted, 3 files would be left unchanged, 2"
- " files would fail to reformat."
- ),
+ "2 files would be reformatted, 3 files would be left unchanged, 2"
+ " files would fail to reformat.",
)
def test_lib2to3_parse(self) -> None:
for version, expected in [
("3.6", [TargetVersion.PY36]),
("3.11.0rc1", [TargetVersion.PY311]),
- (">=3.10", [TargetVersion.PY310, TargetVersion.PY311]),
- (">=3.10.6", [TargetVersion.PY310, TargetVersion.PY311]),
+ (">=3.10", [TargetVersion.PY310, TargetVersion.PY311, TargetVersion.PY312]),
+ (
+ ">=3.10.6",
+ [TargetVersion.PY310, TargetVersion.PY311, TargetVersion.PY312],
+ ),
("<3.6", [TargetVersion.PY33, TargetVersion.PY34, TargetVersion.PY35]),
(">3.7,<3.10", [TargetVersion.PY38, TargetVersion.PY39]),
- (">3.7,!=3.8,!=3.9", [TargetVersion.PY310, TargetVersion.PY311]),
+ (
+ ">3.7,!=3.8,!=3.9",
+ [TargetVersion.PY310, TargetVersion.PY311, TargetVersion.PY312],
+ ),
(
"> 3.9.4, != 3.10.3",
- [TargetVersion.PY39, TargetVersion.PY310, TargetVersion.PY311],
+ [
+ TargetVersion.PY39,
+ TargetVersion.PY310,
+ TargetVersion.PY311,
+ TargetVersion.PY312,
+ ],
),
(
"!=3.3,!=3.4",
TargetVersion.PY39,
TargetVersion.PY310,
TargetVersion.PY311,
+ TargetVersion.PY312,
],
),
(
TargetVersion.PY39,
TargetVersion.PY310,
TargetVersion.PY311,
+ TargetVersion.PY312,
],
),
("==3.8.*", [TargetVersion.PY38]),
tmp_file = Path(black.dump_to_file(source, ensure_final_newline=False))
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"
+ 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)])