[stem/master] Missing is_available() mocks for unit tests

commit 734a7ebc496d1aaa6fa0a852a97a2b7232ba6370 Author: Damian Johnson <atagar@torproject.org> Date: Sun Dec 6 14:42:11 2015 -0800 Missing is_available() mocks for unit tests Our jenkins tests are presently failing in quite a few ways. First addressing some of the easiest ones about a2x not being present... ====================================================================== ERROR: test_download_man_page_when_successful ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/mock.py", line 1224, in patched return func(*args, **keywargs) File "/srv/jenkins-workspace/workspace/stem-tor-ci/test/unit/manual.py", line 214, in test_download_man_page_when_successful stem.manual.download_man_page(file_handle = output) File "/srv/jenkins-workspace/workspace/stem-tor-ci/stem/manual.py", line 196, in download_man_page raise IOError('We require a2x from asciidoc to provide a man page') IOError: We require a2x from asciidoc to provide a man page ====================================================================== FAIL: test_download_man_page_when_a2x_fails ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/mock.py", line 1224, in patched return func(*args, **keywargs) File "/srv/jenkins-workspace/workspace/stem-tor-ci/test/unit/manual.py", line 197, in test_download_man_page_when_a2x_fails self.assertEqual("Unable to run 'a2x -f manpage /no/such/path/tor.1.txt': call failed", str(exc)) AssertionError: "Unable to run 'a2x -f manpage /no/such/path/tor.1.txt': call failed" != 'We require a2x from asciidoc to provide a man page' ====================================================================== FAIL: test_download_man_page_when_download_fails ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/mock.py", line 1224, in patched return func(*args, **keywargs) File "/srv/jenkins-workspace/workspace/stem-tor-ci/test/unit/manual.py", line 185, in test_download_man_page_when_download_fails self.assertEqual("Unable to download tor's manual from https://www.atagar.com/foo/bar to /no/such/path/tor.1.txt: <urlopen error <urlopen error [Errno -2] Name or service not known>>", str(exc)) AssertionError: "Unable to download tor's manual from https://www.atagar.com/foo/bar to /no/such/path/tor.1.txt: <urlopen error <urlopen error [Errno -2] Name or service not known>>" != 'We require a2x from asciidoc to provide a man page' ====================================================================== FAIL: test_download_man_page_when_unable_to_write ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/mock.py", line 1224, in patched return func(*args, **keywargs) File "/srv/jenkins-workspace/workspace/stem-tor-ci/test/unit/manual.py", line 174, in test_download_man_page_when_unable_to_write self.assertEqual("Unable to download tor's manual from https://gitweb.torproject.org/tor.git/plain/doc/tor.1.txt to /no/such/path/tor.1.txt: unable to write to file", str(exc)) AssertionError: "Unable to download tor's manual from https://gitweb.torproject.org/tor.git/plain/doc/tor.1.txt to /no/such/path/tor.1.txt: unable to write to file" != 'We require a2x from asciidoc to provide a man page' --- test/unit/manual.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unit/manual.py b/test/unit/manual.py index 21f578d..4d9d539 100644 --- a/test/unit/manual.py +++ b/test/unit/manual.py @@ -166,6 +166,7 @@ class TestManual(unittest.TestCase): @patch('tempfile.mkdtemp', Mock(return_value = '/no/such/path')) @patch('shutil.rmtree', Mock()) @patch('stem.manual.open', Mock(side_effect = IOError('unable to write to file')), create = True) + @patch('stem.util.system.is_available', Mock(return_value = True)) def test_download_man_page_when_unable_to_write(self): try: stem.manual.download_man_page('/tmp/no_such_file') @@ -176,6 +177,7 @@ class TestManual(unittest.TestCase): @patch('tempfile.mkdtemp', Mock(return_value = '/no/such/path')) @patch('shutil.rmtree', Mock()) @patch('stem.manual.open', Mock(return_value = io.BytesIO()), create = True) + @patch('stem.util.system.is_available', Mock(return_value = True)) @patch(URL_OPEN, Mock(side_effect = urllib.URLError('<urlopen error [Errno -2] Name or service not known>'))) def test_download_man_page_when_download_fails(self): try: @@ -188,6 +190,7 @@ class TestManual(unittest.TestCase): @patch('shutil.rmtree', Mock()) @patch('stem.manual.open', Mock(return_value = io.BytesIO()), create = True) @patch('stem.util.system.call', Mock(side_effect = OSError('call failed'))) + @patch('stem.util.system.is_available', Mock(return_value = True)) @patch(URL_OPEN, Mock(return_value = io.BytesIO(b'test content'))) def test_download_man_page_when_a2x_fails(self): try: @@ -200,6 +203,7 @@ class TestManual(unittest.TestCase): @patch('shutil.rmtree', Mock()) @patch('stem.manual.open', create = True) @patch('stem.util.system.call') + @patch('stem.util.system.is_available', Mock(return_value = True)) @patch('os.path.exists', Mock(return_value = True)) @patch(URL_OPEN, Mock(return_value = io.BytesIO(b'test content'))) def test_download_man_page_when_successful(self, call_mock, open_mock):
participants (1)
-
atagar@torproject.org