def test_should_print_version_and_exit_with_return_code_zero_when_version_option_given( self, mock_stdout, mock_exit): parse_arguments(["--version"], version="yadt-config-rpm-maker 2.0") mock_stdout.write.assert_called_with("yadt-config-rpm-maker 2.0\n") mock_exit.assert_called_with(0)
def test_should_use_usage_information(self, mock_option_parser_class): mock_option_parser = Mock() mock_values = Mock() mock_values.version = False mock_values.debug = False mock_arguments = ["foo", "bar"] mock_option_parser.parse_args.return_value = (mock_values, mock_arguments) mock_option_parser_class.return_value = mock_option_parser parse_arguments([], version="") mock_option_parser_class.assert_called_with(usage=USAGE_INFORMATION)
def test_should_print_help_screen_and_exit_when_less_than_two_positional_arguments_are_given(self, mock_option_parser_class, mock_exit): mock_option_parser = Mock() mock_values = Mock() mock_values.version = False mock_values.debug = False mock_arguments = [""] mock_option_parser.parse_args.return_value = (mock_values, mock_arguments) mock_option_parser_class.return_value = mock_option_parser parse_arguments([], version="") mock_option_parser.print_help.assert_called_with() mock_exit.assert_called_with(1)
def test_should_use_usage_information(self, mock_option_parser_class): mock_option_parser = Mock() mock_values = Mock() mock_values.version = False mock_values.debug = False mock_arguments = ["foo", "bar"] mock_option_parser.parse_args.return_value = (mock_values, mock_arguments) mock_option_parser_class.return_value = mock_option_parser parse_arguments([], version="") mock_option_parser_class.assert_called_with(usage=USAGE_INFORMATION)
def test_should_return_verbose_option_as_true_when_debug_option_given( self): actual_arguments = parse_arguments(["foo", "123", "--verbose"], version="") self.assertTrue(actual_arguments["--verbose"])
def main(): """ This function will be called by the command line interface. """ LOGGER.setLevel(DEBUG) try: arguments = parse_arguments(argv[1:], version='yadt-config-rpm-maker %s' % __version__) initialize_logging_to_console(arguments) repository_url, revision = extract_repository_url_and_revision_from_arguments(arguments) initialize_logging_to_syslog(arguments, revision) initialize_configuration(arguments) start_measuring_time() log_additional_information() building_configuration_rpms_and_clean_host_directories(repository_url, revision) except ConfigurationException as e: log_exception_message(e) return exit_program('Configuration error!', return_code=RETURN_CODE_CONFIGURATION_ERROR) except BaseConfigRpmMakerException as e: log_exception_message(e) return exit_program('An exception occurred!', return_code=RETURN_CODE_EXCEPTION_OCCURRED) except Exception: stack_trace = traceback.format_exc(5) for line in stack_trace.split('\n'): LOGGER.error(line) return exit_program('An unknown exception occurred!', return_code=RETURN_CODE_UNKNOWN_EXCEPTION_OCCURRED) except KeyboardInterrupt: return exit_program('Execution interrupted by user!', return_code=RETURN_CODE_EXECUTION_INTERRUPTED_BY_USER) exit_program(MESSAGE_SUCCESS, return_code=RETURN_CODE_SUCCESS)
def test_should_return_no_syslog_option_as_true_when_no_syslog_option_given( self): actual_arguments = parse_arguments(["foo", "123", "--no-syslog"], version="") self.assertTrue(actual_arguments["--no-syslog"])
def test_should_print_help_screen_and_exit_when_less_than_two_positional_arguments_are_given( self, mock_option_parser_class, mock_exit): mock_option_parser = Mock() mock_values = Mock() mock_values.version = False mock_values.debug = False mock_arguments = [""] mock_option_parser.parse_args.return_value = (mock_values, mock_arguments) mock_option_parser_class.return_value = mock_option_parser parse_arguments([], version="") mock_option_parser.print_help.assert_called_with() mock_exit.assert_called_with(1)
def test_should_return_option_config_viewer_only_as_true_when_option_is_given( self): actual_arguments = parse_arguments( ["foo", "123", "--config-viewer-only"], version="") self.assertTrue(actual_arguments["--config-viewer-only"])
def main(): """ This function will be called by the command line interface. """ LOGGER.setLevel(DEBUG) try: arguments = parse_arguments(argv[1:], version='yadt-config-rpm-maker %s' % __version__) initialize_logging_to_console(arguments) repository_url, revision = extract_repository_url_and_revision_from_arguments( arguments) initialize_logging_to_syslog(arguments, revision) initialize_configuration(arguments) start_measuring_time() log_additional_information() building_configuration_rpms_and_clean_host_directories( repository_url, revision) except ConfigurationException as e: log_exception_message(e) return exit_program('Configuration error!', return_code=RETURN_CODE_CONFIGURATION_ERROR) except BaseConfigRpmMakerException as e: log_exception_message(e) return exit_program('An exception occurred!', return_code=RETURN_CODE_EXCEPTION_OCCURRED) except Exception: stack_trace = traceback.format_exc(5) for line in stack_trace.split('\n'): LOGGER.error(line) return exit_program('An unknown exception occurred!', return_code=RETURN_CODE_UNKNOWN_EXCEPTION_OCCURRED) except KeyboardInterrupt: return exit_program( 'Execution interrupted by user!', return_code=RETURN_CODE_EXECUTION_INTERRUPTED_BY_USER) exit_program(MESSAGE_SUCCESS, return_code=RETURN_CODE_SUCCESS)
def test_should_return_no_clean_up_option_as_true_when_no_clean_up_option_given(self): actual_arguments = parse_arguments(["foo", "123", "--no-clean-up"], version="") self.assertTrue(actual_arguments["--no-clean-up"])
def test_should_return_verbose_option_as_false_when_no_option_given(self): actual_arguments = parse_arguments(["foo", "123"], version="") self.assertFalse(actual_arguments["--verbose"])
def test_should_return_option_config_viewer_only_as_true_when_option_is_given(self): actual_arguments = parse_arguments(["foo", "123", "--config-viewer-only"], version="") self.assertTrue(actual_arguments["--config-viewer-only"])
def test_should_return_first_argument_as_repository(self): actual_arguments = parse_arguments(["foo", "123"], version="") self.assertEqual(actual_arguments["<repository-url>"], "foo")
def test_should_return_second_argument_as_revision(self): actual_arguments = parse_arguments(["foo", "123"], version="") self.assertEqual(actual_arguments["<revision>"], "123")
def test_should_return_first_argument_as_repository(self): actual_arguments = parse_arguments(["foo", "123"], version="") self.assertEqual(actual_arguments["<repository-url>"], "foo")
def test_should_return_verbose_option_as_true_when_debug_option_given(self): actual_arguments = parse_arguments(["foo", "123", "--verbose"], version="") self.assertTrue(actual_arguments["--verbose"])
def test_should_return_verbose_option_as_false_when_no_option_given(self): actual_arguments = parse_arguments(["foo", "123"], version="") self.assertFalse(actual_arguments["--verbose"])
def test_should_print_version_and_exit_with_return_code_zero_when_version_option_given(self, mock_stdout, mock_exit): parse_arguments(["--version"], version="yadt-config-rpm-maker 2.0") mock_stdout.write.assert_called_with("yadt-config-rpm-maker 2.0\n") mock_exit.assert_called_with(0)
def test_should_return_second_argument_as_revision(self): actual_arguments = parse_arguments(["foo", "123"], version="") self.assertEqual(actual_arguments["<revision>"], "123")