Skip to content

Instantly share code, notes, and snippets.

@hiraq
Created August 26, 2016 16:20
Show Gist options
  • Save hiraq/db4b5029a5d95f4415864d226a1b79e7 to your computer and use it in GitHub Desktop.
Save hiraq/db4b5029a5d95f4415864d226a1b79e7 to your computer and use it in GitHub Desktop.
import unittest
import mock
from module.my_class_a import MyClassA
class TestMyClassA(unittest.TestCase):
def setUp(self):
self._fake_path = '/path/to/the/fake/yaml/file'
@mock.patch('module.my_class_a.yaml')
def test_to_test(self, mock_yaml):
a = MyClassA()
mock_yaml.load = mock.MagicMock()
mock_yaml.load.return_value = dict(test='testing')
mock_open = mock.mock_open()
with patch('module.my_class_a.open', mock_open, create=True):
output = a.to_test(self._fake_path)
self.assertEqual('testing', output['test'])
mock_yaml.load.assert_called_with()
mock_open.assert_called_with(self._fake_path, 'r')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment