mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-25 23:09:49 +01:00
update ruff and enable flake8-logging-format and flake8-type-checking (#8894)
* update ruff and enable flake8-logging-format and flake8-type-checking check * Update dvc/external_repo.py * Update dvc/fs/dvc.py * Update dvc/repo/experiments/__init__.py * Update dvc/repo/experiments/queue/base.py * Update pyproject.toml
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -9,7 +10,6 @@ from dvc.output import OutputIsIgnoredError
|
||||
from dvc.pathspec_math import PatternInfo, merge_patterns
|
||||
from dvc.repo import Repo
|
||||
from dvc.testing.tmp_dir import TmpDir
|
||||
from dvc.types import List
|
||||
from dvc_data.hashfile.build import IgnoreInCollectedDirError
|
||||
from dvc_data.hashfile.utils import get_mtime_and_size
|
||||
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
extend = "../pyproject.toml"
|
||||
extend-select = ["RUF005"]
|
||||
extend-ignore = ["S", "RUF001", "ARG001", "ARG002"]
|
||||
extend-ignore = ["S", "RUF001", "ARG001", "ARG002", "TRY002"]
|
||||
|
||||
@@ -3,8 +3,6 @@ from textwrap import dedent
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.repo.experiments.queue.celery import LocalCeleryQueue
|
||||
|
||||
DEFAULT_ITERATIONS = 2
|
||||
CHECKPOINT_SCRIPT_FORMAT = dedent(
|
||||
"""\
|
||||
@@ -156,7 +154,7 @@ def _thread_worker(app, **kwargs):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_queue(tmp_dir, dvc, scm, mocker) -> LocalCeleryQueue:
|
||||
def test_queue(tmp_dir, dvc, scm, mocker):
|
||||
"""Patches experiments celery queue for pytest testing.
|
||||
|
||||
Test queue worker runs for the duration of the test in separate thread(s).
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import pytest
|
||||
from funcy import first
|
||||
from scmrepo.git import Git
|
||||
|
||||
from dvc.repo.experiments.show import (
|
||||
ExpStatus,
|
||||
@@ -10,7 +9,7 @@ from dvc.repo.experiments.show import (
|
||||
)
|
||||
|
||||
|
||||
def test_get_show_branch(tmp_dir, scm: "Git", dvc, exp_stage):
|
||||
def test_get_show_branch(tmp_dir, scm, dvc, exp_stage):
|
||||
new_branch = "new"
|
||||
|
||||
baseline = scm.get_rev()
|
||||
|
||||
@@ -65,7 +65,7 @@ class TestColorFormatter:
|
||||
with caplog.at_level(logging.INFO, logger="dvc"):
|
||||
try:
|
||||
raise ValueError
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
logger.exception("message")
|
||||
|
||||
expected = "{red}ERROR{nc}: message".format(**colors)
|
||||
@@ -76,7 +76,7 @@ class TestColorFormatter:
|
||||
with caplog.at_level(logging.INFO, logger="dvc"):
|
||||
try:
|
||||
raise Exception("description")
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
logger.exception("")
|
||||
|
||||
expected = "{red}ERROR{nc}: description".format(**colors)
|
||||
@@ -87,7 +87,7 @@ class TestColorFormatter:
|
||||
with caplog.at_level(logging.INFO, logger="dvc"):
|
||||
try:
|
||||
raise Exception("description")
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
logger.exception("message")
|
||||
|
||||
expected = "{red}ERROR{nc}: message - description".format(**colors)
|
||||
@@ -98,7 +98,7 @@ class TestColorFormatter:
|
||||
with caplog.at_level(logging.DEBUG, logger="dvc"):
|
||||
try:
|
||||
raise Exception("description")
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
stack_trace = traceback.format_exc()
|
||||
logger.exception("")
|
||||
|
||||
@@ -144,7 +144,7 @@ class TestColorFormatter:
|
||||
with caplog.at_level(logging.DEBUG, logger="dvc"):
|
||||
try:
|
||||
raise Exception("description")
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
stack_trace = traceback.format_exc()
|
||||
logger.exception("something", extra={"tb_only": True})
|
||||
|
||||
|
||||
@@ -2,13 +2,11 @@ import datetime
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
from pytest import CaptureFixture
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from dvc.ui import Console
|
||||
|
||||
|
||||
def test_write(capsys: CaptureFixture[str]):
|
||||
def test_write(capsys):
|
||||
"""Test that ui.write works."""
|
||||
console = Console(enable=True)
|
||||
message = "hello world"
|
||||
@@ -44,9 +42,7 @@ def test_write(capsys: CaptureFixture[str]):
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_write_json(
|
||||
capsys: CaptureFixture[str], mocker: MockerFixture, isatty, expected_output
|
||||
):
|
||||
def test_write_json(capsys, mocker, isatty, expected_output):
|
||||
"""Test that ui.write_json works."""
|
||||
|
||||
console = Console(enable=True)
|
||||
@@ -57,7 +53,7 @@ def test_write_json(
|
||||
assert captured.out == expected_output
|
||||
|
||||
|
||||
def test_capsys_works(capsys: CaptureFixture[str]):
|
||||
def test_capsys_works(capsys):
|
||||
"""Sanity check that capsys can capture outputs from a global ui."""
|
||||
from dvc.ui import ui
|
||||
|
||||
|
||||
+11
-13
@@ -1,14 +1,12 @@
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
from pytest import CaptureFixture
|
||||
from pytest_mock import MockerFixture
|
||||
from rich.style import Style
|
||||
|
||||
from dvc.ui import ui
|
||||
|
||||
|
||||
def test_plain(capsys: CaptureFixture[str]):
|
||||
def test_plain(capsys):
|
||||
ui.table(
|
||||
[("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
|
||||
headers=["first", "second"],
|
||||
@@ -24,7 +22,7 @@ def test_plain(capsys: CaptureFixture[str]):
|
||||
)
|
||||
|
||||
|
||||
def test_plain_md(capsys: CaptureFixture[str]):
|
||||
def test_plain_md(capsys):
|
||||
ui.table(
|
||||
[("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
|
||||
headers=["first", "second"],
|
||||
@@ -42,7 +40,7 @@ def test_plain_md(capsys: CaptureFixture[str]):
|
||||
)
|
||||
|
||||
|
||||
def test_plain_pager(mocker: MockerFixture):
|
||||
def test_plain_pager(mocker):
|
||||
pager_mock = mocker.patch("dvc.ui.pager.pager")
|
||||
ui.table(
|
||||
[("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
|
||||
@@ -62,7 +60,7 @@ def test_plain_pager(mocker: MockerFixture):
|
||||
)
|
||||
|
||||
|
||||
def test_plain_headerless(capsys: CaptureFixture[str]):
|
||||
def test_plain_headerless(capsys):
|
||||
ui.table([("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")])
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == textwrap.dedent(
|
||||
@@ -74,7 +72,7 @@ def test_plain_headerless(capsys: CaptureFixture[str]):
|
||||
)
|
||||
|
||||
|
||||
def test_rich_simple(capsys: CaptureFixture[str]):
|
||||
def test_rich_simple(capsys):
|
||||
ui.table(
|
||||
[("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
|
||||
headers=["first", "second"],
|
||||
@@ -87,7 +85,7 @@ def test_rich_simple(capsys: CaptureFixture[str]):
|
||||
] == ["first second", "foo bar", "foo1 bar1", "foo2 bar2"]
|
||||
|
||||
|
||||
def test_rich_headerless(capsys: CaptureFixture[str]):
|
||||
def test_rich_headerless(capsys):
|
||||
ui.table(
|
||||
[("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")], rich_table=True
|
||||
)
|
||||
@@ -97,7 +95,7 @@ def test_rich_headerless(capsys: CaptureFixture[str]):
|
||||
] == ["foo bar", "foo1 bar1", "foo2 bar2"]
|
||||
|
||||
|
||||
def test_rich_border(capsys: CaptureFixture[str]):
|
||||
def test_rich_border(capsys):
|
||||
ui.table(
|
||||
[("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
|
||||
headers=["first", "second"],
|
||||
@@ -124,7 +122,7 @@ def test_rich_border(capsys: CaptureFixture[str]):
|
||||
{"row_styles": [{"style": Style(bold=True)}]},
|
||||
],
|
||||
)
|
||||
def test_rich_styles(capsys: CaptureFixture[str], extra_opts):
|
||||
def test_rich_styles(capsys, extra_opts):
|
||||
ui.table(
|
||||
[("foo", "bar"), ("foo1", "bar1"), ("foo2", "bar2")],
|
||||
headers=["first", "second"],
|
||||
@@ -138,7 +136,7 @@ def test_rich_styles(capsys: CaptureFixture[str], extra_opts):
|
||||
] == ["first second", "foo bar", "foo1 bar1", "foo2 bar2"]
|
||||
|
||||
|
||||
def test_rich_pager(mocker: MockerFixture):
|
||||
def test_rich_pager(mocker):
|
||||
pager_mock = mocker.patch("dvc.ui.pager.pager")
|
||||
|
||||
ui.table(
|
||||
@@ -154,13 +152,13 @@ def test_rich_pager(mocker: MockerFixture):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rich_table", [True, False])
|
||||
def test_empty(capsys: CaptureFixture[str], rich_table: str):
|
||||
def test_empty(capsys, rich_table):
|
||||
ui.table([], rich_table=rich_table)
|
||||
out, err = capsys.readouterr()
|
||||
assert (out, err) == ("", "")
|
||||
|
||||
|
||||
def test_empty_markdown(capsys: CaptureFixture[str]):
|
||||
def test_empty_markdown(capsys):
|
||||
ui.table([], headers=["Col1", "Col2"], markdown=True)
|
||||
out, err = capsys.readouterr()
|
||||
assert (out, err) == ("| Col1 | Col2 |\n|--------|--------|\n\n", "")
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
from typing import Any, Dict
|
||||
from unittest.mock import ANY, Mock
|
||||
from typing import TYPE_CHECKING, Any, Dict
|
||||
from unittest.mock import ANY
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from unittest.mock import Mock
|
||||
|
||||
|
||||
def issubset(subset: Dict, superset: Dict) -> bool:
|
||||
@@ -7,7 +10,7 @@ def issubset(subset: Dict, superset: Dict) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def called_once_with_subset(m: Mock, *args: Any, **kwargs: Any) -> bool:
|
||||
def called_once_with_subset(m: "Mock", *args: Any, **kwargs: Any) -> bool:
|
||||
m.assert_called_once()
|
||||
m_args, m_kwargs = m.call_args
|
||||
|
||||
|
||||
Reference in New Issue
Block a user