Skip to content

Commit

Permalink
Fixed test that seemed to be failing due to thing.h not being success…
Browse files Browse the repository at this point in the history
…fully reset to its original contents.
  • Loading branch information
tbenthompson committed Jan 12, 2021
1 parent bb44c70 commit 15fbfbb
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tests/test_cppimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@

@contextlib.contextmanager
def appended(filename, text):
orig = open(filename, "r").read()
open(filename, "a").write(text)
with open(filename, "r") as f:
orig = f.read()
with open(filename, "a") as f:
f.write(text)
try:
yield
finally:
open(filename, "w").write(orig)
with open(filename, "w") as f:
f.write(orig)


def subprocess_check(test_code, returncode=0):
p = subprocess.Popen(["python", "-c", test_code], cwd=os.path.dirname(__file__))
p.wait()
p = subprocess.run(
["python", "-c", test_code], cwd=os.path.dirname(__file__), capture_output=True
)
print(p.stdout.decode("utf-8"))
print(p.stderr.decode("utf-8"))
assert p.returncode == returncode


Expand Down Expand Up @@ -119,13 +125,14 @@ def test_no_rebuild_if_no_deps_change():
def test_rebuild_header_after_change():
cppimport.imp("mymodule")
test_code = """
import cppimport
cppimport.set_quiet(False)
mymodule = cppimport.imp("mymodule")
import cppimport;
cppimport.set_quiet(False);
mymodule = cppimport.imp("mymodule");
mymodule.Thing().cheer()
"""
with appended("tests/thing.h", add_to_thing):
subprocess_check(test_code)
assert open("tests/thing.h", "r").read() == ""


def test_raw_extensions():
Expand Down

0 comments on commit 15fbfbb

Please sign in to comment.