def testUnrecognizedOption(self): options = Options() options.addOption("-?","--help", False, False, "display help") options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.") options.addOption("-u","--user", True, True, "scheme (user) of the database.") parser = Parser() try: commandLine = parser.parse(options,['-q']) except UnrecognizedOptionException as uoe: self.assertEquals(uoe.getMessage(), 'unrecognized option -q')
def testMissingArgument(self): options = Options() options.addOption("-?","--help", False, False, "display help") options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.") options.addOption("-u","--user", True, True, "scheme (user) of the database.") parser = Parser() commandLine = parser.parse(options,['-s']) try: parser.checkRequiredArguments() except MissingArgumentException as mae: self.assertEquals(mae.getMessage(), 'missing argument in option -s')
def testMissingArgumentValue(self): options = Options() options.addOption("-?","--help", False, False, "display help") options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.") options.addOption("-u","--user", True, True, "scheme (user) of the database.") option = options.getOption("-s") option.setValues(['localhost']) parser = Parser() try: commandLine = parser.parse(options,['-s=orcl']) except UnrecognizedArgumentException as uae: self.assertEquals(uae.getMessage(), 'unrecognized argument orcl')
def testOptions(self): options = Options() options.addOption("-?","--help", False, False, "display help") options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.") options.addOption("-u","--user", True, False, "scheme (user) of the database.") self.assertEquals(options.size(),3, "invalid number of options") parser = Parser() commandLine = parser.parse(options,['-s=orcl','--user=apps']) self.assertEquals(commandLine.hasOption('-s'), True, "invalid parameter") self.assertEquals(commandLine.hasOption('-?'), False, "invalid parameter") self.assertEquals(commandLine.hasOption('-t'), False, "invalid parameter") self.assertEquals(commandLine.hasOption('-u'), True, "invalid parameter") self.assertEquals(commandLine.getOptionValues('-s'), ['orcl'], "invalid option value") self.assertEquals(commandLine.getOptionValue('-s'), 'orcl', "invalid option value") self.assertEquals(commandLine.getOptionValue('-s'), 'orcl', "invalid option value")
class CommandLine: def __init__(self): self.__options = Options() def addOption(self, option): self.__options.add(option) def hasOption(self, type): options = self.__options return options.hasOption(type) def getOption(self, type): options = self.getOptions() if options.hasOption(type): return options.getOption(type) def getOptionValues(self, type, defaultValue=None): options = self.getOptions() if options.hasOption(type): option = options.getOption(type) return option.getValues() return defaultValue def getOptionValue(self, type, defaultValue=None): options = self.getOptions() if options.hasOption(type): option = options.getOption(type) return option.getValue() return defaultValue def getRequiredArguments(self): options = self.getOptions() return options.getRequiredArguments() def getOptions(self): return self.__options
def testNoOraAppPass(self): NOORA_DIR = os.path.abspath('.').split('test')[0] + "src" sys.path.append(NOORA_DIR) CURRENT_DIR = os.path.abspath('.') properties = Properties() propertyLoader = PropertyLoader(properties) properties.setProperty("noora.dir", NOORA_DIR) properties.setProperty("current.dir", CURRENT_DIR) properties.setProperty( "plugin.dir", NOORA_DIR + os.sep + 'org' + os.sep + 'noora' + os.sep + 'plugin') app = NoOraApp() file = app.getConfigFile(properties) fileReader = FileReader(file) propertyLoader.load(fileReader) classLoader = ClassLoader() options = Options() pluginManager = PluginManager(classLoader, options) pluginsProperty = properties.getProperty('PLUGINS') pluginManager.load(pluginsProperty) options = pluginManager.getOptions() arguments = [ 'drop', 'create', 'update', '-h=localhost', '-d=orcl', '-e=dev', '-v=1.0.1' ] parser = Parser() commands = parser.parse(options, arguments) for command in commands.getOptions().getOptions(): plugin = pluginManager.findByType(command.getType()) options = plugin.getOptions(properties) commandLine = parser.parse(options, arguments) parser.checkRequiredOptions() parser.checkRequiredArguments() plugin.execute(commandLine, properties)
def __init__(self): self.__options = Options()
def __init__(self, type, connectable): Pluginable.__init__(self, type, connectable) self.__options = Options() self.setType(type) self.setConnector(connectable)
NOORA_DIR + os.sep + 'org' + os.sep + 'noora' + os.sep + 'plugin') properties.setProperty("project.file", "pgproject.conf") properties.setProperty( "alter.dir", properties.getPropertyValue("current.dir") + os.sep + "alter") properties.setProperty( "create.dir", properties.getPropertyValue("current.dir") + os.sep + "create") app = NoOraApp() file = app.getConfigFile(properties) fileReader = FileReader(file) propertyLoader.load(fileReader) classLoader = ClassLoader() options = Options() pluginManager = PluginManager(classLoader, options) pluginsProperty = properties.getProperty('PLUGINS') pluginManager.load(pluginsProperty) options = pluginManager.getOptions() #arguments = ['drop','create','update','-h=localhost','-d=orcl','-e=dev','-v=1.0.1'] arguments = sys.argv[1:] parser = Parser() commands = parser.parse(options, arguments) for command in commands.getOptions().getOptions(): plugin = pluginManager.findByType(command.getType())