Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt post-check message to context #13

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
10 changes: 9 additions & 1 deletion nbresult/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ def check(self):
tests_directory = 'tests'
if self.subdir:
tests_directory = f'{tests_directory}/{self.subdir}'
result = f"""

nbresult_post_check_message = os.getenv('NBRESULT_POST_CHECK_MESSAGE')
if nbresult_post_check_message == 'JUPYTERLAB':
result = f"""
{result}\n
:100: You can now save your changes and move on to the next challenge.
"""
else:
result = f"""
{result}\n
💯 You can commit your code:\n
\033[1;32mgit\033[39m add {tests_directory}/{self.name}.pickle\n
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
long_description = fh.read()

setup(name='nbresult',
version='0.1.0',
description='Extract results from Jupyter notebooks',
version='0.1.1',
description='Adapt post check message to context.',
Eschults marked this conversation as resolved.
Show resolved Hide resolved
license="MIT",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
31 changes: 31 additions & 0 deletions tests/test_challenge_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,34 @@ def test_subdir_is_in_the_file_path_to_add(self):
result.write()
output = result.check()
self.assertIn(f'add tests/{subdir}/unicity.pickle', output)

def test_post_check_message_when_env_not_set(self):
cwd = os.getcwd()
challenge_dir = os.path.join(os.path.dirname(__file__), 'fixtures', 'package_challenge', 'toto')
subdir = 'first_tests'
tests_dir = os.path.join(challenge_dir, 'tests', subdir)
os.chdir(challenge_dir)
result = ChallengeResult('unicity', subdir=subdir, dummy=42)
result.write()
output = result.check()
# Manual tear down
os.chdir(cwd)
os.remove(os.path.join(tests_dir, 'unicity.pickle'))

self.assertIn(f'You can commit your code', output)

def test_post_check_message_when_env_set_to_jupyterlab(self):
cwd = os.getcwd()
challenge_dir = os.path.join(os.path.dirname(__file__), 'fixtures', 'package_challenge', 'toto')
subdir = 'first_tests'
tests_dir = os.path.join(challenge_dir, 'tests', subdir)
os.chdir(challenge_dir)
result = ChallengeResult('unicity', subdir=subdir, dummy=42)
result.write()
os.environ['NBRESULT_POST_CHECK_MESSAGE'] = 'JUPYTERLAB'
output = result.check()
# Manual tear down
os.chdir(cwd)
os.remove(os.path.join(tests_dir, 'unicity.pickle'))
os.environ['NBRESULT_POST_CHECK_MESSAGE'] = ''
self.assertIn(f'You can now save your changes and move on to the next challenge', output)
Loading