diff options
| author | Paul Nasrat <pnasrat@gmail.com> | 2011-04-21 11:10:11 +0100 |
|---|---|---|
| committer | Paul Nasrat <pnasrat@gmail.com> | 2011-04-21 15:31:17 +0100 |
| commit | 5d57c4cb78fb9ba17027deadbafdda01efea12e1 (patch) | |
| tree | c93b649f9bde07ec165e018bb26695824563f79e /tests | |
| parent | e48487561417f81ba232a3016572e7aaecc67248 (diff) | |
| download | virtualenv-5d57c4cb78fb9ba17027deadbafdda01efea12e1.tar.gz | |
Prevent traceback with non-exec interpreter
Fixes #121
Add tests for virtualenv with nose and mock
Add helper method to virtualenv for is_executable
Raise SystemExit rather than sys.exit directly
Tested on 2.4.4, 2.7.1 and 3.2
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_virtualenv.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py new file mode 100644 index 0000000..9faad8a --- /dev/null +++ b/tests/test_virtualenv.py @@ -0,0 +1,75 @@ +import virtualenv +from mock import patch, Mock +import os.path +import sys + +def test_version(): + """Should have a version string""" + assert virtualenv.virtualenv_version == "1.6", "Should have version" + +@patch('os.path.exists') +@patch('os.path.abspath') +def test_resolve_interpreter_with_absolute_path(mock_abspath, mock_exists): + """Should return absolute path if given and exists""" + mock_abspath.return_value = True + mock_exists.return_value = True + virtualenv.is_executable = Mock(return_value=True) + + mock_abspath.start() + mock_exists.start() + + exe = virtualenv.resolve_interpreter("/usr/bin/python42") + + assert exe == "/usr/bin/python42", "Absolute path should return as is" + mock_abspath.assert_called_with("/usr/bin/python42") + mock_exists.assert_called_with("/usr/bin/python42") + virtualenv.is_executable.assert_called_with("/usr/bin/python42") + + mock_abspath.stop() + mock_exists.stop() + +@patch('os.path.exists') +@patch('os.path.abspath') +def test_resolve_intepreter_with_nonexistant_interpreter(mock_abspath, mock_exists): + """Should exit when with absolute path if not exists""" + mock_abspath.return_value = True + mock_exists.return_value = False + + mock_abspath.start() + mock_exists.start() + + try: + exe = virtualenv.resolve_interpreter("/usr/bin/python42") + assert False, "Should raise exception" + except SystemExit: + pass + + mock_abspath.assert_called_with("/usr/bin/python42") + mock_exists.assert_called_with("/usr/bin/python42") + + mock_abspath.stop() + mock_exists.stop() + +@patch('os.path.exists') +@patch('os.path.abspath') +def test_resolve_intepreter_with_invalid_interpreter(mock_abspath, mock_exists): + """Should exit when with absolute path if not exists""" + mock_abspath.return_value = True + mock_exists.return_value = True + virtualenv.is_executable = Mock(return_value=False) + + mock_abspath.start() + mock_exists.start() + + try: + exe = virtualenv.resolve_interpreter("/usr/bin/python42") + assert False, "Should raise exception" + except SystemExit: + pass + + mock_abspath.assert_called_with("/usr/bin/python42") + mock_exists.assert_called_with("/usr/bin/python42") + virtualenv.is_executable.assert_called_with("/usr/bin/python42") + + mock_abspath.stop() + mock_exists.stop() |
