Exemplo n.º 1
0
 def testUnixName(self):
   expectations = {
     'foo': 'foo',
     'fooBar': 'foo_bar',
     'fooBarBaz': 'foo_bar_baz',
     'fooBARBaz': 'foo_bar_baz',
     'fooBAR': 'foo_bar',
     'FOO': 'foo',
     'FOOBar': 'foo_bar',
     'foo.bar': 'foo_bar',
     'foo.BAR': 'foo_bar',
     'foo.barBAZ': 'foo_bar_baz'
     }
   for name in expectations:
     self.assertEquals(expectations[name], model.UnixName(name));
Exemplo n.º 2
0
 def _LoadModel(self, basedir, name):
     """Loads and returns the model for the |name| API from either its JSON or
 IDL file, e.g.
     name=contextMenus will be loaded from |basedir|/context_menus.json,
     name=alarms will be loaded from |basedir|/alarms.idl.
 """
     loaders = {'json': json_schema.Load, 'idl': idl_schema.Load}
     # APIs are referred to like "webRequest" but that's in a file
     # "web_request.json" so we need to unixify the name.
     unix_name = model.UnixName(name)
     for loader_ext, loader_fn in loaders.items():
         file_path = '%s/%s.%s' % (basedir, unix_name, loader_ext)
         if os.path.exists(file_path):
             # For historical reasons these files contain a singleton list with the
             # model, so just return that single object.
             return (loader_fn(file_path)[0], file_path)
     raise ValueError('File for model "%s" not found' % name)