def test_load_reads_file_as_json(self): load('file.json') open_context_mock = self.open_mock.return_value \ .__enter__.return_value self.json_mock.load.assert_called_once_with(open_context_mock)
def load_all(): return files.load('data/parts.json')
def test_load_returns_empty_list_when_file_not_found(self): self.open_mock.side_effect = FileNotFoundError result = load('file.json') self.assertEqual([], result)
def test_load_returns_loaded_json(self): self.json_mock.load.return_value = [{'name': 2}] result = load('file.json') self.assertEqual([{'name': 2}], result)
def test_load_sets_read_permissions_for_open(self): load('file.json') self.open_mock.assert_called_once_with(ANY, 'r')
def test_load_sets_path_to_file(self): load('file.json') self.open_mock.assert_called_once_with('file.json', ANY)