Skip to content
Myr

Test side effect (#1889)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Hyunchel Kim · committed by David Lord · parent 9f9e1fd · Browse files · 1 file+18 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+18 added−3 removed

  • tests:+18 added−3 removed

1 file+18 added−3 removed

modified:tests/test_cli.py+18 added-3 removed
10 unmodified lines
11# the Revised BSD License.12# Copyright (C) 2015 CERN.13#14from __future__ import absolute_import, print_function15import os16import sys1718import click19import pytest20from click.testing import CliRunner
30 unmodified lines
51 pytest.raises(NoAppException, find_best_app, mod)525354def test_prepare_exec_for_file(test_apps):53 assert prepare_exec_for_file('test.py') == 'test'54 assert prepare_exec_for_file('/usr/share/__init__.py') == 'share'55 """Expect the correct path to be set and the correct module name to be returned.5657 :func:`prepare_exec_for_file` has a side effect, where58 the parent directory of given file is added to `sys.path`.59 """60 realpath = os.path.realpath('/tmp/share/test.py')61 dirname = os.path.dirname(realpath)62 assert prepare_exec_for_file('/tmp/share/test.py') == 'test'63 assert dirname in sys.path6465 realpath = os.path.realpath('/tmp/share/__init__.py')66 dirname = os.path.dirname(os.path.dirname(realpath))67 assert prepare_exec_for_file('/tmp/share/__init__.py') == 'share'68 assert dirname in sys.path6970 with pytest.raises(NoAppException):56 prepare_exec_for_file('test.txt')71 prepare_exec_for_file('/tmp/share/test.txt')727374def test_locate_app(test_apps):75 """Test of locate_app."""
83 unmodified lines