def testSpace(self): defaults = dict(year=(1980, 'doc'), month=('june', 'doc'), day=(24, 'doc')) raw = 'year=the year I was born' known, _ = common.parse_settings(defaults, raw) self.assertEqual(known['year'], 'the year I was born')
def createToken(self, info, parent): cmd = (info['command'], info['subcommand']) settings = info['settings'] # Handle filename and None subcommand match = self.FILENAME_RE.search( info['subcommand']) if info['subcommand'] else None if match: cmd = (info['command'], match.group('ext')) elif info['subcommand'] and info['subcommand'].startswith('http'): cmd = (info['command'], None) elif info['subcommand'] and '=' in info['subcommand']: #settings += ' ' + info['subcommand'] settings = info['subcommand'] + ' ' + settings cmd = (info['command'], None) # Locate the command object to call try: obj = self.translator.__EXTENSION_COMMANDS__[cmd] except KeyError: try: obj = self.translator.__EXTENSION_COMMANDS__[(cmd[0], '*')] except KeyError: msg = "The following command combination is unknown: '{} {}'." raise common.exceptions.TokenizeException(msg.format(*cmd)) # Build the token if obj.PARSE_SETTINGS: settings, _ = common.parse_settings(obj.defaultSettings(), settings) obj.setSettings(settings) token = obj.createToken(info, parent) return token
def createToken(self, info, parent): cmd = (info['command'], info['subcommand']) settings = info['settings'] # Handle filename and None subcommand match = self.FILENAME_RE.search(info['subcommand']) if info['subcommand'] else None if match: cmd = (info['command'], match.group('ext')) elif info['subcommand'] and info['subcommand'].startswith('http'): cmd = (info['command'], None) elif info['subcommand'] and '=' in info['subcommand']: #settings += ' ' + info['subcommand'] settings = info['subcommand'] + ' ' + settings cmd = (info['command'], None) # Locate the command object to call try: obj = self.translator.__EXTENSION_COMMANDS__[cmd] except KeyError: try: obj = self.translator.__EXTENSION_COMMANDS__[(cmd[0], '*')] except KeyError: msg = "The following command combination is unknown: '{} {}'." raise common.exceptions.TokenizeException(msg.format(*cmd)) # Build the token if obj.PARSE_SETTINGS: settings, _ = common.parse_settings(obj.defaultSettings(), settings) obj.setSettings(settings) token = obj.createToken(info, parent) return token
def __call__(self, parent, info, page): """ MooseDocs internal method, this should not be called, please use the createToken method. The lexer system within MooseDocs expects a function this method allows this class to act as a function. Inputs: info[LexerInformation]: Object containing the lexer information object. parent[tokens.Token]: The parent node in the AST for the token being created. """ # Disable inactive extensions, the "is not None" allows this method to work when # components are added outside of an extension, which is needed for testing if (self.extension is not None) and (not self.extension.active): tokens.DisabledToken(parent, string=info[0]) return parent # Define the settings defaults = self.defaultSettings() if self.PARSE_SETTINGS and ('settings' in info): self.__settings, _ = parse_settings(defaults, info['settings']) else: self.__settings = {k: v[0] for k, v in defaults.iteritems()} # Call user method and reset settings token = self.createToken(parent, info, page) self.__settings = None return token
def __call__(self, parent, info, page): """ MooseDocs internal method, this should not be called, please use the createToken method. The lexer system within MooseDocs expects a function this method allows this class to act as a function. Inputs: info[LexerInformation]: Object containing the lexer information object. parent[tokens.Token]: The parent node in the AST for the token being created. """ # Disable inactive extensions, the "is not None" allows this method to work when # components are added outside of an extension, which is needed for testing if (self.extension is not None) and (not self.extension.active): tokens.DisabledToken(parent, string=info[0]) return parent # Define the settings defaults = self.defaultSettings() if self.PARSE_SETTINGS and ('settings' in info): self.__settings, _ = parse_settings(defaults, info['settings']) else: self.__settings = {k:v[0] for k, v in defaults.iteritems()} # Call user method and reset settings token = self.createToken(parent, info, page) self.__settings = None return token
def testChangeException(self): defaults = dict(year=(1980, 'doc')) raw = 'year=2003 month=june' with self.assertRaises(exceptions.MooseDocsException) as e: known, unknown = common.parse_settings(defaults, raw) self.assertIn("The following key, value settings are unknown:", e.exception.message) self.assertIn("month", e.exception.message)
def testUnknown(self): defaults = dict(year=(1980, 'doc')) raw = 'year=2003 month=june' known, unknown = common.parse_settings(defaults, raw, error_on_unknown=False) self.assertEqual(known['year'], 2003) self.assertNotIn('month', known) self.assertIn('month', unknown) self.assertEqual(unknown['month'], 'june')
def testBasic(self): defaults = dict(year=(1980, 'doc'), month=('june', 'doc'), day=(24, 'doc')) raw = 'year=2003' known, unknown = common.parse_settings(defaults, raw) self.assertEqual(known['year'], 2003) self.assertEqual(known['month'], 'june') self.assertEqual(known['day'], 24) self.assertEqual(unknown, dict())
def testChangeException(self): defaults = dict(year=(1980, 'doc')) raw = 'year=2003 month=june' with self.assertRaises(KeyError) as e: known, unknown = common.parse_settings(defaults, raw, exc=KeyError) self.assertIn("The following key, value settings are unknown:", e.exception.message) self.assertIn("month", e.exception.message)
def testUnknownException(self): defaults = dict(year=(1980, 'doc')) raw = 'year=2003 month=june' with self.assertRaises(exceptions.MooseDocsException) as e: known, unknown = common.parse_settings(defaults, raw) self.assertIn("The following key, value settings are unknown:", e.exception.message) self.assertIn("month", e.exception.message)
def testUnknown(self): defaults = dict(year=(1980, 'doc')) raw = 'year=2003 month=june' known, unknown = common.parse_settings(defaults, raw, error_on_unknown=False) self.assertEqual(known['year'], 2003) self.assertNotIn('month', known) self.assertIn('month', unknown) self.assertEqual(unknown['month'], 'june')
def testBasic(self): defaults = dict(year=(1980, 'doc'), month=('june', 'doc'), day=(24, 'doc')) raw = 'year=2003' known, unknown = common.parse_settings(defaults, raw) self.assertEqual(known['year'], 2003) self.assertEqual(known['month'], 'june') self.assertEqual(known['day'], 24) self.assertEqual(unknown, dict())
def createToken(self, parent, info, page): cmd = (info['command'], info['subcommand']) settings = info['settings'] # Handle filename and None subcommand match = self.FILENAME_RE.search( info['subcommand']) if info['subcommand'] else None if match: cmd = (info['command'], match.group('ext')) elif info['subcommand'] and info['subcommand'].startswith('http'): cmd = (info['command'], None) elif info['subcommand'] and '=' in info['subcommand']: settings = info['subcommand'] + ' ' + settings cmd = (info['command'], None) # Locate the command object to call try: obj = CommandExtension.EXTENSION_COMMANDS[cmd] except KeyError: try: obj = CommandExtension.EXTENSION_COMMANDS[(cmd[0], '*')] except KeyError: msg = "The following command combination is unknown: '{} {}'." raise common.exceptions.MooseDocsException(msg.format(*cmd)) if not obj.extension.active: if isinstance(self, InlineCommand): tokens.DisabledToken(parent, tag='span', string=info[0]) tokens.DisabledToken(parent, tag='p', string=info[0]) return parent # Build the token if obj.PARSE_SETTINGS: settings, _ = common.parse_settings(obj.defaultSettings(), settings) obj.setSettings(settings) token = obj.createToken(parent, info, page) return token
def __call__(self, info, parent): """ MooseDocs internal method, this should not be called, please use the createToken method. The lexer system within MooseDocs expects a function this method allows this class to act as a function. Inputs: info[LexerInformation]: Object containing the lexer information object. parent[tokens.Token]: The parent node in the AST for the token being created. """ # Define the settings defaults = self.defaultSettings() if self.PARSE_SETTINGS and ('settings' in info): self.__settings, _ = parse_settings(defaults, info['settings']) else: self.__settings = {k: v[0] for k, v in defaults.iteritems()} # Call user method and reset settings token = self.createToken(info, parent) self.__settings = None return token
def __call__(self, info, parent): """ MooseDocs internal method, this should not be called, please use the createToken method. The lexer system within MooseDocs expects a function this method allows this class to act as a function. Inputs: info[LexerInformation]: Object containing the lexer information object. parent[tokens.Token]: The parent node in the AST for the token being created. """ # Define the settings defaults = self.defaultSettings() if self.PARSE_SETTINGS and ('settings' in info): self.__settings, _ = parse_settings(defaults, info['settings']) else: self.__settings = {k:v[0] for k, v in defaults.iteritems()} # Call user method and reset settings token = self.createToken(info, parent) self.__settings = None return token
def createToken(self, parent, info, page): cmd = (info['command'], info['subcommand']) settings = info['settings'] # Handle filename and None subcommand match = self.FILENAME_RE.search(info['subcommand']) if info['subcommand'] else None if match: cmd = (info['command'], match.group('ext')) elif info['subcommand'] and info['subcommand'].startswith('http'): cmd = (info['command'], None) elif info['subcommand'] and '=' in info['subcommand']: settings = info['subcommand'] + ' ' + settings cmd = (info['command'], None) # Locate the command object to call try: obj = CommandExtension.EXTENSION_COMMANDS[cmd] except KeyError: try: obj = CommandExtension.EXTENSION_COMMANDS[(cmd[0], '*')] except KeyError: msg = "The following command combination is unknown: '{} {}'." raise common.exceptions.MooseDocsException(msg.format(*cmd)) if not obj.extension.active: if isinstance(self, InlineCommand): tokens.DisabledToken(parent, tag='span', string=info[0]) tokens.DisabledToken(parent, tag='p', string=info[0]) return parent # Build the token if obj.PARSE_SETTINGS: settings, _ = common.parse_settings(obj.defaultSettings(), settings) obj.setSettings(settings) token = obj.createToken(parent, info, page) return token
def testFloat(self): defaults = dict(year=(1980, 'doc')) raw = 'year=2003' known, _ = common.parse_settings(defaults, raw) self.assertIsInstance(known['year'], float)
def testSpace(self): defaults = dict(year=(1980, 'doc'), month=('june', 'doc'), day=(24, 'doc')) raw = 'year=the year I was born' known, _ = common.parse_settings(defaults, raw) self.assertEqual(known['year'], 'the year I was born')
def testFloat(self): defaults = dict(year=(1980, 'doc')) raw = 'year=2003' known, _ = common.parse_settings(defaults, raw) self.assertIsInstance(known['year'], float)