Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
Fix broken newly added micro targets
Browse files Browse the repository at this point in the history
... whose breakage wasn't caught by the smoke tests because I used the
paint task which doesn't test the target at all. There's no formatting
going on. Unfortunately just switching over to the `fmt` task really
slows down the test suite due to all of the subprocess related overhead
(process startup + task imports). Sooo let's just emulate what the `fmt`
task would do with black's internal APIs :)

P.S. I know it's not perfect since it doesn't cover the many mode
options available these days but I can't test 'em all and at that point
it's probably a bug with Black :P (which I may end up triaging haha)
  • Loading branch information
ichard26 committed Jul 24, 2021
1 parent eda205b commit c83d51d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/blackbench/micro-targets/list-literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@
u'some_rather_long_text_value',
u'some_rather_long_text_value',
u'some_rather_long_text_value',
]
])
)
2 changes: 1 addition & 1 deletion src/blackbench/micro-targets/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def level_eleven():
if oss == "distributed":
if oss == "democratic":
print("oss doesn't mean corps just get to expect EoL'd Pythons to work for free")
print(f"{f'{{{{{{{}}}}}}}'}")
print(f"{f'{{{{{{{hi_fellow_maintainers}}}}}}}'}")


my_list = [*[*[*[*[*[*[*[133], 123],1927],410],100], 371], 401], 163]
29 changes: 14 additions & 15 deletions tests/smoke_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from typing import List
from unittest.mock import patch

import black
import pytest

import blackbench
from blackbench import Benchmark, Target, resources
from blackbench import Target, resources

from .utils import PAINT_TASK, fast_run, replace_targets
from .utils import fast_run, replace_targets


@pytest.mark.parametrize("task", resources.tasks.keys())
Expand All @@ -27,18 +27,17 @@ def test_provided_tasks(task: str, tmp_path: Path, tmp_result: Path, run_cmd):


@pytest.mark.parametrize("target", resources.targets.values(), ids=lambda t: t.name)
def test_provided_targets(tmp_result: Path, run_cmd, target: Target, capsys):
benchmark = Benchmark(PAINT_TASK, target)
# fmt: off
with \
patch("subprocess.run", fast_run), \
blackbench.utils.managed_workdir() as workdir \
:
results, errored = blackbench.run_suite([benchmark], [], workdir)
# fmt: on
assert results and not errored
captured = capsys.readouterr()
assert "ERROR" not in captured.out and "WARNING" not in captured.out
def test_provided_targets(tmp_result: Path, run_cmd, target: Target):
# This is basically what the `fmt` task does, but without the huge subprocess overhead from
# `blackbench.run_suite`. It's not perfect, but smoke tests should be fast afterall. Oh and
# don't @ me about internal APIs and whatnot, it's fine (take it from a maintainer of black
# :P). Although seriously please try to avoid using Black's internal APIs as much as possible
# because their external usages makes maintenance harder :/
code = target.path.read_text("utf8")
try:
black.format_file_contents(code, fast=False, mode=black.Mode())
except black.NothingChanged:
pass


def test_no_duplicated_id():
Expand Down

0 comments on commit c83d51d

Please sign in to comment.