def test_check_triangle_exception_no_stop_on_first_failure(self): self.mock_config.getboolean.side_effect = [False ] # STOP_ON_FIRST_FAILURE self.mock_check_triangle.side_effect = Exception('FAIL') actual = run_all() assert actual[0].failures == ['FAIL', 'FAIL']
def test_run_all(self): actual = run_all() assert len(actual) == 1 assert actual[0].name == 'test_solution' assert not actual[0].failures self.mock_check_bandit.assert_called_once_with( 'test_local_dir/test_solution') self.mock_create_virtualenv.assert_called_once_with( 'test_local_dir/test_solution') self.mock_install_requirements.assert_called_once_with( 'test_venv', 'test_local_dir/test_solution') self.mock_check_triangle.assert_has_calls([ mock.call('test_local_dir/test_solution', executable='test_executable', filename='test_file1', expected=[5], python_executable='test_venv/bin/python3'), mock.call('test_local_dir/test_solution', executable='test_executable', filename='test_file2', expected=[1, 2, 3], python_executable='test_venv/bin/python3'), ]) assert not self.mock_write_failures_to_file.called
def test_exceptions_continue(self): self.mock_check_bandit.side_effect = Exception('FAIL') actual = run_all() assert len(actual) == 1 assert actual[0].name == 'test_solution' assert actual[0].failure_reason == 'FAIL' self.mock_check_bandit.assert_called_once_with( 'test_local_dir/test_solution') self.mock_term.red.assert_any_call( 'Got exception running test_solution') assert not self.mock_check_triangle.called
def main(): config = loadConfig('settings.conf') HOST = config.get('IMAP', 'HOST') USERNAME = config.get('IMAP', 'USERNAME') FOLDER = config.get('IMAP', 'FOLDER') FILENAME = config.get('RESULTS', 'FILENAME') PASSWORD = getpass.getpass() LOCAL_DIRECTORY = config.get('ATTACHMENTS', 'LOCAL_DIRECTORY') imap_server = ImapServer(HOST, USERNAME, PASSWORD, folder=FOLDER, ) imap_server.download_attachements(directory=LOCAL_DIRECTORY) imap_server.logout() print('Finished downloading attachments') print() print('Starting decompressing archives') decompress_archives(LOCAL_DIRECTORY) print('Finished decompressing archives') print() run_code = input('Run code now? (y/N) ') if run_code.lower() in ('y', 'yes'): results = run_all() successes = [x for x in results if not x.failed] successes.sort(key=lambda x: x.time) print('Correct Solutions:') for result in successes: print('{name}\n\t{time}'.format(name=term.blue(result.name), time=term.magenta(str(result.time)))) print() if FILENAME: with open(FILENAME, 'w') as f: for result in successes: f.write('{name} {time}\n'.format(name=result.name, time=str(result.time))) print() print('All Done')
def main(): config = loadConfig('settings.conf') HOST = config.get('IMAP', 'HOST') USERNAME = config.get('IMAP', 'USERNAME') FOLDER = config.get('IMAP', 'FOLDER') FILENAME = config.get('RESULTS', 'FILENAME') PASSWORD = getpass.getpass() LOCAL_DIRECTORY = config.get('ATTACHMENTS', 'LOCAL_DIRECTORY') imap_client = ImapClient( HOST, USERNAME, PASSWORD, folder=FOLDER, ) imap_client.download_attachements(directory=LOCAL_DIRECTORY) imap_client.logout() print('Finished downloading attachments') print() print('Starting decompressing archives') decompress_archives(LOCAL_DIRECTORY) print('Finished decompressing archives') print() run_code = input('Run code now? (y/N) ') if run_code.lower() in ('y', 'yes'): results = run_all() output_results_to_stdout(results) if FILENAME: output_results_to_file(FILENAME, results) for result in results: if result.has_failures: result.write_failures_to_file() print() print('All Done')
def test_check_triangle_exception_stop_on_first_failure(self): self.mock_check_triangle.side_effect = Exception('FAIL') actual = run_all() assert actual[0].failures == ['FAIL']
def test_StopExecution_reraises(self): self.mock_check_triangle.side_effect = StopExecution('FAIL') with pytest.raises(StopExecution): run_all()