Skip to content

Commit

Permalink
Add setup and teardown functions so tests pass even when JUPYTER_PREF…
Browse files Browse the repository at this point in the history
…ER_ENV_PATH is defined in the environment
  • Loading branch information
jasongrout committed Oct 12, 2021
1 parent 7a8e44c commit 8a06609
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 9 additions & 0 deletions jupyter_core/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
)


resetenv = patch.dict(os.environ)

def setup_module():
resetenv.start()
os.environ.pop('JUPYTER_PREFER_ENV_PATH', None)

def teardown_module():
resetenv.stop()

def get_jupyter_output(cmd):
"""Get output of a jupyter command"""
if not isinstance(cmd, list):
Expand Down
16 changes: 13 additions & 3 deletions jupyter_core/tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,24 @@

jupyter_config_env = '/jupyter-cfg'
config_env = patch.dict('os.environ', {'JUPYTER_CONFIG_DIR': jupyter_config_env})
prefer_env = patch.dict('os.environ', {'JUPYTER_PREFER_ENV_PATH': 'True'})

resetenv = patch.dict(os.environ)

def setup_module():
resetenv.start()
os.environ.pop('JUPYTER_PREFER_ENV_PATH', None)

def teardown_module():
resetenv.stop()



def realpath(path):
return os.path.abspath(os.path.realpath(os.path.expanduser(path)))

home_jupyter = realpath('~/.jupyter')


def test_envset():
true_values = ['', 'True', 'on', 'yes', 'Y', '1', 'anything']
false_values = ['n', 'No', 'N', 'fAlSE', '0', '0.0', 'Off']
Expand Down Expand Up @@ -199,7 +209,7 @@ def test_jupyter_path_no_user_site():
assert path[1] == paths.ENV_JUPYTER_PATH[0]

def test_jupyter_path_prefer_env():
with patch.dict('os.environ', {'JUPYTER_PREFER_ENV_PATH': 'true'}):
with prefer_env:
path = jupyter_path()
assert path[0] == paths.ENV_JUPYTER_PATH[0]
assert path[1] == jupyter_data_dir()
Expand Down Expand Up @@ -241,7 +251,7 @@ def test_jupyter_config_path_no_user_site():


def test_jupyter_config_path_prefer_env():
with patch.dict('os.environ', {'JUPYTER_PREFER_ENV_PATH': 'true'}):
with prefer_env:
path = jupyter_config_path()
assert path[0] == paths.ENV_CONFIG_PATH[0]
assert path[1] == jupyter_config_dir()
Expand Down

0 comments on commit 8a06609

Please sign in to comment.