def test_reformat_schema(self): # Not a real schema, just doing a smoke test of the function # properties = 'target' class FakeResource(object): schema = { "additionalProperties": False, "properties": { "type": "foo", "default": { "type": "object" }, "key": { "type": "string" }, "op": { "enum": ["regex", "ni", "gt", "not-in"] }, "value": { "oneOf": [ { "type": "array" }, { "type": "string" }, { "type": "boolean" }, { "type": "number" }, ] }, }, "required": ["key"], } ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, dict) # Test error conditions # Instead of testing for specific keywords, just make sure that strings # are returned instead of a dictionary. FakeResource.schema = {} ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, six.text_type) delattr(FakeResource, "schema") ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, six.text_type)
def test_reformat_schema(self): # Not a real schema, just doing a smoke test of the function properties = 'target' class FakeResource(object): schema = { 'additionalProperties': False, 'properties': { 'type': 'foo', 'default': { 'type': 'object' }, 'key': { 'type': 'string' }, 'op': { 'enum': ['regex', 'ni', 'gt', 'not-in'] }, 'value': { 'oneOf': [{ 'type': 'array' }, { 'type': 'string' }, { 'type': 'boolean' }, { 'type': 'number' }] }, }, 'required': ['key'], } ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, dict) # Test error conditions # Instead of testing for specific keywords, just make sure that strings # are returned instead of a dictionary. FakeResource.schema = {} ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, six.text_type) delattr(FakeResource, 'schema') ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, six.text_type)
def test_reformat_schema(self): # Not a real schema, just doing a smoke test of the function # properties = 'target' class FakeResource(object): schema = { "additionalProperties": False, "properties": { "type": "foo", "default": {"type": "object"}, "key": {"type": "string"}, "op": {"enum": ["regex", "ni", "gt", "not-in"]}, "value": { "oneOf": [ {"type": "array"}, {"type": "string"}, {"type": "boolean"}, {"type": "number"}, ] }, }, "required": ["key"], } ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, dict) # Test error conditions # Instead of testing for specific keywords, just make sure that strings # are returned instead of a dictionary. FakeResource.schema = {} ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, six.text_type) delattr(FakeResource, "schema") ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, six.text_type)
def test_reformat_schema(self): # Not a real schema, just doing a smoke test of the function properties = 'target' class FakeResource(object): schema = { 'additionalProperties': False, 'properties': { 'type': 'foo', 'default': {'type': 'object'}, 'key': {'type': 'string'}, 'op': {'enum': ['regex', 'ni', 'gt', 'not-in']}, 'value': {'oneOf': [{'type': 'array'}, {'type': 'string'}, {'type': 'boolean'}, {'type': 'number'}]}, }, 'required': ['key'], } ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, dict) # Test error conditions # Instead of testing for specific keywords, just make sure that strings # are returned instead of a dictionary. FakeResource.schema = {} ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, unicode) delattr(FakeResource, 'schema') ret = utils.reformat_schema(FakeResource) self.assertIsInstance(ret, unicode)
def run(self): sig = " ".join(self.arguments) m = py_sig_re.match(sig) if m is None: raise SphinxError("Unable to parse signature for c7n-schema: %r" % sig) name_prefix, model_name, arglist, ret_ann = m.groups() module_name = self.options['module'] try: module = importlib.import_module(module_name) except ImportError: raise SphinxError( "Unable to generate reference docs for %s, couldn't import module '%s'" % (model_name, module_name)) model = getattr(module, model_name, None) if model is None: raise SphinxError( "Unable to generate reference docs for %s, no model '%s' in %s" % (model_name, model_name, module_name)) if not hasattr(model, 'schema'): raise SphinxError( "Unable to generate reference docs for %s, model '%s' does not\ have a 'schema' attribute" % (model_name, model_name)) schema = reformat_schema(model) schema_json = json.dumps( schema, sort_keys=True, indent=2, separators=(',', ': ') ) rst_text = TEMPLATE_C7N_SCHEMA.render( name=model_name, module_name=module_name, schema_json=schema_json, ) return self._parse(rst_text, "<c7n-schema>")