def validate_params(rules): if not request.json: result = validate(rules, request.form) else: result = validate(rules, request.json) if result[0] is not True: raise ParamsInvalidate('Params is not validated', errors=result[1]) return result[0]
def test_empty_dict_alias(self): dimdata = {} distbuffer = {'__version__': VERSION, 'buffer' : b'', 'dim_data' : (dimdata,)} is_valid, msg = validator.validate(distbuffer) self.assertTrue(is_valid, msg)
def _validate(path, name, args): """Perform steps necessary to complete a basic validation.""" print "Validating..." s = sys.stdout sys.stdout = StringIO() toprint = [] result = True try: json = validate(path=path) output = sys.stdout.getvalue() toprint.append("JSON Length: %d; stdout Length: %d" % (len(json), len(output))) toprint.append("Done - %d/%d" % (acount, vcount) if json else json) except Exception as ex: # Make crazy names safer. if name.startswith("-"): name = "_%s" % name tback = open("%s%s.log" % (args.brokendirectory, name), mode="w") traceback.print_exc(file=tback) tback.close() traceback_path = "%s%s" % (args.brokendirectory, name) if path != traceback_path: shutil.move(path, traceback_path) toprint.append("TRACEBACK FAIL: %s" % ("%s.log" % traceback_path)) result = False sys.stdout = s print "\n".join(toprint) return result
def query(request): # Obtain attributes from request verb = str(request.POST['verb']).strip().lower() semanticRole = str(request.POST['role']) noun = str(request.POST['noun']).strip().lower() group = str(request.POST['group1']) model = str(request.POST['select_model']) topN = int(request.POST['top_results']) quadrant = int(request.POST['quadrant']) result = {} # LOG logger.debug('v: %s' , verb) logger.debug('r: %s' , semanticRole) logger.debug('n: %s' , noun) logger.debug('group: %s' , group) logger.debug('top_results: %d' , topN) # Perform validation on request attributes isValid, errorMessage = validate(verb, noun, group, topN) if isValid: result = processQuery(verb, noun, semanticRole, group, model, topN, quadrant) else: result = errorMessage return JsonResponse(result)
def make_move(board, score_list, word, position, letter_rack, letter_bag, orientation): """ Takes in a board, a word, a position to start the word at, the orientation of the word to play, and a rack of letters the player has to choose from and plays a word at that position. If the move is valid, it returns the new board and mod. Parameters: board - The board for the game currently being played, formatted as a list of lists. word - The word the current player is attempting to play, in a string in capital letters. position - A tuple containing the coordinates for the starting square for the word the player is attempting to play. letter_rack - A list of letters available to the player to play their current word. letter_bag - A list of letters available to all players as they play the letters currently in their rack. orientation - One of two possible orientations for the word being played, either 'horizontal' or 'vertical'. """ temp_board = copy.deepcopy(board) for letter in word: if not (letter in letter_rack and word.count(letter) <= letter_rack.count(letter)): print "You do not have the proper letters in your rack to play this word." return board temp_board = play_word(temp_board, word, position, orientation) if validator.validate(temp_board): for letter in word: letter_rack.remove(letter) for i in range(len(word)): letter_rack.append(draw_letter(letter_bag)) score_word(word, score_list) board = temp_board else: retry_word = raw_input("You have made an illegal move. Try again ") make_move(board, score_list, retry_word, position, letter_rack, letter_bag, orientation) return board
def test_rule_func_07(): class AgesChecker: def __call__(self, arg): return 18 <= arg class NameChecker: def __call__(self, arg): return len(arg) > 0 class MailChecker: def __call__(self, arg): return "@" in arg rule = { "name": NameChecker(), "ages": AgesChecker(), "mail": MailChecker() } req = {"name": "Jon Doe", "ages": 33, "mail": "*****@*****.**"} assert validate(req, rule) req = {"name": "", "ages": 10, "mail": "Jon.Doe"} result, validated_data, errors = validate(req, rule, True) # Result Should be False assert not result # Validated data should be length of 0 assert len(validated_data) == 0 # Check for all rules' errors assert len(errors) == 3 # Check if all of them are containing string assert len(errors["ages"]) == 1 assert len(errors["mail"]) == 1 assert len(errors["name"]) == 1 # check for correct namings in errors assert "AgesChecker" in errors["ages"] assert "MailChecker" in errors["mail"] assert "NameChecker" in errors["name"] # check for correct namings in errors assert errors["ages"]["AgesChecker"] == CUSTOM_ERROR_MSG assert errors["mail"]["MailChecker"] == CUSTOM_ERROR_MSG assert errors["name"]["NameChecker"] == CUSTOM_ERROR_MSG
def test_uuid_v3_03(): assert validate({"val": "f6c83289-fa9d-3ff0-94d4-1bd6ba6323e2"}, {"val": "UUIDv3"}) assert validate({"val": "f6c83289-fa9d-3ff0-94d4-1bd6ba6323e2"}, {"val": "UUIDv3"}) assert not validate( { "val": [ "db168366-c9c3-11ea-bc9e-000000000000", "198047cd-39c3-57be-8da2-7a35eb3c5200", ] }, {"val": "UUIDv3"}, ) assert not validate({"val": "074eaa42-79e8-4bbe-b396-e44e9d7dffaa"}, {"val": "UUIDv3"})
def start_sample_matrix(ratio, lambdas, lr, table_name, l): MAE = 0 RMSE = 0 start_time = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) log.start_log( start_time, "../matrix/" + table_name.decode('utf-8') + "/" + "MF矩阵分解结果.txt".decode('utf-8')) f = log.write_log() lc_table_name = 'lc_' + table_name tp_table_name = 'tp_' + table_name # start预测部分 # # 得到的矩阵是挖取过值的矩阵 # C, original_matrix, changed_zero = dm.getMatrix(table_name, ratio) C, original_matrix, changed_zero = dm.get_Matrix_from_lc_tp( lc_table_name, tp_table_name, ratio, 1) # C = np.array(C) d = C.shape U = np.random.rand(d[0], l) V = np.random.rand(d[1], l) print "开始矩阵分解" matrix, X, Y = simple_mat.matrix_factorization(C, U, V, lambdas, step, lr) # 开始验证 print "开始验证" matrix0, pre_or_mat, num = de.norma_matrix(matrix, original_matrix) MAE, RMSE = vali.validate(matrix, original_matrix, changed_zero) # #end # end预测部分 file_path = "../matrix/" + table_name.decode('utf-8') t = str(ratio) + "_" + str(num) + "_" + start_time + ".txt" # start将矩阵分解后的矩阵保存 np.savetxt(file_path + "/matrix_factorization/MF_matrix_factorization_" + str(ratio) + ".txt", matrix, fmt='%.8f') # end将矩阵分解后的矩阵保存 # start将原矩阵经预测填充后的矩阵保存 np.savetxt(file_path + "/result/MF_pre_" + str(ratio) + ".txt", pre_or_mat, fmt='%.8f') # end 将原矩阵经预测填充后的矩阵保存 # start将矩阵分解后的矩阵(处理过的,负数变0)保存 np.savetxt(file_path + "/out/MF_" + t.decode('utf-8'), matrix0, fmt='%.8f') # end 将矩阵分解后的矩阵(处理过的,负数变0)保存 # end end_time = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) print >> f, "开始时间:", start_time print >> f, "结束时间:", end_time # 显示梯度下降情况 title = 'lr:{0} alpha:{1} beta:{2} step:{3} lambdas:{4} sim:{5}' title = title.format(lr, ab[0], ab[1], step, lambdas, simlambda) print >> f, "参数:", title figure_path = "../matrix/" + table_name.decode( 'utf-8') + "/figure/MF_" + str(ratio) + "_" + start_time + ".jpg" figure.paint1(X, Y, title, figure_path) log.close_log() return MAE, RMSE
def validator_doc(doc_data): results = {} result_errors = {} validation = { 'doc_tab': [Required, In(tab)], 'model_id': [Required, Length(0, maximum=50), lambda x: isinstance(x, str)], 'doc_content': [Required, lambda x: isinstance(x, list)] } res = validate(validation, doc_data) result_errors.update(res.errors) if isinstance(doc_data['doc_content'], list): for content in doc_data['doc_content']: validation = { 'language': [Required, In(language)], 'doc_name': [ Required, Length(0, maximum=50), lambda x: isinstance(x, str) ], 'content_title': [ Required, Length(0, maximum=200), lambda x: isinstance(x, str) ], 'developer': [Length(0, maximum=50), lambda x: isinstance(x, str)], 'brief_intro': [lambda x: isinstance(x, dict)], 'method': [lambda x: isinstance(x, dict)], 'model_evaluation': [lambda x: isinstance(x, dict)], 'data_set_size': [lambda x: isinstance(x, dict)], 'ethnicity': [lambda x: isinstance(x, dict)], 'limitation': [lambda x: isinstance(x, dict)], 'return_params': [lambda x: isinstance(x, dict)], 'state_explain': [lambda x: isinstance(x, dict)], 'example_result': [lambda x: isinstance(x, dict)], 'ref': [lambda x: isinstance(x, list)] } content_res = validate(validation, content) result_errors.update(content_res.errors) valid = True if result_errors: valid = False results['errors'] = result_errors results['valid'] = valid return results
def test_empty_dict_alias(self): dimdata = {} distbuffer = { '__version__': VERSION, 'buffer': b'', 'dim_data': (dimdata, ) } is_valid, msg = validator.validate(distbuffer) self.assertTrue(is_valid, msg)
def validate_input(self, data): rules = { 'name': [Required, Not(Blank())], 'email': [Required, Not(Blank())], 'password': [Required, Not(Blank()), Length(6)], } return validate(rules, data)
def delete(self): try: args = seedParser.parse_args() if (not validate(args, seed_validator)): return {'ERROR': 'arguments may not be valid'}, 422 removeAt(args['seed_type']) return {'message': 'deleted'}, 222 except Exception as e: return {'SERVER ERROR': str(e)}, 522
def validate_input(self, data): rules = { 'company': [Required, Not(Blank())], 'job': [Required, Not(Blank())], 'headline': [Required, Not(Blank())], 'pros': [Required, Not(Blank())], 'cons': [Required, Not(Blank())], } return validate(rules, data)
def _day_seller_en_get(): current_app.logger.info(request.url) current_app.logger.info("current_app _day_seller_en_get get") rules = { "startdate": [Required, Length(8, 8)], "enddate": [Required, Length(8, 8)] } valid, errors = validate(rules, request.args) # current_app.logger.info(str(valid) + str(errors)) result = results() # 参数校验 if not valid: result.set_statuscode(1) result.set_data(str(errors)) return jsonify(json.loads(str(result))) conn = MysqlUtil("adver") sql = """s """ % (request.args.get('startdate', None), request.args.get('enddate', None)) if request.args.get('en', None): sql = sql + " and en in ( '%s') " % (request.args.get('en', None)) sql = sql + """ group by day,en,terminal """ current_app.logger.info(sql) print sql flag, res = conn.excute(sql) if flag: data = [] for row in res: list_col = [ 'day', 'en', 'terminal', 'oreq', 'sreq', 'sres', 'sans', 'request', 'start', 'imp', 'click', 'repository', 'repository_max', 'repository_30max' ] dict_tmp = convert_object(list_col, row) #判断列数是否一致 if dict_tmp == 1: data.append({"error": '序列化列数不一致'}) result.set_data(data) result.set_statuscode(1) return jsonify(json.loads(str(result))) for k, v in dict_tmp.items(): dict_tmp[k] = conver_type(v) data.append(dict_tmp) print "取出的条数=" + str(len(data)) current_app.logger.info("取出的条数=" + str(len(data))) result.set_statuscode(0) result.set_data(data) else: result.set_statuscode(1) result.set_resultMsg(res + ":sql exec fail!!!") return jsonify(json.loads(str(result)))
def _hour_adx_buyer_position_get(): current_app.logger.info(request.url) current_app.logger.info("current_app hour_adx_buyer_position get") rules = { "startdate": [Required, Length(8, 8)], "enddate": [Required, Length(8, 8)] } valid, errors = validate(rules, request.args) # result = results() current_app.logger.info(str(valid) + str(errors)) #参数校验 if not valid: result.set_statuscode(1) result.set_data(str(errors)) return jsonify(json.loads(str(result))) conn = MysqlUtil("adver") sql = """SEL day>=%s and day<=%s """ % (request.args.get('startdate', None), request.args.get('enddate', None)) if request.args.get('b', None): sql = sql + " and buyerid in (%s)" % (request.args.get('b', None)) sql = sql + """ group by hab.buyerid,hab.day,hab.hour,hab.impid,asa.name""" current_app.logger.info(sql) print sql flag, res = conn.excute(sql) if flag: data = [] for row in res: dict_tmp = collections.defaultdict() dict_tmp['buyerid'] = row[0] dict_tmp['day'] = row[1] dict_tmp['hour'] = row[2] dict_tmp['impid'] = row[3] dict_tmp['impidname'] = row[4] dict_tmp['imp'] = row[5] dict_tmp['click'] = row[6] dict_tmp['effectincome'] = row[7] dict_tmp['position_request'] = row[8] dict_tmp['position_bid'] = row[9] dict_tmp['win'] = row[10] dict_tmp['timeoutrate'] = row[11] for k, v in dict_tmp.items(): dict_tmp[k] = conver_type(v) data.append(dict_tmp) print "取出的条数=" + str(len(data)) current_app.logger.info("取出的条数=" + str(len(data))) result.set_statuscode(0) result.set_data(data) else: result.set_statuscode(1) result.set_resultMsg(res + ":sql exec fail!!!") return jsonify(json.loads(str(result)))
def test_validator_valid(): validation = validate( test_schema, { "name": "Daniel", "age": 30, "hired_at": "1970-01-01", "married": "married" }) print(validation) assert validation == True
def test_validate_invalid_in_vertical(self): assert False == validate([[5, 3, 4, 6, 7, 8, 9, 1, 2], [6, 7, 2, 1, 9, 5, 3, 4, 8], [1, 9, 8, 3, 4, 2, 5, 6, 7], [8, 5, 9, 7, 6, 1, 4, 2, 3], [4, 2, 6, 8, 5, 3, 7, 9, 1], [7, 1, 3, 9, 2, 4, 8, 5, 6], [9, 6, 1, 5, 3, 7, 2, 8, 4], [2, 8, 7, 4, 1, 9, 6, 3, 5], [5, 4, 5, 2, 8, 6, 1, 7, 9]])
def test_validate_invalid_in_block(self): assert False == validate([[1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 4, 5, 6, 7, 8, 9, 1], [3, 4, 5, 6, 7, 8, 9, 1, 2], [4, 5, 6, 7, 8, 9, 1, 2, 3], [5, 6, 7, 8, 9, 1, 2, 3, 4], [6, 7, 8, 9, 1, 2, 3, 4, 5], [7, 8, 9, 1, 2, 3, 4, 5, 6], [8, 9, 1, 2, 3, 4, 5, 6, 7], [9, 1, 2, 3, 4, 5, 6, 7, 8]])
def test(sub_size, difficulty_lvl): grid = generate(sub_size) clean(grid, difficulty_lvl) sudoku = Sudoku(grid) solver = Solver(sudoku) solver.solve() return solver.is_completed(), validate( sudoku.grid), solver.count, solver.found
def test_validate_is_true(self): assert True == validate([[5, 3, 4, 6, 7, 8, 9, 1, 2], [6, 7, 2, 1, 9, 5, 3, 4, 8], [1, 9, 8, 3, 4, 2, 5, 6, 7], [8, 5, 9, 7, 6, 1, 4, 2, 3], [4, 2, 6, 8, 5, 3, 7, 9, 1], [7, 1, 3, 9, 2, 4, 8, 5, 6], [9, 6, 1, 5, 3, 7, 2, 8, 4], [2, 8, 7, 4, 1, 9, 6, 3, 5], [3, 4, 5, 2, 8, 6, 1, 7, 9]])
def _validate(self): result = validate(self.arguments_valid_rules, self.request.DATA) if not result[0]: # 格式有误,直接报错 try: error_dict = {arg: result[1][arg][0] for arg in result[1].keys()} error_info = ", ".join(["参数 %s 出错: %s" % (key, value) for key, value in error_dict.iteritems()]) raise APIError(HTTP_STATUS_BAD_REQUEST, log_message=error_info) except (IndexError, KeyError): raise APIError(HTTP_STATUS_BAD_REQUEST, log_message="参数缺失或格式有误")
def _validateFileForm(form): '''Validate file passed to the file foram''' # at this point form data are not on disk yet, and form contains complete # file data, not a file name. input_data = db.input_data(form.vars.id) _log.info('index: input file: %s', input_data) try: validator.validate(os.path.join(request.folder, 'uploads', input_data.input_file)) # on success set hidden fields input_data.update_record(original_name=request.vars.input_file.filename, created=datetime.datetime.now()) _log.info('index: validation succeeded') return True except Exception as ex: # if validation fails then display an error form.errors.input_file = T('file_validation_failed') + ': ' + str(ex) _log.info('index: validation failed', exc_info=True) return False
def test_uuidv4_03(): assert validate({"val": "0d713a92-8406-489e-b0bd-24af3d1da2fa"}, {"val": "uuidv4"}) assert validate({"val": "e96e74e2-f106-4ad7-9467-322ba6cb3c78"}, {"val": "uuidv4"}) assert not validate( { "val": [ "0d713a92-8406-489e-b0bd-24af3d1da2fa", "e96e74e2-f106-4ad7-9467-322ba6cb3c78", ] }, {"val": "uuidv4"}, ) assert not validate({"val": "addee3a2-c941-11ea-bbd4-ab0012dacf6c"}, {"val": "uuidv4"})
def post(self): try: args = seedParser.parse_args() if (not validate(args, seed_validator)): return {'ERROR': 'arguments may not be valid'}, 422 # Add the appropriate data seedAt(args['seed_type']) return {'message': 'success'}, 222 except Exception as e: return {'message': str(e)}, 522
def validate_progdata(progdict, directory=None): members = [ "lastimages", "reconnect", "lastpage", "lastindex", "link_identifier", "image_identifier" ] return validate(progdict, members, directory=directory)
def test_size_12_dict(): assert validate( {"val": { "k1": "v1", "k2": "v2", "k3": "v3" }}, {"val": "dict|size:3"}, ) # ToDo : More True Tests with dict assert not validate( {"val": { "k1": "v1", "k2": "v2", "k3": "v3" }}, {"val": "dict|size:25"}, )
def test_validator_invalid_if_not_dict(): # Observe! Below uses json.dumps to cast data to string, which should not validate data = json.dumps({ "name": "Daniel", "age": 30, "hired_at": "1970-01-01", "married": "married" }) validation = validate(test_schema, data) print(validation) assert validation == {'data': 'data is not a dictionary'}
def test_validator_with_non_existing_file(): absolute_path = os.path.dirname(os.path.abspath(__file__)) schema_file = os.path.join(absolute_path, "schemas/does-not-exist.json") validation = validate(schema_file, { "name": "Daniel", "age": 30, "hired_at": "1970-01-01" }) print(validation) assert validation == {'schema': 'schema file does not exist'}
def test_missing_version(self): dimdata = { 'dist_type': 'c', 'size': 3, 'proc_grid_size': 4, 'proc_grid_rank': 3, 'start': 3, } distbuffer = {'buffer': b'', 'dim_data': (dimdata, )} is_valid, msg = validator.validate(distbuffer) self.assertTrue(not is_valid, msg)
def validate_service(data): rules = { "name": [Required, Length(3, 50)], "fqdn": [Required], "healthcheck_path": [], "healthcheck_interval": [Range(1000, 60000)], "healthcheck_rise": [Range(0, 20)], "healthcheck_fall": [Range(0, 20)], "connection_draining": [Range(5, 300)] } return validate(rules, data)
def test_interface_3(): """Test group creation via the third interface.""" tcex_instance = utility.init_tcex() owner = tcex_instance.args.api_default_org batch = tcex_instance.batch(owner) batch_group_creation_interface_3.adversary_create(batch) batch_group_creation_interface_3.campaign_create(batch) batch_group_creation_interface_3.document_create(batch) batch_group_creation_interface_3.document_malware_create(batch) batch_group_creation_interface_3.email_create(batch) batch_group_creation_interface_3.event_create(batch) batch_group_creation_interface_3.incident_create(batch) batch_group_creation_interface_3.intrusion_set_create(batch) batch_group_creation_interface_3.report_create(batch) batch_group_creation_interface_3.signature_create(batch) batch_group_creation_interface_3.threat_create(batch) results = batch.submit_all() assert results[0]['errorCount'] == 0 assert results[0]['successCount'] == 11 validator.validate(tcex_instance, expected_groups=11)
def test_validator_with_file(): absolute_path = os.path.dirname(os.path.abspath(__file__)) schema_file = os.path.join(absolute_path, "schemas/test-schema.json") validation = validate(schema_file, { "name": "Daniel", "age": 30, "hired_at": "1970-01-01" }) print(validation) assert validation == True
def get(self, username): try: # ^^^^^^^^^^^ ERROR CHECK ^^^^^^^^^^^^^^^^^^^^^^^ if (not validate(username, username_validator)): error_str = username + ' does not exist.' return {'server_error': error_str}, 242 # vvvvvvvvvvv ERROR CHECK END vvvvvvvvvvvvvvvvv user1 = User.query.filter_by(username=username).first() return user1, 222 except Exception as e: return {'server_error': str(e)}, 522
def get(self): try: return { 'server_error': 'TODO: setup respone which returns users around, top, bottom, etc' }, 322 args = users_parser.parse_args() # ^^^^^^^^^^^ ERROR CHECK ^^^^^^^^^^^^^^^^^^^^^^^ if (not validate(args, users_validator)): return { 'server_error': 'one or more parameters not valid' }, 422 if (not validate(args['username'], username_validator)): error_str = username + ' does not exist.' return {'server_error': error_str}, 422 # vvvvvvvvvvv ERROR CHECK END vvvvvvvvvvvvvvvvv return {'user': '******'}, 222 except Exception as e: return {'server_error': str(e)}, 522
def validar_header(self,header): rules = { "Authorization": [Required], "Content-Type": [Required,Equals('application/json')] } respuesta=validate(rules, header) if respuesta[0]: return True,'' else: codigo = generador.validarGuardarInformacionError("000","validar header- no se enviaron todo los parametros- header_controller","post",'') return False ,codigo
def test_07_validate_simple(): request = {"age": 23} rule = {"age": [R.Integer, R.Min(18), R.Max(30)]} result = validate(request, rule) assert result request = {"age": 33} rule = {"age": [R.Integer, R.Min(18), R.Max(30)]} result = validate(request, rule) assert not result request = {"age": 23, "name": "Jon"} rule = {"age": [R.Integer, R.Min(18)], "name": [R.Required()]} result = validate(request, rule) assert result request = {"age": 23, "name": ""} rule = {"age": [R.Integer, R.Min(18), R.Max(30)], "name": [R.Required()]} result = validate(request, rule) assert not result
def validate_metadata(metadict, directory=None): """Validates that the given comic metadata is valid""" members = [ "title", "authors" ] optpaths = [ "descriptionfile", "coverfile" ] return validate(metadict, members, optpaths=optpaths, directory=directory)
def test_missing_version(self): dimdata = { 'dist_type':'c', 'size':3, 'proc_grid_size':4, 'proc_grid_rank':3, 'start' : 3, } distbuffer = {'buffer' : b'', 'dim_data' : (dimdata,)} is_valid, msg = validator.validate(distbuffer) self.assertTrue(not is_valid, msg)
def test_cyclic(self): dim_data = ({'dist_type': 'c', 'size': 50, 'proc_grid_size': 2, 'proc_grid_rank': 0, 'start': 0},) distbuffer = {'__version__': VERSION, 'buffer': np.ones(50), 'dim_data': dim_data} is_valid, msg = validator.validate(distbuffer) self.assertTrue(is_valid, msg)
def test_route_parser(self): test_path = ("packages", "validator.py", "0.8.0") route = ("packages", ":pkg", ":ver") params = mite.router.parse_path(route, test_path) validation = { "pkg": [Required, Equals("validator.py")], "ver": [Required, Equals("0.8.0")] } valid, errs = validate(validation, params) assert errs == {}
def test_json_test(self): with open('test_files/validator/students-small.json') as students_file: students_json = json.load(students_file) with open('test_files/validator/teachers-small.json') as teachers_file: teachers_json = json.load(teachers_file) periods_in_day = 3 result = validate(students_json, teachers_json, periods_in_day) self.assertIsInstance(result, bool) print('Validator result:', result)
def paramsvalidator(payload): rules = { "name": [InstanceOf(str)], "uuid": [ If( InstanceOf(str), Then( Pattern( "\w\w\w\w\w\w\w\w-\w\w\w\w-\w\w\w\w-\w\w\w\w-\w\w\w\w\w\w\w\w\w\w\w\w" ))) ], # Example UUID = 8243c413-2575-461e-87e8-5f203c611223 "rarity": [ If(InstanceOf(str), Then(In(["Epic", "Legendary", "Rare", "Uncommon", "Common"]))) ], "hex_type": [If(InstanceOf(str), Then(In(["Card", "Equipment", "Pack"])))], "hex_set": [ If( InstanceOf(str), Then( In([ "AI Only Cards", "Armies of Myth", "AZ1", "AZ2", "Dead of Winter", "Frostheart", "Frostheart Core Commons", "Herofall", "Primal Dawn", "PvE 01 Universal Card Set", "Scars of War", "Set01 Kickstarter", "Set01 PvE Arena", "Set01 PvE Holiday", "Set03 PvE Promo", "Set04 PvE Promo", "Set05 PvE Promo", "Set06 PvE Promo", "Set07 PvE Promo", "Set08 PvE Promo", "Shards of Fate", "Shattered Destiny" ]))) ], "limit": [If(InstanceOf(int), Then(InstanceOf(int))) ], # teger - Limits the quantity of returned results (default: 25) "offset": [If(InstanceOf(int), Then(InstanceOf(int))) ], #Integer - Skips offset articles before returning (default: 0) "contains": [If(InstanceOf(str), Then(InstanceOf(bool)))], "currency": [If(InstanceOf(str), Then(In(["Gold", "Platinum"])))], # In Game currency "start": [ Pattern("\d\d\d\d-\d\d-\d\d") ], # String - A valid date representation, such as "2016-01-01" (default: the date for the time of the request in CET timezone - 31 days) "end": [ Pattern("\d\d\d\d-\d\d-\d\d") ] # String - same as above (default: the date of the time of the request in CET timezone) } results = validate(rules, payload) return results.valid
def test_bad_unstructured_indices(self): """Test non-buffer for unstructured indices.""" dim_data = ({'dist_type': 'u', 'size': 100, 'proc_grid_size': 2, 'proc_grid_rank': 0, 'indices': [1, 2, 3, 4]},) distbuffer = {'__version__': VERSION, 'buffer': np.ones(4), 'dim_data': dim_data} is_valid, msg = validator.validate(distbuffer) self.assertFalse(is_valid, msg)
def run(self): """Run method that performs all the real work""" selectedLayerIndex = -1 counter = -1 layers = self.iface.legendInterface().layers() layer_list = [] for layer in layers: if layer.type() == QgsMapLayer.VectorLayer: layer_list.append(layer.name()) counter += 1 if layer == self.iface.mapCanvas().currentLayer(): selectedLayer = layer selectedLayerIndex = counter self.dlg.comboBox.clear() self.dlg.comboBox.addItems(layer_list) self.dlg.comboBox.setCurrentIndex(selectedLayerIndex) # show the dialog self.dlg.show() # Run the dialog event loop result = self.dlg.exec_() # See if OK was pressed if result: # Do something useful here - delete the line containing pass and # substitute with your code. rulesfile = self.dlg.rulesFile.text() layer = self.getVectorLayerByName(self.dlg.comboBox.currentText()) err_file = self.dlg.outputFile.text() checked = self.check_input_values(rulesfile, layer, err_file) if checked: cleaned = self.remove_previous_output(err_file) validate(rulesfile, None, layer, err_file) self.iface.addVectorLayer(err_file, "output:errors", "ogr") self.iface.setActiveLayer(layer)
def test_bad_buffer(self): dimdata = { 'dist_type':'c', 'size':3, 'proc_grid_size':4, 'proc_grid_rank':3, 'start' : 3, } distbuffer = {'__version__': VERSION, 'dim_data' : (dimdata,), 'buffer' : [1,2,3,4],} is_valid, msg = validator.validate(distbuffer) self.assertTrue(not is_valid, msg)
def test_unstructured(self): dim_data = ({'dist_type': 'u', 'size': 50, 'proc_grid_size': 2, 'proc_grid_rank': 1, 'indices': np.array([1, 22, 44, 49, 9, 33, 21], dtype=np.uint32) },) distbuffer = {'__version__': VERSION, 'buffer': np.ones(len(dim_data[0]['indices'])), 'dim_data': dim_data} is_valid, msg = validator.validate(distbuffer) self.assertTrue(is_valid, msg)
def test_empty_process(self): dimdata = { 'dist_type':'c', 'size':3, 'proc_grid_size':4, 'proc_grid_rank':3, 'start' : 3, } distbuffer = {'__version__': VERSION, 'buffer' : b'', 'dim_data' : (dimdata,)} is_valid, msg = validator.validate(distbuffer) self.assertTrue(is_valid, msg)
def test_bad_cyclic_block_size(self): """Test negative block size in cyclic.""" dim_data = ({'dist_type': 'c', 'size': 100, 'proc_grid_size': 3, 'proc_grid_rank': 0, 'start': 0, 'block_size': -10},) distbuffer = {'__version__': VERSION, 'buffer': np.ones(10), 'dim_data': dim_data} is_valid, msg = validator.validate(distbuffer) self.assertFalse(is_valid, msg)
def test_bad_block_start(self): """Test negative start.""" dim_data = ({'dist_type': 'b', 'size': 50, 'proc_grid_size': 2, 'proc_grid_rank': 0, 'start': -1, 'stop': 10},) distbuffer = {'__version__': VERSION, 'buffer': np.ones(11), 'dim_data': dim_data} is_valid, msg = validator.validate(distbuffer) self.assertFalse(is_valid, msg)
def make_move(myboard, word, position, direction, rack): """returns a new board and updates the player rack iff the move in question is valid""" newboard = board.play_word(myboard, word, position, direction) if not validator.validate(newboard): raise Exception('new board state is invalid') for letter in word: if letter not in rack: raise Exception('a letter in the word was not in the rack') rack.remove(letter.lower()) return newboard
def test_bad_dist_type(self): """Test stop > size.""" dim_data = ({'dist_type': 'q', 'size': 50, 'proc_grid_size': 2, 'proc_grid_rank': 0, 'start': 0, 'stop': 51},) distbuffer = {'__version__': VERSION, 'buffer': np.ones(51), 'dim_data': dim_data} is_valid, msg = validator.validate(distbuffer) self.assertFalse(is_valid, msg)
def test_undistributed_padded_periodic(self): dim_data = ({'dist_type': 'b', 'size': 10, 'proc_grid_size': 1, 'proc_grid_rank': 0, 'start': 0, 'stop': 10, 'padding': (2,2), 'periodic': True,},) distbuffer = {'__version__': VERSION, 'buffer': np.ones(10), 'dim_data': dim_data} is_valid, msg = validator.validate(distbuffer) self.assertTrue(is_valid, msg)
def test_bad_block_padding(self): """Test padding not ints.""" dim_data = ({'dist_type': 'b', 'size': 50, 'proc_grid_size': 2, 'proc_grid_rank': 0, 'start': 0, 'stop': 10, 'padding': ('a','b')},) distbuffer = {'__version__': VERSION, 'buffer': np.ones(10), 'dim_data': dim_data} is_valid, msg = validator.validate(distbuffer) self.assertFalse(is_valid, msg)
def check(self): print 'compiling...' solution = self.get_solution() if not solution.compile(): print 'CompileError' exit(-1) if not os.path.exists(self.get_input_file_name(0)) or \ not os.path.exists(self.get_output_file_name(0)): print 'downloading...' self.download() max_time = 0.0 validator = self.get_validator() ok = True no_input_files = True for index in range(100): input_file_path = self.get_input_file_name(index) output_file_path = self.get_output_file_name(index) if not os.path.exists(input_file_path): break no_input_files = False print '----- Case #%d -----' % index execution_time = solution.execute(input_file_path, 'out.txt') if max_time < execution_time: max_time = execution_time if os.path.exists(output_file_path): ok = validator.validate(output_file_path, 'out.txt') and ok else: subprocess.Popen(['cat', 'out.txt']).wait() if no_input_files: print 'No input files...' elif ok: print 'OK (max ' + str(max_time) + "s)" else: print 'WrongAnswer (max ' + str(max_time) + "s)"
def score(corpus, ner): if ner == 'ritter': results = ritter_ner.ner(corpus+'.ttl', "nif") print "NER completado" elif ner == 'stanford-en': results = stanford_ner.ner(corpus+'.ttl', "nif", 'english') print "NER completado" elif ner == 'stanford-es': results = stanford_ner.ner(corpus+'.ttl', "nif", 'spanish') print "NER completado" elif ner == 'polyglot-en': results = polyglot_ner.ner(corpus+'.ttl', 'nif', 'en') print "NER completado" elif ner == 'polyglot-es': results = polyglot_ner.ner(corpus+'.ttl', 'nif', 'es') print "NER completado" elif ner == 'citius-en': results = citius_ner.ner(corpus+'.ttl', 'nif', 'en') print "NER completado" elif ner == 'citius-es': results = citius_ner.ner(corpus+'.ttl', 'nif', 'es') print "NER completado" elif ner == 'voting': results = voting(corpus) print "NER completado" nifresults = resultstonif.convert(results, corpus+'.xml') print "Conversión a NIF completada" resultspath = corpus+'-results.ttl' with codecs.open(resultspath, 'wb', encoding='utf-8') as resultsfile: resultsfile.write(nifresults) print "NIF guardado" scores = validator.validate(corpus+'.ttl', resultspath) print "Validación completada" return scores
def main(): args = parse_args() # We read all these upfront to avoid race conditions where VAL # sees a different domain/problem/plan than what we compute the # hash ID for. domain_text = util.read_file(args.domain) problem_text = util.read_file(args.problem) plan_text = util.read_file(args.plan) try: quality = validator.validate(domain_text, problem_text, plan_text) except validator.Error as e: print e else: result = db.Result( domain_text=domain_text, problem_text=problem_text, plan_text=plan_text, plan_comment="<no comment for this plan>", plan_quality=quality) result.update_db()
def test_student_yaml(self): is_str = InstanceOf(type("")) spec = { 'blog': [Required, is_str], 'feed': [Required, is_str], 'forges': [Required, InstanceOf(list)], 'hw': [Required, InstanceOf(dict)], 'irc': [Required, is_str], 'name': [Required, is_str], 'rit_dce': [Required, is_str], # optional fields 'bio': [is_str], 'twitter': [is_str], 'coderwall': [is_str], } student_files = [] for root, _, fnames in os.walk( os.path.join(os.getcwd(), "people")): for fname in fnames: if (fname.endswith('.yaml') or fname.endswith('.yml')): student_files.append(os.path.join(root, fname)) for fullname in student_files: with open(fullname, 'r') as student: content = yaml.safe_load(student) validity = validate(spec, content) if not validity[0]: out = "" for k, v in validity[1].items(): out += ("File: {f} Key: {key} " "{check}\n\n".format(key=k, check=v, f=fullname) ) self.fail(out)
from sklearn import linear_model import csv import ingestor import validator training_data, training_target, test_data, test_target = ingestor.get_data( '../clean_data.csv') lr = linear_model.LogisticRegression() lr.fit(training_data, training_target) print validator.validate(lr, test_data, test_target)
def validate_board(board): if validator.validate(board) == True: return True else: return False
#!/usr/bin/env python """ Main file for Assignment 2 Stage 1""" import sys import validator import weather """ Main Section """ # call validator, get a request object back with valid data else None request = validator.validate(sys.argv) if (request != None): # testing #print request.get_location() #print request.get_time() # testing scenario 2 #print request.get_day_of_week() #print request.is_today() # call get weather, get a weather object back, None if error getting data print "*** Calling weather ***" #weather.get_weather(request) else: print "invalid request"