Skip to content

Commit

Permalink
Modify test for check for activation/deactivation
Browse files Browse the repository at this point in the history
Key should be removed and not set to false to deactivate
  • Loading branch information
Carreau committed Mar 25, 2015
1 parent ab2c80a commit 769af17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
7 changes: 6 additions & 1 deletion nbgrader/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ def deactivate(profile=None, ipython_dir=None):
if 'nbgrader/create_assignment' not in config['load_extensions']:
return

config['load_extensions']['nbgrader/create_assignment'] = False
# deactivation require the delete thr key.
del config['load_extensions']['nbgrader/create_assignment']

# prune if last extension.
if config['load_extension']:
del config['load_extension']

with io.open(json_file, 'w+') as f:
f.write(cast_unicode_py2(json.dumps(config, indent=2), 'utf-8'))
Expand Down
34 changes: 18 additions & 16 deletions nbgrader/tests/test_nbextension.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
from copy import copy

from nose.tools import assert_equal
from nose.tools import assert_equal, assert_raises

from selenium import webdriver
from selenium.webdriver.common.by import By
Expand All @@ -16,6 +16,16 @@

from nbgrader.install import main

def _assert_is_deactivated(config_file):
with open(config_file, 'r') as fh:
config = json.load(fh)
assert_raises(KeyError, config['load_extensions']['nbgrader/create_assignment'])

def _assert_is_activated(config_file):
with open(config_file, 'r') as fh:
config = json.load(fh)
assert config['load_extensions']['nbgrader/create_assignment']


class TestCreateAssignmentNbExtension(object):

Expand Down Expand Up @@ -129,16 +139,13 @@ def test_00_install_extension(self):

# check that it is activated
config_file = os.path.join(self.ipythondir, 'profile_default', 'nbconfig', 'notebook.json')
with open(config_file, 'r') as fh:
config = json.load(fh)
assert config['load_extensions']['nbgrader/create_assignment']
_assert_is_activated(config_file)


def test_01_deactivate_extension(self):
# check that it is activated
config_file = os.path.join(self.ipythondir, 'profile_default', 'nbconfig', 'notebook.json')
with open(config_file, 'r') as fh:
config = json.load(fh)
assert config['load_extensions']['nbgrader/create_assignment']
_assert_is_activated(config_file)

main([
'--deactivate',
Expand All @@ -148,16 +155,12 @@ def test_01_deactivate_extension(self):
])

# check that it is deactivated
with open(config_file, 'r') as fh:
config = json.load(fh)
assert not config.get('load_extensions', {}).get('nbgrader/create_assignment', False)
_assert_is_deactivated(config_file)

def test_02_activate_extension(self):
# check that it is deactivated
config_file = os.path.join(self.ipythondir, 'profile_default', 'nbconfig', 'notebook.json')
with open(config_file, 'r') as fh:
config = json.load(fh)
assert not config.get('load_extensions', {}).get('nbgrader/create_assignment', False)
_assert_is_deactivated(config_file)

main([
'--activate',
Expand All @@ -167,9 +170,8 @@ def test_02_activate_extension(self):
])

# check that it is activated
with open(config_file, 'r') as fh:
config = json.load(fh)
assert config['load_extensions']['nbgrader/create_assignment']
_assert_is_activated(config_file)


def test_create_assignment(self):
self._activate_toolbar()
Expand Down

0 comments on commit 769af17

Please sign in to comment.