def import_resource(self, path): if self._resources.has_key(path): LOGGER.info("Found resource file '%s' from cache" % path) else: resource = ResourceFile(path) self._resources[path] = resource return self._resources[path]
def import_resource(self, path): if path in self._resource_cache: LOGGER.info("Found resource file '%s' from cache" % path) else: resource = ResourceFile(path).populate() self._resource_cache[path] = resource return self._resource_cache[path]
def pc(request): if request.method == 'GET': username = request.user.username base_path = os.path.dirname(__file__) private_path = os.path.join("../../static/resource_house/", username) resource_path = os.path.join(base_path, private_path) resource_path = os.path.join(resource_path, 'robot/PC/trunk/resource') resource_list = os.listdir(resource_path) for rm_dir in [u'.DS_Store', u'.svn']: if rm_dir in resource_list: resource_list.remove(rm_dir) result = {} for each_resource in resource_list: case_name_list = [] path = os.path.join(resource_path, each_resource) data = ResourceFile(source=path).populate() name_list = [] for each_keyword in data.keyword_table: name_list.append(each_keyword.name) for each_variable in data.variable_table.variables: name_list.append(each_variable.name) result[each_resource[:-5]] = name_list return render_to_response("pc.html", locals(), context_instance=RequestContext(request))
def test_robot(): try: suite = TestData(parent=None, source=sys.argv[1]) except DataError: # if loading the suite failed, assume it's a resource file # (bad assumption, but _whatever_) suite = ResourceFile(source=sys.argv[1]) return suite
def mainloop(self): for path in sys.argv[1:]: try: suite = TestData(parent=None, source=sys.argv[1]) except DataError: # Hmmm. This means it's not a test suite. Maybe it's a # resource file? suite = ResourceFile(path)
def resource_data(request): if request.method == "GET": path = request.GET.get("path") resource_file = ResourceFile(path).populate() data = resource_parser(resource_file, path) response = HttpResponse(json.dumps(data), content_type="application/json") response['Access-Control-Allow-Origin'] = '*' return response
def _create_datafile(self, source): if self._is_init_file(source): dir_ = os.path.dirname(source) return TestDataDirectory(source=dir_).populate(recurse=False) try: return TestCaseFile(source=source).populate() except DataError: try: return ResourceFile(source=source).populate() except DataError: raise DataError("Invalid data source '%s'." % source)
def _parse_data(self, path): if os.path.isdir(path): return TestDataDirectory(source=path).populate() if self._is_init_file(path): path = os.path.dirname(path) return TestDataDirectory(source=path).populate(recurse=False) try: return TestCaseFile(source=path).populate() except DataError: try: return ResourceFile(source=path).populate() except DataError: raise DataError("Invalid data source '%s'." % path)
def UserLibrary(path): """Create a user library instance from given resource file. This is used at least by libdoc.py.""" from robot.parsing import ResourceFile from robot import utils from .arguments import UserKeywordArguments from .userkeyword import UserLibrary as RuntimeUserLibrary resource = ResourceFile(path).populate() ret = RuntimeUserLibrary(resource.keyword_table.keywords, path) for handler in ret.handlers.values( ): # This is done normally only at runtime. handler.arguments = UserKeywordArguments(handler._keyword_args, handler.longname) handler.doc = utils.unescape(handler._doc) ret.doc = resource.setting_table.doc.value return ret
def delete(request): if request.method == "GET": delete_type = request.method.GET("type") path = request.method.GET("path") name = request.method.GET("name") if delete_type == 'suite': os.remove(path) if delete_type == 'case': data = TestData(source=path) for each_case in data.testcase_table: if each_case.name == name: data.testcase_table.tests.remove(each_case) data.save(format='html') if delete_type == "resource": os.remove(path) if delete_type == "resource_case": data = ResourceFile(source=path).populate() pass
def create_robot_tests(fout): """ Create tests for all robot based keywords """ processed = {} # dict to avoid circular imports def get_all_keywords(resource): """ Helper function to recursively get keywords from resource files """ keywords = [] resource.populate() for res in [ i for i in resource.imports.data if isinstance(i, robot.parsing.settings.Resource) ]: keyword_file = os.path.abspath('{}/{}'.format( res.directory, res.name)) if keyword_file not in processed: res_obj = ResourceFile(keyword_file) processed[keyword_file] = res_obj keywords += get_all_keywords(res_obj) for keyword in resource.keywords: print(keyword.name) keywords.append( tuple((keyword.source, keyword.name, keyword.args.value if keyword.args.value else []))) return keywords fusion_api_resource = ResourceFile(MAIN_RESOURCE_FILE) for keyword in get_all_keywords(fusion_api_resource): fout.write('Test {}\n'.format(keyword[1])) fout.write(' [Documentation] {}\n'.format(keyword[0])) fout.write(' {} '.format(keyword[1])) for arg in keyword[2]: if '=' in arg: fout.write(' {} '.format(arg.split('=')[-1])) else: if arg.startswith('&'): fout.write(' testk=testv ') else: fout.write(' test ') fout.write('\n\n')
def UserLibrary(path): """Create a user library instance from given resource file. This is used by Libdoc. """ from robot.parsing import ResourceFile from robot import utils from .arguments.argumentspec import ArgumentSpec from .userkeyword import UserLibrary as RuntimeUserLibrary resource = ResourceFile(path).populate() ret = RuntimeUserLibrary(resource.keyword_table.keywords, path) for handler in ret.handlers.values(): if handler.type != 'error': handler.doc = utils.unescape(handler._doc) else: handler.arguments = ArgumentSpec(handler.longname) handler.doc = '*Creating keyword failed: %s*' % handler.error ret.doc = resource.setting_table.doc.value return ret
def xTestData(parent=None, source=None, include_suites=[], warn_on_skipped=False): '''Open either a test case directory or file, or a resource file This was copied from robot.parsing.model.TestData, then modified to support opening resource files ''' if os.path.isdir(source): return TestDataDirectory(parent, source).populate(include_suites, warn_on_skipped) else: try: return TestCaseFile(parent, source).populate() except DataError: # the assumption is, if we get a DataError then this is a # resource file. That's probably not a very good # assumption to make, but it's the only hint robot gives # me that it might be a resource file return ResourceFile(source)
def get_all_keywords(resource): """ Helper function to recursively get keywords from resource files """ keywords = [] resource.populate() for res in [ i for i in resource.imports.data if isinstance(i, robot.parsing.settings.Resource) ]: keyword_file = os.path.abspath('{}/{}'.format( res.directory, res.name)) if keyword_file not in processed: res_obj = ResourceFile(keyword_file) processed[keyword_file] = res_obj keywords += get_all_keywords(res_obj) for keyword in resource.keywords: print(keyword.name) keywords.append( tuple((keyword.source, keyword.name, keyword.args.value if keyword.args.value else []))) return keywords
def resource_save(request): if request.method == "GET": resorce_data = request.method.GET("resource_data") path = resorce_data.get("path", "") #setings settings = resorce_data.get("settings", {}) doc = settings.get("doc", "") imports = settings.get("imports", []) #variables variables = resorce_data.get("variables", []) #keywords keywords = resorce_data.get("keywords", []) data = ResourceFile( source=u'/Users/libin/Desktop/robot/PC/trunk/testcase/我的资产.html' ).populate() #设置doc data.setting_table.doc.populate(doc) #设置import data.setting_table.imports.data = [] for each_import in imports: if each_import["type"] == "Library": data.setting_table.add_library(each_import["name"]) if each_import["type"] == "Resource": data.setting_table.add_resource(each_import["name"]) if each_import["type"] == "variable": data.setting_table.add_resource(each_import["name"]) #设置variables data.variable_table.variables = [] for each_variable in variables: name = each_variable["variable_name"] value = each_variable["variable_value"] comment = each_variable["variable_comment"] data.variable_table.add(name, value, comment) #设置keywords for keyword_object in data.keyword_table: for each_keyword in keywords: teardown = each_keyword["keyword_teardown"] steps = each_keyword["keyword_steps"] if keyword_object.name == each_keyword["keyword_name"]: #设置doc keyword_object.doc.populate(each_keyword["keyword_doc"]) #设置arguments keyword_object.args.populate(each_keyword["keyword_args"]) #设置return value keyword_object.return_.populate( each_keyword["keyword_return"]) #设置timeout timeout_value = each_keyword["keyword_timeout"].split(" ") keyword_object.timeoutpopulate(timeout_value) #设置teardown keyword_object.teardown.name = None keyword_object.teardown.args = [] keyword_object.teardown.assign = () teardown_value = [] teardown_value.append(teardown["name"]) teardown_value.append(teardown["args"]) keyword_object.teardown.populate(teardown_value) #设置steps if steps: #先清空 keyword_object.steps = [] row_list = [] for each_step in steps: type = each_step.get('type', False) if not type: assign = each_step.get("assign", []) keyword = each_step.get("keyword", "") comment = each_step.get("comment", []) args = each_step.get("args", []) if assign: for each_assign in assign: row_list.append(each_assign) if keyword: row_list.append(keyword) if args: for each_args in args: row_list.append(each_args) if comment: for each_comment in comment: row_list.append(each_comment) keyword_object.add_step(row_list) else: as_list = each_step.get('as_list', "") forloop = each_step.get('setps', []) forloop_obj = keyword_object.add_for_loop( as_list) for each_loop in forloop: assign = each_loop.get("assign", []) keyword = each_loop.get("keyword", "") comment = each_loop.get("comment", []) args = each_loop.get("args", []) if assign: for each_assign in assign: row_list.append(each_assign) if keyword: row_list.append(keyword) if args: for each_args in args: row_list.append(each_args) if comment: for each_comment in comment: row_list.append(each_comment) forloop_obj.add_step(row_list) data.save(format="html")