Skip to content

Commit

Permalink
test both with and without existing bytecode cache files
Browse files Browse the repository at this point in the history
  • Loading branch information
Technologicat committed Apr 10, 2021
1 parent 3b7fa4f commit e27a375
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
8 changes: 8 additions & 0 deletions mcpyrate/test/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..quotes import macros, q, u # noqa: F401

import copy
import sys
from textwrap import dedent

# `expand` and `compile` aren't tested separately, but `run` is built on them, so meh.
Expand All @@ -38,6 +39,13 @@ def test_create_module():
assert flip.__package__ is None
assert flop.__package__ == "flip"
assert flip.flop is flop # submodule is added to the package namespace

# We must clean up so that the second-pass test works too.
try:
del sys.modules["flip.flop"]
del sys.modules["flip"]
except KeyError:
pass
test_create_module()

def test_dynamicmodule_from_source():
Expand Down
22 changes: 15 additions & 7 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def listalldemofiles(demoroot):
# return out


def runtests():
print(colorize("Testing started.", ColorScheme.TESTHEADING), file=sys.stderr)
def runtests(clear_bytecode_cache=True):
cache_note = "Bytecode cache will be cleared." if clear_bytecode_cache else "Using existing bytecode."
print(colorize(f"Testing started. {cache_note}", ColorScheme.TESTHEADING), file=sys.stderr)
errors = 0
# Each submodule of `mcpyrate` should have an entry here, regardless of if it currently has tests or not.
testsets = (("main", os.path.join("mcpyrate", "test")),
Expand All @@ -67,7 +68,8 @@ def runtests():
if not os.path.isdir(path): # skip empty testsets
continue
modnames = filenames_to_modulenames(path, listtestfiles(path))
deletepycachedirs(path)
if clear_bytecode_cache:
deletepycachedirs(path)
for m in modnames:
try:
# TODO: We're not inside a package, so we can't use a relative import.
Expand Down Expand Up @@ -116,11 +118,13 @@ def runtests():

# UGH! We can't currently import demos as modules, since they may depend on other modules
# in their containing directory. So let's run them like a shell script would.
def rundemos():
print(colorize("Demos started.", ColorScheme.TESTHEADING), file=sys.stderr)
def rundemos(clear_bytecode_cache=True):
cache_note = "Bytecode cache will be cleared." if clear_bytecode_cache else "Using existing bytecode."
print(colorize(f"Demos started. {cache_note}", ColorScheme.TESTHEADING), file=sys.stderr)
errors = 0
demofiles = listalldemofiles("demo")
deletepycachedirs("demo")
if clear_bytecode_cache:
deletepycachedirs("demo")
for fn in demofiles:
print(colorize(f" Running file '{fn}'...", ColorScheme.TESTHEADING),
file=sys.stderr)
Expand All @@ -144,5 +148,9 @@ def rundemos():
return all_passed

if __name__ == '__main__':
if not (runtests() and rundemos()):
t1 = runtests(True)
t2 = runtests(False)
t3 = rundemos(True)
t4 = rundemos(False)
if not (t1 and t2 and t3 and t4):
sys.exit(1) # pragma: no cover, this only runs when the tests fail.

0 comments on commit e27a375

Please sign in to comment.