Skip to content

Instantly share code, notes, and snippets.

@ewongbb
Created September 8, 2017 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ewongbb/6ddce01a75db93a35b07a6147ec39dea to your computer and use it in GitHub Desktop.
Save ewongbb/6ddce01a75db93a35b07a6147ec39dea to your computer and use it in GitHub Desktop.
testing
diff --git a/stem/util/system.py b/stem/util/system.py
index 53c06ac..4752779 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -24,8 +24,6 @@ best-effort, providing **None** if the lookup fails.
is_bsd - checks if we're running on the bsd family of operating systems
is_slackware - checks if we're running on slackware
- has_encoding_man - checks if the system's man command has --encoding=ascii available
-
is_available - determines if a command is available on this system
is_running - determines if a given process is running
size_of - provides the memory usage of an object
@@ -313,18 +311,6 @@ class DaemonTask(object):
conn.close()
-def has_encoding_man():
- """
- Checks if --encoding=ascii is available for man
- """
- retval = True
- if is_available('man'):
- result = call('man --encoding=ascii man', [], error_return=True)
- if 'unrecognized option' in result:
- retval = False
- return retval
-
-
def is_windows():
"""
Checks if we are running on Windows.
@@ -1238,8 +1224,7 @@ def files_with_suffix(base_path, suffix):
yield os.path.join(root, filename)
-def call(command, default = UNDEFINED, ignore_exit_status = False, timeout = None,
- cwd = None, env = None, error_return = False):
+def call(command, default = UNDEFINED, ignore_exit_status = False, timeout = None, cwd = None, env = None):
"""
call(command, default = UNDEFINED, ignore_exit_status = False)
@@ -1311,10 +1296,7 @@ def call(command, default = UNDEFINED, ignore_exit_status = False, timeout = Non
exit_status = process.poll()
if not ignore_exit_status and exit_status != 0:
- if error_return:
- return stderr
- else:
- OSError('%s returned exit status %i' % (command, exit_status))
+ raise OSError('%s returned exit status %i' % (command, exit_status))
if stdout:
return stdout.decode('utf-8', 'replace').splitlines()
diff --git a/test/integ/manual.py b/test/integ/manual.py
index 85de28c..846b1b6 100644
--- a/test/integ/manual.py
+++ b/test/integ/manual.py
@@ -107,7 +107,7 @@ class TestManual(unittest.TestCase):
stem.manual.download_man_page(file_handle = tmp)
self.man_path = tmp.name
- man_cmd = 'man %s -P cat %s' % ('' if not stem.util.system.has_encoding_man() else '--encoding=ascii', self.man_path)
+ man_cmd = 'man %s -P cat %s' % ('' if stem.util.system.is_mac() else '--encoding=ascii', self.man_path)
self.man_content = stem.util.system.call(man_cmd, env = {'MANWIDTH': '10000000'})
except Exception as exc:
self.download_error = 'Unable to download the man page: %s' % exc
diff --git a/test/unit/manual.py b/test/unit/manual.py
index 9850e82..cd850af 100644
--- a/test/unit/manual.py
+++ b/test/unit/manual.py
@@ -153,8 +153,8 @@ class TestManual(unittest.TestCase):
expand our example (or add another).
"""
- if not stem.util.system.has_encoding_man():
- self.skipTest('(man lacks --encoding arg on OSX, BSD, and Slackware #18660)')
+ if stem.util.system.is_mac() or stem.util.system.is_bsd() or stem.util.system.is_slackware():
+ self.skipTest('(man lacks --encoding arg on OSX and BSD, #18660)')
return
manual = stem.manual.Manual.from_man(EXAMPLE_MAN_PATH)
@@ -174,7 +174,7 @@ class TestManual(unittest.TestCase):
options. Unlike most other tests this doesn't require network access.
"""
- if not stem.util.system.has_encoding_man():
+ if stem.util.system.is_mac() or stem.util.system.is_bsd() or stem.util.system.is_slackware():
self.skipTest('(man lacks --encoding arg on OSX and BSD and Slackware, #18660)')
return
@@ -202,8 +202,8 @@ class TestManual(unittest.TestCase):
Check that we can save and reload manuals as a config.
"""
- if not stem.util.system.has_encoding_man():
- self.skipTest('(man lacks --encoding arg on OSX, BSD and Slackware, #18660)')
+ if stem.util.system.is_mac() or stem.util.system.is_bsd():
+ self.skipTest('(man lacks --encoding arg on OSX and BSD, #18660)')
return
manual = stem.manual.Manual.from_man(EXAMPLE_MAN_PATH)
@@ -219,8 +219,8 @@ class TestManual(unittest.TestCase):
Check that we can save and reload manuals as sqlite.
"""
- if not stem.util.system.has_encoding_man():
- self.skipTest('(man lacks --encoding arg on OSX, BSD, and Slackware #18660)')
+ if stem.util.system.is_mac() or stem.util.system.is_bsd():
+ self.skipTest('(man lacks --encoding arg on OSX and BSD, #18660)')
return
manual = stem.manual.Manual.from_man(EXAMPLE_MAN_PATH)
@@ -297,9 +297,8 @@ class TestManual(unittest.TestCase):
self.assertEqual(b'a2x output', output.getvalue())
call_mock.assert_called_once_with('a2x -f manpage /no/such/path/tor.1.txt')
- @patch('stem.util.system.has_encoding_man', Mock(return_value = True))
- @patch('stem.util.system.is_bsd', Mock(return_value = False))
@patch('stem.util.system.is_mac', Mock(return_value = False))
+ @patch('stem.util.system.is_bsd', Mock(return_value = False))
@patch('stem.util.system.is_slackware', Mock(return_value = False))
@patch('stem.util.system.call', Mock(side_effect = OSError('man --encoding=ascii -P cat tor returned exit status 16')))
def test_from_man_when_manual_is_unavailable(self):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment