Created
August 26, 2016 16:20
-
-
Save hiraq/db4b5029a5d95f4415864d226a1b79e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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