Skip to content

Commit

Permalink
Revert ghostwriter test change
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Aug 3, 2024
1 parent 9c440af commit eb26d39
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions hypothesis-python/tests/ghostwriter/test_ghostwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import ast
import enum
import json
import os
import platform
import re
import socket
import unittest
Expand Down Expand Up @@ -452,22 +450,13 @@ def test_get_imports_for_strategy(strategy, imports):


@pytest.fixture
def in_temp_path(tmp_path):
"""Fixture to execute tests in a temporary path."""
old_path = Path.cwd()
os.chdir(tmp_path)
yield
os.chdir(old_path)


@pytest.fixture
def temp_script_file(in_temp_path):
"""Fixture to create a script file in a temporary working directory.
Changes the working directory to a temporary directory, then yields an extant file
whose name will end in .py and which includes an importable function.
def temp_script_file():
"""Fixture to yield a Path to a temporary file in the local directory. File name will end
in .py and will include an importable function.
"""
p = Path("my_temp_script.py")
if p.exists():
raise FileExistsError(f"Did not expect {p} to exist during testing")
p.write_text(
dedent(
"""
Expand All @@ -477,17 +466,18 @@ def say_hello():
),
encoding="utf-8",
)
return p
yield p
p.unlink()


@pytest.fixture
def temp_script_file_with_py_function(in_temp_path):
"""Fixture to create a python file in a temporary working directory.
Changes the working directory to a temporary directory, then yields an extant file
whose name will end in .py and which includes an importable function named "py".
def temp_script_file_with_py_function():
"""Fixture to yield a Path to a temporary file in the local directory. File name will end
in .py and will include an importable function named "py"
"""
p = Path("my_temp_script_with_py_function.py")
if p.exists():
raise FileExistsError(f"Did not expect {p} to exist during testing")
p.write_text(
dedent(
"""
Expand All @@ -497,7 +487,8 @@ def py():
),
encoding="utf-8",
)
return p
yield p
p.unlink()


def test_obj_name(temp_script_file, temp_script_file_with_py_function):
Expand All @@ -519,15 +510,12 @@ def test_obj_name(temp_script_file, temp_script_file_with_py_function):
assert e.match(
"Remember that the ghostwriter should be passed the name of a module, not a file."
)

# File names of modules (strings ending in ".py") that exist should get a suggestion
if platform.system() == "Darwin":
return # bad/flaky interaction between importlib and tempdirs here
with pytest.raises(click.exceptions.UsageError) as e:
cli.obj_name(str(temp_script_file))
assert e.match(
"Remember that the ghostwriter should be passed the name of a module, not a file."
# f"\n\tTry: hypothesis write {temp_script_file.stem}" # flaky??
f"\n\tTry: hypothesis write {temp_script_file.stem}"
)
# File names of modules (strings ending in ".py") that define a py function should succeed
assert isinstance(
Expand Down

0 comments on commit eb26d39

Please sign in to comment.