def test_get_issues(self, mock_json, mock_close): logger = Logger() logger._issues = {'1': 'any issue', '2': 'any other issue'} self.assertEqual(logger._issues, {'1': 'any issue', '2': 'any other issue'}) mocked_file = mock_open(read_data='any line\nany other line\n') with patch('builtins.open', mocked_file): issues = logger.get_issues() result = [issue for issue in issues] mock_close.assert_called() mock_json.loads.assert_has_calls([call('any line'), call('any other line')])
def test_clear_issues(self, mock_os): logger = Logger() logger._issues = {'1': 1} logger._data_msg_count = {'any': 'value'} logger._offload_file = 'any file' logger._offload_filename = 'any filename' # Assert all variables have been cleared logger.clear_issues() self.assertEqual(logger._issues, {}) self.assertEqual(logger._offload_file, None) mock_os.remove.assert_called_with('any filename') # Check an OSError is passed without error mock_os.remove.side_effect = OSError() logger._offload_filename = 'any non existing filename' logger.clear_issues()