def parse_options_from_sys_argv_test(self, MockedOptionParser): """ Test that parse_options sets up OptionParser correctly and parses sys.argv """ # GIVEN: A list of valid options and a mocked out OptionParser object mocked_parser = MagicMock() MockedOptionParser.return_value = mocked_parser expected_calls = [ call('-e', '--no-error-form', dest='no_error_form', action='store_true', help='Disable the error notification form.'), call('-l', '--log-level', dest='loglevel', default='warning', metavar='LEVEL', help='Set logging to LEVEL level. Valid values are "debug", "info", "warning".'), call('-p', '--portable', dest='portable', action='store_true', help='Specify if this should be run as a portable app, off a USB flash drive (not implemented).'), call('-d', '--dev-version', dest='dev_version', action='store_true', help='Ignore the version file and pull the version directly from Bazaar'), call('-s', '--style', dest='style', help='Set the Qt4 style (passed directly to Qt4).') ] # WHEN: Calling parse_options parse_options([]) # THEN: A tuple should be returned with the parsed options and left over options MockedOptionParser.assert_called_with(usage='Usage: %prog [options] [qt-options]') self.assertEquals(expected_calls, mocked_parser.add_option.call_args_list) mocked_parser.parse_args.assert_called_with()
def test_parse_options_file(self): """ Test the parse options process works with a file """ # GIVEN: a a set of system arguments. sys.argv[1:] = ['dummy_temp'] # WHEN: We we parse them to expand to options args = parse_options(None) # THEN: the following fields will have been extracted. self.assertFalse(args.dev_version, 'The dev_version flag should be False') self.assertEquals(args.loglevel, 'warning', 'The log level should be set to warning') self.assertFalse(args.no_error_form, 'The no_error_form should be set to False') self.assertFalse(args.portable, 'The portable flag should be set to false') self.assertEquals(args.style, None, 'There are no style flags to be processed') self.assertEquals(args.rargs, 'dummy_temp', 'The service file should not be blank')
def test_parse_options_all_no_file(self): """ Test the parse options process works with two options """ # GIVEN: a a set of system arguments. sys.argv[1:] = ['-l debug', '-d'] # WHEN: We we parse them to expand to options args = parse_options(None) # THEN: the following fields will have been extracted. self.assertTrue(args.dev_version, 'The dev_version flag should be True') self.assertEquals(args.loglevel, ' debug', 'The log level should be set to debug') self.assertFalse(args.no_error_form, 'The no_error_form should be set to False') self.assertFalse(args.portable, 'The portable flag should be set to false') self.assertEquals(args.style, None, 'There are no style flags to be processed') self.assertEquals(args.rargs, [], 'The service file should be blank')