commit a6ea923c7a6dfb6c20620955382a4b6d469ab31f Author: Damian Johnson atagar@torproject.org Date: Mon Apr 20 19:09:30 2015 -0700
Test for 'python setup.py install'
This has been a hole in our tests for quite some time, biting us from time to time during releas time...
https://trac.torproject.org/projects/tor/ticket/15258
Just a simple test for now. Might expand this in the future with more assertions. --- stem/util/system.py | 11 ++++++++--- test/integ/installation.py | 32 ++++++++++++++++++++++++++++++++ test/settings.cfg | 1 + 3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/stem/util/system.py b/stem/util/system.py index c263ce3..aa13cb9 100644 --- a/stem/util/system.py +++ b/stem/util/system.py @@ -957,7 +957,7 @@ def call(command, default = UNDEFINED, ignore_exit_status = False): results. This is not actually ran in a shell so pipes and other shell syntax are not permitted.
- :param str command: command to be issued + :param str,list command: command to be issued :param object default: response if the query fails :param bool ignore_exit_status: reports failure if our command's exit status was non-zero @@ -967,11 +967,16 @@ def call(command, default = UNDEFINED, ignore_exit_status = False): :raises: **OSError** if this fails and no default was provided """
+ if isinstance(command, str): + command_list = command.split(' ') + else: + command_list = command + try: - is_shell_command = command.split(' ')[0] in SHELL_COMMANDS + is_shell_command = command_list[0] in SHELL_COMMANDS
start_time = time.time() - process = subprocess.Popen(command.split(), stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = is_shell_command) + process = subprocess.Popen(command_list, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = is_shell_command)
stdout, stderr = process.communicate() stdout, stderr = stdout.strip(), stderr.strip() diff --git a/test/integ/installation.py b/test/integ/installation.py new file mode 100644 index 0000000..618cd4e --- /dev/null +++ b/test/integ/installation.py @@ -0,0 +1,32 @@ +import glob +import os +import shutil +import unittest + +import stem +import stem.util.system + +import test.runner + + +class TestInstallation(unittest.TestCase): + def test_installing_stem(self): + base_directory = os.path.sep.join(__file__.split(os.path.sep)[:-3]) + + if not os.path.exists(os.path.sep.join([base_directory, 'setup.py'])): + test.runner.skip(self, "(only for git checkout)") + + original_cwd = os.getcwd() + + try: + os.chdir(base_directory) + stem.util.system.call('python setup.py install --prefix /tmp/stem_test') + site_packages_paths = glob.glob('/tmp/stem_test/lib/*/site-packages') + + if len(site_packages_paths) != 1: + self.fail("We should only have a single site-packages directory, but instead had: %s" % site_packages_paths) + + self.assertEqual(stem.__version__, stem.util.system.call(['python', '-c', "import sys;sys.path.insert(0, '%s');import stem;print stem.__version__" % site_packages_paths[0]])[0]) + finally: + shutil.rmtree('/tmp/stem_test') + os.chdir(original_cwd) diff --git a/test/settings.cfg b/test/settings.cfg index 21f5eb2..79fec01 100644 --- a/test/settings.cfg +++ b/test/settings.cfg @@ -201,6 +201,7 @@ test.integ_tests |test.integ.util.connection.TestConnection |test.integ.util.proc.TestProc |test.integ.util.system.TestSystem +|test.integ.installation.TestInstallation |test.integ.descriptor.remote.TestDescriptorDownloader |test.integ.descriptor.server_descriptor.TestServerDescriptor |test.integ.descriptor.extrainfo_descriptor.TestExtraInfoDescriptor
tor-commits@lists.torproject.org