diff --git a/pythonbrew/commands/py.py b/pythonbrew/commands/py.py index d6b90fa..1a052b9 100644 --- a/pythonbrew/commands/py.py +++ b/pythonbrew/commands/py.py @@ -4,7 +4,7 @@ from pythonbrew.basecommand import Command from pythonbrew.define import PATH_PYTHONS from pythonbrew.util import Package from pythonbrew.log import logger -from subprocess import PIPE, Popen +from subprocess import Popen class PyCommand(Command): name = "py" diff --git a/pythonbrew/commands/switch.py b/pythonbrew/commands/switch.py index 6ad1ffe..d553ccb 100644 --- a/pythonbrew/commands/switch.py +++ b/pythonbrew/commands/switch.py @@ -1,8 +1,8 @@ import os import sys from pythonbrew.basecommand import Command -from pythonbrew.define import PATH_PYTHONS, PATH_BIN, PATH_ETC_CURRENT -from pythonbrew.util import Package +from pythonbrew.define import PATH_PYTHONS, PATH_BIN +from pythonbrew.util import Package, set_current_path from pythonbrew.log import logger class SwitchCommand(Command): @@ -22,14 +22,8 @@ class SwitchCommand(Command): sys.exit(1) pkgbin = os.path.join(pkgdir,'bin') - self._set_current('%s:%s' % (PATH_BIN, pkgbin)) + set_current_path('%s:%s' % (PATH_BIN, pkgbin)) logger.info("Switched to %s" % pkgname) - - def _set_current(self, path): - fp = open(PATH_ETC_CURRENT, 'w') - fp.write('PATH_PYTHONBREW="%s"\n' % (path)) - fp.close() - SwitchCommand() diff --git a/pythonbrew/commands/update.py b/pythonbrew/commands/update.py index b17eb00..2462eb3 100644 --- a/pythonbrew/commands/update.py +++ b/pythonbrew/commands/update.py @@ -22,7 +22,7 @@ class UpdateCommand(Command): # check for latest version if version <= VERSION: logger.info("You are already running the installed latest version of pythonbrew.") - sys.exit() + return download_url = get_pythonbrew_update_url(version) if not download_url: diff --git a/pythonbrew/installer.py b/pythonbrew/installer.py index 585992e..32c0c15 100644 --- a/pythonbrew/installer.py +++ b/pythonbrew/installer.py @@ -4,7 +4,7 @@ import glob import shutil import re import mimetypes -from pythonbrew.util import makedirs, symlink, Package, is_url, splitext, Link,\ +from pythonbrew.util import makedirs, symlink, Package, is_url, Link,\ unlink, is_html, Subprocess, rm_r,\ is_macosx_snowleopard, is_python25, is_python24, is_python26,\ unpack_downloadfile, is_archive_file, path_to_fileurl, is_file,\ diff --git a/pythonbrew/util.py b/pythonbrew/util.py index 9b83163..3491017 100644 --- a/pythonbrew/util.py +++ b/pythonbrew/util.py @@ -8,8 +8,7 @@ import tarfile import platform import urllib from subprocess import PIPE, Popen -from pythonbrew.define import PATH_BIN, PATH_PYTHONS, PATH_ETC_CURRENT,\ - PATH_ETC_TEMP +from pythonbrew.define import PATH_BIN, PATH_PYTHONS, PATH_ETC_CURRENT from pythonbrew.exceptions import ShellCommandException from pythonbrew.log import logger @@ -108,7 +107,7 @@ def off(): continue unlink("%s/%s" % (root, f)) unlink("%s/current" % PATH_PYTHONS) - write_current(PATH_BIN) + set_current_path(PATH_BIN) def split_leading_dir(path): path = str(path) @@ -202,6 +201,11 @@ def get_current_python_path(): else: return None +def set_current_path(path): + fp = open(PATH_ETC_CURRENT, 'w') + fp.write('PATH_PYTHONBREW="%s"\n' % (path)) + fp.close() + def path_to_fileurl(path): path = os.path.normcase(os.path.abspath(path)) url = urllib.quote(path) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..d21f0fd --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,21 @@ +import os +import shutil + +PYTHONBREW_ROOT = '/tmp/pythonbrew.test' +TESTPY_FILE = '/tmp/pythonbrew_test.py' +TESTPY_VERSION = '2.6.6' +def cleanall(): + if os.path.isdir(PYTHONBREW_ROOT): + shutil.rmtree(PYTHONBREW_ROOT) + if os.path.isfile(TESTPY_FILE): + os.remove(TESTPY_FILE) + +def setup(): + os.environ['PYTHONBREW_ROOT'] = PYTHONBREW_ROOT + cleanall() + fp = open(TESTPY_FILE, 'w') + fp.write("print 'test'") + fp.close() + +def teardown(): + cleanall() diff --git a/tests/test_00_install_pythonbrew.py b/tests/test_00_install_pythonbrew.py new file mode 100644 index 0000000..bef3c06 --- /dev/null +++ b/tests/test_00_install_pythonbrew.py @@ -0,0 +1,3 @@ +def test_install_pythonbrew(): + from pythonbrew.installer import install_pythonbrew + install_pythonbrew() diff --git a/tests/test_01_update.py b/tests/test_01_update.py new file mode 100644 index 0000000..884c11e --- /dev/null +++ b/tests/test_01_update.py @@ -0,0 +1,5 @@ +def test_update(): + from pythonbrew.commands.update import UpdateCommand + c = UpdateCommand() + c.run_command(None, None) + \ No newline at end of file diff --git a/tests/test_02_help.py b/tests/test_02_help.py new file mode 100644 index 0000000..be0c836 --- /dev/null +++ b/tests/test_02_help.py @@ -0,0 +1,4 @@ +def test_help(): + from pythonbrew.commands.help import HelpCommand + c = HelpCommand() + c.run_command(None, None) diff --git a/tests/test_03_version.py b/tests/test_03_version.py new file mode 100644 index 0000000..1db366a --- /dev/null +++ b/tests/test_03_version.py @@ -0,0 +1,4 @@ +def test_version(): + from pythonbrew.commands.version import VersionCommand + c = VersionCommand() + c.run_command(None, None) diff --git a/tests/test_04_install.py b/tests/test_04_install.py new file mode 100644 index 0000000..0b1722f --- /dev/null +++ b/tests/test_04_install.py @@ -0,0 +1,11 @@ +from tests import TESTPY_VERSION + +class InstallOptions(object): + force = True + configure = "" + no_setuptools = False + +def test_install(): + from pythonbrew.commands.install import InstallCommand + c = InstallCommand() + c.run_command(InstallOptions(), [TESTPY_VERSION]) diff --git a/tests/test_05_switch.py b/tests/test_05_switch.py new file mode 100644 index 0000000..e6d9fe2 --- /dev/null +++ b/tests/test_05_switch.py @@ -0,0 +1,6 @@ +from tests import TESTPY_VERSION + +def test_switch(): + from pythonbrew.commands.switch import SwitchCommand + c = SwitchCommand() + c.run_command(None, [TESTPY_VERSION]) diff --git a/tests/test_06_use.py b/tests/test_06_use.py new file mode 100644 index 0000000..ebd5ce3 --- /dev/null +++ b/tests/test_06_use.py @@ -0,0 +1,6 @@ +from tests import TESTPY_VERSION + +def test_use(): + from pythonbrew.commands.use import UseCommand + c = UseCommand() + c.run_command(None, [TESTPY_VERSION]) diff --git a/tests/test_07_off.py b/tests/test_07_off.py new file mode 100644 index 0000000..60e9f65 --- /dev/null +++ b/tests/test_07_off.py @@ -0,0 +1,4 @@ +def test_off(): + from pythonbrew.commands.off import OffCommand + c = OffCommand() + c.run_command(None, None) diff --git a/tests/test_08_list.py b/tests/test_08_list.py new file mode 100644 index 0000000..7d5ab7e --- /dev/null +++ b/tests/test_08_list.py @@ -0,0 +1,8 @@ +class ListOptions(object): + all_versions = False + known = False + +def test_list(): + from pythonbrew.commands.list import ListCommand + c = ListCommand() + c.run_command(ListOptions(), None) diff --git a/tests/test_09_py.py b/tests/test_09_py.py new file mode 100644 index 0000000..54f7e8c --- /dev/null +++ b/tests/test_09_py.py @@ -0,0 +1,10 @@ +from tests import TESTPY_FILE + +class PyOptions(object): + pythons = [] + verbose = False + +def test_py(): + from pythonbrew.commands.py import PyCommand + c = PyCommand() + c.run_command(PyOptions(), [TESTPY_FILE]) diff --git a/tests/test_10_uninstall.py b/tests/test_10_uninstall.py new file mode 100644 index 0000000..3327b77 --- /dev/null +++ b/tests/test_10_uninstall.py @@ -0,0 +1,6 @@ +from tests import TESTPY_VERSION + +def test_uninstall(): + from pythonbrew.commands.uninstall import UninstallCommand + c = UninstallCommand() + c.run_command(None, [TESTPY_VERSION]) diff --git a/tests/test_11_clean.py b/tests/test_11_clean.py new file mode 100644 index 0000000..7823339 --- /dev/null +++ b/tests/test_11_clean.py @@ -0,0 +1,4 @@ +def test_clean(): + from pythonbrew.commands.clean import CleanCommand + c = CleanCommand() + c.run_command(None, None)