Browse Source

Test side effect (#1889)

Function `prepare_exec_for_file` has a side effect where a path is added to
`sys.path` list.
This commit enhances an exisiting test case for `prepare_exec_for_file`
by testing the side effect of the function and adding necessary
comments.
pull/1873/merge
Hyunchel Kim 9 years ago committed by David Lord
parent
commit
64a37bb9b7
  1. 21
      tests/test_cli.py

21
tests/test_cli.py

@ -12,6 +12,8 @@
# Copyright (C) 2015 CERN. # Copyright (C) 2015 CERN.
# #
from __future__ import absolute_import, print_function from __future__ import absolute_import, print_function
import os
import sys
import click import click
import pytest import pytest
@ -50,10 +52,23 @@ def test_find_best_app(test_apps):
def test_prepare_exec_for_file(test_apps): def test_prepare_exec_for_file(test_apps):
assert prepare_exec_for_file('test.py') == 'test' """Expect the correct path to be set and the correct module name to be returned.
assert prepare_exec_for_file('/usr/share/__init__.py') == 'share'
:func:`prepare_exec_for_file` has a side effect, where
the parent directory of given file is added to `sys.path`.
"""
realpath = os.path.realpath('/tmp/share/test.py')
dirname = os.path.dirname(realpath)
assert prepare_exec_for_file('/tmp/share/test.py') == 'test'
assert dirname in sys.path
realpath = os.path.realpath('/tmp/share/__init__.py')
dirname = os.path.dirname(os.path.dirname(realpath))
assert prepare_exec_for_file('/tmp/share/__init__.py') == 'share'
assert dirname in sys.path
with pytest.raises(NoAppException): with pytest.raises(NoAppException):
prepare_exec_for_file('test.txt') prepare_exec_for_file('/tmp/share/test.txt')
def test_locate_app(test_apps): def test_locate_app(test_apps):

Loading…
Cancel
Save