Skip to content

Instantly share code, notes, and snippets.

@huntfx
Last active June 10, 2020 19:59
Show Gist options
  • Save huntfx/ae66267cae9a119837f46a68e43947f9 to your computer and use it in GitHub Desktop.
Save huntfx/ae66267cae9a119837f46a68e43947f9 to your computer and use it in GitHub Desktop.
"""Grab the test count and grader setup from the EdX Python exercises."""
import os
import sys
mod = __import__(sys.argv[1][:-3])
def __fn__(*args, **kwargs):
print('Number of tests:', len(mod.grader.tests()))
print()
print(sys.argv[1] + ':')
with open(os.path.join(os.getcwd(), sys.argv[1]), 'r') as f:
lines = [' ' + line.rstrip() for line in f]
for line in lines[:-1]:
print(line)
return lines[-1] # Return the final line so function based executions don't print None
if hasattr(mod, 'fn'):
globals()[mod.fn] = __fn__
else:
print(func())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment