Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Sep 8, 2024
1 parent 8995ea7 commit ae7c69b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
7 changes: 1 addition & 6 deletions src/black/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import importlib.resources
import json
import sys
from typing import Any


Expand All @@ -11,10 +10,6 @@ def get_schema(tool_name: str = "black") -> Any:
pkg = "black.resources"
fname = "black.schema.json"

if sys.version_info < (3, 9):
with importlib.resources.open_text(pkg, fname, encoding="utf-8") as f:
return json.load(f)

schema = importlib.resources.files(pkg).joinpath(fname) # type: ignore[unreachable]
schema = importlib.resources.files(pkg).joinpath(fname)
with schema.open(encoding="utf-8") as f:
return json.load(f)
17 changes: 10 additions & 7 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -2157,8 +2157,9 @@ def test_cache_single_file_already_cached(self) -> None:
@event_loop()
def test_cache_multiple_files(self) -> None:
mode = DEFAULT_MODE
with cache_dir() as workspace, patch(
"concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor
with (
cache_dir() as workspace,
patch("concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor),
):
one = (workspace / "one.py").resolve()
one.write_text("print('hello')", encoding="utf-8")
Expand All @@ -2180,9 +2181,10 @@ def test_no_cache_when_writeback_diff(self, color: bool) -> None:
with cache_dir() as workspace:
src = (workspace / "test.py").resolve()
src.write_text("print('hello')", encoding="utf-8")
with patch.object(black.Cache, "read") as read_cache, patch.object(
black.Cache, "write"
) as write_cache:
with (
patch.object(black.Cache, "read") as read_cache,
patch.object(black.Cache, "write") as write_cache,
):
cmd = [str(src), "--diff"]
if color:
cmd.append("--color")
Expand Down Expand Up @@ -2311,8 +2313,9 @@ def test_write_cache_creates_directory_if_needed(self) -> None:
@event_loop()
def test_failed_formatting_does_not_get_cached(self) -> None:
mode = DEFAULT_MODE
with cache_dir() as workspace, patch(
"concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor
with (
cache_dir() as workspace,
patch("concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor),
):
failing = (workspace / "failing.py").resolve()
failing.write_text("not actually python", encoding="utf-8")
Expand Down

0 comments on commit ae7c69b

Please sign in to comment.