diff options
| author | Damian Johnson <atagar@torproject.org> | 2017-05-23 16:38:42 -0700 |
|---|---|---|
| committer | Damian Johnson <atagar@torproject.org> | 2017-05-23 16:41:16 -0700 |
| commit | 46fc50b4d1d9a3c006691af01f38f9ec80023b00 (patch) | |
| tree | 881bfbd41f6afec727f75d7303bae174533cf339 | |
| parent | a9af1b665b2aa85de6ecdc4011f6935fd0299804 (diff) | |
| parent | 3bf77ecf6e2d16eca768834f1e7da75e53eda6b0 (diff) | |
Let tests pass without a PATH
catalyst ran into some issues where stem's tests didn't pass on his setup...
https://trac.torproject.org/projects/tor/ticket/22301
Tests now pass when I run...
% env -i ./run_tests.py --all --tor ../tor/src/or/tor
| -rw-r--r-- | stem/util/system.py | 2 | ||||
| -rw-r--r-- | test/integ/installation.py | 11 | ||||
| -rw-r--r-- | test/integ/process.py | 4 | ||||
| -rw-r--r-- | test/integ/util/system.py | 4 |
4 files changed, 13 insertions, 8 deletions
diff --git a/stem/util/system.py b/stem/util/system.py index 4b705f34..7b315169 100644 --- a/stem/util/system.py +++ b/stem/util/system.py @@ -247,6 +247,8 @@ def is_available(command, cached=True): return True elif cached and command in CMD_AVAILABLE_CACHE: return CMD_AVAILABLE_CACHE[command] + elif 'PATH' not in os.environ: + return False # lacking a path will cause find_executable() to internally fail else: cmd_exists = distutils.spawn.find_executable(command) is not None CMD_AVAILABLE_CACHE[command] = cmd_exists diff --git a/test/integ/installation.py b/test/integ/installation.py index 1cb9471f..16da8179 100644 --- a/test/integ/installation.py +++ b/test/integ/installation.py @@ -20,6 +20,7 @@ INSTALL_MISMATCH_MSG = "Running 'python setup.py sdist' doesn't match our git co BASE_INSTALL_PATH = '/tmp/stem_test' DIST_PATH = os.path.join(test.STEM_BASE, 'dist') SETUP_THREAD, INSTALL_FAILURE, INSTALL_PATH, SDIST_FAILURE = None, None, None, None +PYTHON_EXE = sys.executable if sys.executable else 'python' def setup(): @@ -35,12 +36,10 @@ def setup(): original_cwd = os.getcwd() try: - os.chdir(test.STEM_BASE) - try: os.chdir(test.STEM_BASE) - stem.util.system.call('%s setup.py install --prefix %s' % (sys.executable, BASE_INSTALL_PATH), timeout = 60) - stem.util.system.call('%s setup.py clean --all' % sys.executable, timeout = 60) # tidy up the build directory + stem.util.system.call('%s setup.py install --prefix %s' % (PYTHON_EXE, BASE_INSTALL_PATH), timeout = 60) + stem.util.system.call('%s setup.py clean --all' % PYTHON_EXE, timeout = 60) # tidy up the build directory site_packages_paths = glob.glob('%s/lib*/*/site-packages' % BASE_INSTALL_PATH) if len(site_packages_paths) != 1: @@ -52,7 +51,7 @@ def setup(): if not os.path.exists(DIST_PATH): try: - stem.util.system.call('%s setup.py sdist' % sys.executable, timeout = 60) + stem.util.system.call('%s setup.py sdist' % PYTHON_EXE, timeout = 60) except Exception as exc: SDIST_FAILURE = exc else: @@ -121,7 +120,7 @@ class TestInstallation(unittest.TestCase): if INSTALL_FAILURE: raise INSTALL_FAILURE - self.assertEqual(stem.__version__, stem.util.system.call([sys.executable, '-c', "import sys;sys.path.insert(0, '%s');import stem;print(stem.__version__)" % INSTALL_PATH])[0]) + self.assertEqual(stem.__version__, stem.util.system.call([PYTHON_EXE, '-c', "import sys;sys.path.insert(0, '%s');import stem;print(stem.__version__)" % INSTALL_PATH])[0]) _assert_has_all_files(INSTALL_PATH) @test.require.only_run_once diff --git a/test/integ/process.py b/test/integ/process.py index 1ca0f706..95c14cbd 100644 --- a/test/integ/process.py +++ b/test/integ/process.py @@ -96,8 +96,8 @@ class TestProcess(unittest.TestCase): hush to cut it down. """ - output = self.run_tor('--hush', '--hash-password', 'my_password') - self.assertTrue(re.match('^16:[0-9A-F]{58}\n$', output)) + output = self.run_tor('--hush', '--hash-password', 'my_password').splitlines()[-1] + self.assertTrue(re.match('^16:[0-9A-F]{58}$', output)) # I'm not gonna even pretend to understand the following. Ported directly # from tor's test_cmdline_args.py. diff --git a/test/integ/util/system.py b/test/integ/util/system.py index 912251b9..07d7d752 100644 --- a/test/integ/util/system.py +++ b/test/integ/util/system.py @@ -66,9 +66,11 @@ require_single_tor_instance = test.require.needs(_is_single_tor_running, 'multip require_control_port = test.require.needs(_has_port, 'test instance has no port') require_linux = test.require.needs(_is_linux, 'linux only') require_bsd = test.require.needs(stem.util.system.is_bsd, 'bsd only') +require_path = test.require.needs(lambda: 'PATH' in os.environ, 'requires PATH') class TestSystem(unittest.TestCase): + @require_path def test_is_available(self): """ Checks the stem.util.system.is_available function. @@ -99,6 +101,7 @@ class TestSystem(unittest.TestCase): self.assertTrue(stem.util.system.is_running(tor_cmd) or stem.util.system.is_running('tor.real')) self.assertFalse(stem.util.system.is_running('blarg_and_stuff')) + @require_path @require_single_tor_instance def test_pid_by_name(self): """ @@ -312,6 +315,7 @@ class TestSystem(unittest.TestCase): os.rmdir(tmpdir) self.assertEqual(None, stem.util.system.pid_by_open_file(tmpdir)) + @require_path def test_pids_by_user(self): """ Checks the stem.util.system.pids_by_user function. |
