Skip to content

Commit

Permalink
Add a test for the stderr supression
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman authored Sep 20, 2024
1 parent 934fa26 commit 6277569
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_torchfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,32 @@ def test_errorcodes_distinct():

def test_parse_error_code_str(case, expected):
assert process_error_code_str(case) == expected


def test_stderr_suppression(tmp_path):
data = "import torchvision.datasets as datasets\n"
data_path = tmp_path / "fixable.py"
data_path.write_text(data)
result = subprocess.run(
["torchfix", "--select", "TOR203", "--fix", str(data_path)],
stderr=subprocess.PIPE,
text=True,
)
assert (
result.stderr
== "Finished checking 1 files.\nTransformed 1 files successfully.\n"
)

data = "import torchvision.datasets as datasets\n"
data_path = tmp_path / "fixable.py"
data_path.write_text(data)
result = subprocess.run(
["torchfix", "--select", "TOR203", "--show-stderr", "--fix", str(data_path)],
stderr=subprocess.PIPE,
text=True,
)
assert (
result.stderr
== "Executing codemod...\nFailed to determine module name for {path}: '{path}' is not in the subpath of '' OR one path is relative and the other is absolute.\nFinished checking 1 files.\nTransformed 1 files successfully.\n"
)

0 comments on commit 6277569

Please sign in to comment.