Skip to content

Commit

Permalink
Attempt at testing the exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioRosado committed Jan 17, 2018
1 parent 2a75fe0 commit e04d0f1
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,22 @@ def test_pip_install_deps(self):

def test_no_pip_install(self):
opsdroid, loader = self.setup()
with mock.patch.object(subprocess, 'Popen') as mocked_popen:
mocked_popen.side_effect = FileNotFoundError()
self.assertRaises(FileNotFoundError, mocked_popen)
with mock.patch.object(loader, 'pip_install_deps') as pip_install:
mocked_popen.return_value.\
communicate.return_value = ['Test\nTest']
with mock.patch.object(loader, 'pip_install_deps') as mock_pip:
mock_pip.side_effect = FileNotFoundError()
with self.assertRaises(FileNotFoundError) as error:
mock_pip.return_value.communicate.return_value = ['Test\nTest']
loader.pip_install_deps("/path/to/some/file.txt")
self.assertTrue(pip_install.called)
self.assertTrue(mock_pip.called)

def test_no_pip_or_pip3_install(self):
opsdroid, loader = self.setup()
loader.pip_install_deps("/path/to/some/file.txt")

with mock.patch.object(subprocess, 'Popen') as mocked_popen:
mocked_popen.side_effect = FileNotFoundError()
self.assertRaises(FileNotFoundError, mocked_popen)

with mock.patch.object(subprocess, 'Popen') as mocked_2popen:
mocked_2popen.side_effect = OSError()
self.assertRaises(OSError, mocked_2popen)
mocked_popen.side_effect = [FileNotFoundError(), FileNotFoundError(), OSError()]
with self.assertRaises(OSError) as error:
loader.pip_install_deps("/path/to/some/file.txt")
self.assertEqual(error, "Pip and pip3 not found, exiting...")

def test_build_module_path(self):
config = {}
Expand Down

0 comments on commit e04d0f1

Please sign in to comment.