Skip to content

Commit

Permalink
Try using caplog context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Nov 5, 2024
1 parent b0e9c14 commit 0085384
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions tests/test_regex_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@


def test_transformer_no_change(mocker, caplog, tmp_path_factory):
caplog.set_level(logging.DEBUG)
base_dir = tmp_path_factory.mktemp("foo")
code = base_dir / "code.py"
code.write_text("# Something that won't match")

file_context = FileContext(
base_dir,
code,
)
execution_context = CodemodExecutionContext(
directory=base_dir,
dry_run=True,
verbose=False,
registry=mocker.MagicMock(),
providers=mocker.MagicMock(),
repo_manager=mocker.MagicMock(),
path_include=[],
path_exclude=[],
)
pipeline = RegexTransformerPipeline(
pattern=r"hello", replacement="bye", change_description="testing"
)

changeset = pipeline.apply(
context=execution_context,
file_context=file_context,
results=None,
)
assert changeset is None
assert "No changes produced for" in caplog.text
with caplog.at_level(logging.DEBUG):
base_dir = tmp_path_factory.mktemp("foo")
code = base_dir / "code.py"
code.write_text("# Something that won't match")

file_context = FileContext(
base_dir,
code,
)
execution_context = CodemodExecutionContext(
directory=base_dir,
dry_run=True,
verbose=False,
registry=mocker.MagicMock(),
providers=mocker.MagicMock(),
repo_manager=mocker.MagicMock(),
path_include=[],
path_exclude=[],
)
pipeline = RegexTransformerPipeline(
pattern=r"hello", replacement="bye", change_description="testing"
)

changeset = pipeline.apply(
context=execution_context,
file_context=file_context,
results=None,
)
assert changeset is None
assert "No changes produced for" in caplog.text


def test_transformer(mocker, tmp_path_factory):
Expand Down

0 comments on commit 0085384

Please sign in to comment.