How to use percent_of_tests method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

configuration.py

Source:configuration.py Github

copy

Full Screen

1# coding: utf-823#Hoopaloo - Version 1.0 - 2008/20094#Author: Mariana Romao do Nascimento - mariana@dsc.ufcg.edu.br56from django.conf import settings78TEST_DEFAULT_CODE = "import unittest \n\n\n\nclass %s (unittest.TestCase): \n\n\tdef setUp(self):\n\t\t pass\n\n\n\tdef tearDown(self):\n\t\tpass"910UNDER_TEST_COMPLEMENT = "if __name__== '__main__':\n\tfrom unittest import TestResult\n\tloader = unittest.TestLoader()\n\tloader.testMethodPrefix = 'undertest'\n\tsuite = loader.loadTestsFromTestCase(%s)\n\tr = TestResult()\n\tsuite.run(r)\n\tresult_file = open(%s + 'result.txt', 'wb')\n\tresult_file.write(str(len(r.errors)))\n\tresult_file.write('\\n')\n\tresult_file.write(str(len(r.failures)))\n\tresult_file.write('\\n')\n\tresult_file.write(str(r.testsRun))\n\tresult_file.write('\\n')\n\tresult_file.write(str(r.wasSuccessful()))\n\tresult_file.write('\\n')\n\tfor e in r.errors:\n\t\tresult_file.write(e[1])\n\tfor f in r.failures:\n\t\tresult_file.write(f[1])\n\tresult_file.close()"1112TEST_APPEND = "if __name__== '__main__':\n\tfrom unittest import TestResult\n\tloader = unittest.TestLoader()\n\tsuite = loader.loadTestsFromTestCase(%s)\n\tr = TestResult()\n\tsuite.run(r)\n\tresult_file = open('result.txt', 'wb')\n\tresult_file.write(str(len(r.errors)))\n\tresult_file.write('\\n')\n\tresult_file.write(str(len(r.failures)))\n\tresult_file.write('\\n')\n\tresult_file.write(str(r.testsRun))\n\tresult_file.write('\\n')\n\tresult_file.write(str(r.wasSuccessful()))\n\tresult_file.write('\\n')\n\tfor e in r.errors:\n\t\tresult_file.write(e[1])\n\tfor f in r.failures:\n\t\tresult_file.write(f[1])\n\tresult_file.close()"1314TEST_APPEND_STUDENT_FOLDER = "if __name__== '__main__':\n\tfrom unittest import TestResult\n\tloader = unittest.TestLoader()\n\tsuite = loader.loadTestsFromTestCase(%s)\n\tr = TestResult()\n\tsuite.run(r)\n\tresult_file = open(%s + 'result.txt', 'wb')\n\tresult_file.write(str(len(r.errors)))\n\tresult_file.write('\\n')\n\tresult_file.write(str(len(r.failures)))\n\tresult_file.write('\\n')\n\tresult_file.write(str(r.testsRun))\n\tresult_file.write('\\n')\n\tresult_file.write(str(r.wasSuccessful()))\n\tresult_file.write('\\n')\n\tfor e in r.errors:\n\t\tresult_file.write(e[1])\n\tfor f in r.failures:\n\t\tresult_file.write(f[1])\n\tresult_file.close()"151617INFINITE_LOOP_MSG = "The program entered in infinite loop."1819EMAIL_SYSTEM = 'hoopaloo@dsc.ufcg.edu.br'20SMTP_SERVER = "anjinho.dsc.ufcg.edu.br" 21BACKUP_TEST_NAME = 'backup_test'2223PASSWORD_EMAIL = 'Welcome to Hoopaloo,\n\nYou are registered in the system and your login is: %s and your password is %s.\nThanks,\nHoopaloo.'24FORGOT_PASSWORD_EMAIL = 'Hello %s,\nYou requested a new password. This password is %s and you must change it when access Hoopaloo system at the next time.\n\nThanks, Hoopaloo.'2526RESULT_TEST_FILE = 'result.txt'2728PERCENT_OF_TESTS = [(100, 91), (90, 71), (70, 51), (50, 31), (30, 11), (10, 0)]29PERCENT_OF_SCORE = [(10.0, 9.1), (9.0, 8.1), (8.0, 7.1), (7.0, 6.1), (6.0, 5.1), (5.0, 4.1), (4.0, 3.1), (3.0, 2.1), (2.0, 1.1), (1.0, 0.0)]3031LOGIN_SUCESS = 'You are logged'32LOGOUT_SUCESS = 'You are unlogged'33UNDELIVERED_EXERCISES_MSG = 'You not submited the following exercises and the deadline for the submission is expired.'34#duvida na frase abaixo35DELIVERED_EXERCISES_MSG = 'You submit the following exercises. You can modify your submission if you want.'36AVAILABLE_EXERCISES_MSG = 'The following exercises are available for submission.'37UNDELIVERED_AVAILABLE_EXERCISES_MSG = 'You not submited the following exercises. You must verify the deadline for them.'3839REALIZED_SUBMISSIONS = 'All submissions that you realized in Hoopaloo are listed bellow.'40TEACHER_VIEW_EXPLICATION = 'There are not registered students.'4142PASSWORD_CHANGED_MSG = 'Your password was changed.'43PASSWORD_NOT_MATCHES = 'The two password fields did not match.'44INVALID_PASSWORD = 'The password is invalid.'4546FORGOT_PASSWORD = 'Please check your email. If you did not receive any message, check your spam folder.'4748ASSIGN_SUCESS = 'The assign students to assistant(s) was done sucessfully.'49ASSIGN_ERROR = 'You have not permission to assign students to assistants.'50REVIEW_ASSIGN = 'Review the assigns students to assistant(s) bellow. See usernames with attention.'5152EXERCISE_ADD_SUCESS = 'The exercise was added sucessfully. If you want edit the default test to this exercise click on link "Exercises > List Tests" and edit it.'53EXERCISE_ADD_ERROR = 'Some error exists in your form.'54EXERCISE_ADD_ERROR_DATE = 'Review the date.'55EXERCISE_EXISTS = 'An exercise with the same name already exists.'56EXERCISE_UPDATED_SUCESSFULLY = 'The exercise was updated sucessfully.'57EXERCISE_UPDATE_AVAILABILITY = 'The exercise was updated sucessfully. Please, check the deadline to this exercise.'58EXERCISE_UPDATE_AVAILABILITY_ERROR = 'The execise was not updated. Change the dead line for this exercise before.'59EXERCISE_DELETED = 'The exercise was deleted sucessfully.' 60EXERCISE_UPDATE_FAIL = 'Select a date later than current date.'6162ADD_NOTE_ERROR = "The score must be a integer or a decimal number (use '.' in this case)."63ADD_NOTE_ERROR_2 = 'The score must be between 0 and 10.'6465EXECUTION_PASS = 'Your program passed in all tests (%d tests).'66EXECUTION_FAILED = 'Your program not passed in all tests. There are %d registered tests and you not passed in %d tests.'67#EXECUTION_FAILED = 'Your program passed in none tests.'68EXECUTION_LOOP = 'Your program entered in infinite loop.'69EXECUTION_AFTER = 'Your program was submited sucessfully, but at the moment there are not tests registered.\nWhen tests will be added, your program will be executed and the results sent to you by email.'7071EXECUTION_SUCESS = 'The program of student %s passed in all tests of exercise %s. The link to see the code of program is http://dataccc.gmf.ufcg.edu.br/hoopaloo/submission/student%d/exercise/id=%d'7273SUBMISSION_MSG = 'Do the upload of your program and select given exercise.'74SUBMISSION_ERROR = 'You must choose an exercise.'75SUBMISSION_FAIL = 'It exists some error in method names, imports or syntax of your program. Fix it and try submit again.'76SUBMISION_SUCESS = 'Your program was updated sucessfully. Check your code submission in table bellow.'7778ADD_COMMENT_SCORE_SUCESS = 'Comments/score are addedd sucessfully.'7980TEST_UPDATE_SUCESS = 'The test was updated sucessfully and it will be executed automatically to all students.'81TEST_ADD_SUCESSFULLY = 'The test was added sucessfully.'82TEST_EXISTS = 'A test with the same name already exists.'83TEST_ADD_ERROR = 'Some error exists in your form.'84UNDER_TEST_ADD_SUCESSFULLY = 'The test under test was added sucessfullty. Choose the student submissions to execute.'8586ASSISTANT_ADD_SUCESS = 'The assistants was added sucessfully.'87ASSISTANT_ADD_ERROR = 'The assistants bellow are not registered. Review usernames and emails for them.'88REVIEW_USERNAMES_AND_EMAILS = 'Rewiew usernames and emails.'8990STUDENT_ADD_SUCESS = 'The students were added successfully.'91STUDENT_ADD_ERROR = 'The students bellow are not registered. Review usernames, studentID and emails for them.'9293USER_DELETED = "The user was deleted successfully."94# PERMITIONS9596EXERCISE_ADD_NOT_PERMISSION = 'You have not permission to add exercises.'97TEST_UPDATE_NOT_PERMISSION = 'You have not permission to change tests.'98TESTS_ADD_NOT_PERMISSION = 'You have not permission to add tests.'99EXERCISE_UPDATE_NOT_PERMISSION = 'You have not permission to change exercises.'100EXERCISE_SEE_NOT_PERMISSION = 'You have not permission to see exercise details.'101ASSISTANT_ADD_NOT_PERMISSION = 'You have not permission to add assistants.'102VIEW_USERS_NOT_PERMISSION = 'You have not permissions to see user details.'103DELETE_USERS_NOT_PERMISSION = 'You have not permission to delete users.'104ASSIGN_STUDENTS_NOT_PERMISSION = 'You have not permission to assign students to assistants.'105RESULT_SEE_NOT_PERMISSION = 'You have not permission to see submission data of students.'106TEST_SEE_NOT_PERMISSION = 'You have not permission to see the test details.'107INVALIDATE_TEST_NOT_PERMISSION = 'You have not permission to annul a test.'108TEACHER_VIEW_NOT_PERMISSION = 'You are not a teacher.'109ASSISTANT_VIEW_NOT_PERMISSION = 'You are not a assistant.'110SEE_ACTIONS_NOT_PERMISSION = 'You have not permission to see the system actions.'111STUDENT_ADD_NOT_PERMISSION = 'You have not permission to add students.'112SUBMISSION_NOT_PERMISSION = 'You have not permission to submit programs.'113SUBMISSION_SEE_NOT_PERMISSION = 'You have not permission to see submission details.'114DELETE_ASSOCIATION_NOT_PERMISSION = 'You have not permission to delete assigns between students and assistants.'115116# ACTIONS #117LOG_LOGIN = "Realized login"118LOG_LOGOUT = "Realized logout"119LOG_CHANGE_PASSWORD = "Changed the password"120LOG_FORGOT_PASSWORD = "%s requested a new password to %s"121LOG_ASSIGN_STUDENTS = "Assign the assistant %s to students %s"122LOG_ADD_EXERCISE = "Registered new exercise: %s"123LOG_EDIT_EXERCISE = "Edited the exercise: %s"124LOG_EDIT_SUBMISSION = "Add coments or/and note to submission %d of student %s"125LOG_SUBMISSION = "Submit a solution to exercise %s"126LOG_ADD_TEST = "Registered new test: %s"127LOG_EDIT_TEST = "Edited the test: %s"128LOG_IVALIDATE_TEST = "Annuled a test: %s"129LOG_ADD_ASSISTANT = "Registered new assistant: %s"130LOG_ADD_STUDENT = "Registered new student: %s"131LOG_DELETE_EXERCISE = "Deleted the exercise %s"132LOG_DELETE_USER = "Deleted the user %s" ...

Full Screen

Full Screen

network.py

Source:network.py Github

copy

Full Screen

1import random2import numpy as np3DICTIONARY = ['A', 'B', 'C']4NUMBER_OF_POSITIONS = 45START_POSITION = np.zeros(NUMBER_OF_POSITIONS)6START_POSITION[0] = 17NUMBER_OF_CHARS = len(DICTIONARY)8PERCENT_OF_TESTS = 0.19TenzToAdd = 2.010EPS = 10e-411NU = 0.712NU_ADDER = 0.313class NeuralNetwork:14 tensor = np.zeros([NUMBER_OF_POSITIONS, NUMBER_OF_CHARS, NUMBER_OF_POSITIONS])15 adder = np.zeros(NUMBER_OF_POSITIONS)16 def __init__(self):17 self.tensor = np.zeros([NUMBER_OF_POSITIONS, NUMBER_OF_CHARS, NUMBER_OF_POSITIONS])18 for fr in range(NUMBER_OF_POSITIONS):19 for ch in range(NUMBER_OF_CHARS):20 z = np.random.rand(NUMBER_OF_POSITIONS)21 z = normalize(z)22 for to in range(NUMBER_OF_POSITIONS):23 self.tensor[to][ch][fr] = z[to]24 self.adder = np.zeros(NUMBER_OF_POSITIONS)25 for to in range(NUMBER_OF_POSITIONS):26 self.adder[to] = 1.0 * (to + 1) / (NUMBER_OF_POSITIONS) ### weird27 def check(self, word): # get a word output - forward propogation28 curr_pos = START_POSITION29 for k in range(len(word)):30 curr_word = char_to_vector(word[k])31 curr_pos = match(self, curr_word, curr_pos)32 curr_pos = normalize(curr_pos)33 return lastsum(self, curr_pos)34 def train_online(self, dataset):35 average_error = 1.036 epoch_number = 037 n = len(dataset)38 tests_size = int(PERCENT_OF_TESTS * n)39 while (average_error > EPS):40 random.shuffle(dataset)41 cases_left = len(dataset)42 epoch_number += 143 print('Epoch #' + str(epoch_number))44 while(cases_left > tests_size):45 self.train(dataset[cases_left - 1][0], dataset[cases_left - 1][1])46 cases_left -= 147 average_error = 0.048 for i in range(cases_left):49 average_error += cost_function(dataset[i][1], self.check(dataset[i][0]))50 average_error /= cases_left51 print("Average error: " + str(average_error))52 def train(self, word, exp):53 cut_v = np.vectorize(cut)54 word_length = len(word)55 positions = np.zeros([word_length + 1, NUMBER_OF_POSITIONS])56 before_normalize = np.zeros([word_length, NUMBER_OF_POSITIONS])57 d_tensor = np.zeros([NUMBER_OF_POSITIONS, NUMBER_OF_CHARS, NUMBER_OF_POSITIONS])58 d_adder = np.zeros(NUMBER_OF_POSITIONS)59 positions[0] = START_POSITION60 for k in range(word_length):61 curr_word = char_to_vector(word[k])62 before_normalize[k] = match(self, curr_word, positions[k])63 positions[k + 1] = normalize(before_normalize[k])64 answer = lastsum(self, positions[-1])65 error = cost_function(exp, answer)66 gradient = cost_function_derrivative(exp, answer)67 d_adder += lastsum_derrivative_adder(self, gradient, positions[-1])68 gradient = lastsum_derrivative(self, gradient)69 first_gradient = sum(abs(gradient)) * TenzToAdd70 for k in range(word_length - 1, -1, -1):71 curr_grad = sum(abs(gradient))72 if (curr_grad < 0.001):73 koef = 1.074 else:75 koef = first_gradient / sum(abs(gradient))76 gradient *= koef77 curr_word = char_to_vector(word[k])78 gradient = normalize_derrivative(gradient, before_normalize[k])79 d_tensor += match_derrivative_tensor(gradient, curr_word, positions[k])80 gradient = match_derrivative(self, gradient, curr_word)81 d_tensor /= word_length82 self.tensor = cut_v(self.tensor - NU * d_tensor)83 self.adder = cut_v(self.adder - NU * NU_ADDER * d_adder)84 return error85 def get_automaton(self):86 for j in range(NUMBER_OF_POSITIONS):87 for i in range(NUMBER_OF_CHARS):88 max_ind = 089 for k in range(1, NUMBER_OF_POSITIONS):90 if (nn.tensor[k][i][j] > nn.tensor[max_ind][i][j]):91 max_ind = k92 print(str(j) + ' -> ' + str(max_ind) + ' [label="' + str(DICTIONARY[i]) + '"]')93 for k in range(NUMBER_OF_POSITIONS):94 if (nn.adder[k] > 0.5):95 print(str(k) + " [style=filled, fillcolor=red]")96def cost_function(exp, res):97 return (res - exp) ** 298def cost_function_derrivative(exp, res):99 return res - exp100def match(nn, ch, pos):101 new_pos = np.zeros(NUMBER_OF_POSITIONS)102 for k in range(NUMBER_OF_POSITIONS):103 for i in range (NUMBER_OF_CHARS):104 for j in range (NUMBER_OF_POSITIONS):105 new_pos[k] += nn.tensor[k][i][j] * ch[i] * pos[j]106 return new_pos107def match_derrivative(nn, dz, ch):108 derrivative = np.zeros([NUMBER_OF_POSITIONS, NUMBER_OF_POSITIONS])109 for i in range(NUMBER_OF_POSITIONS):110 for k in range(NUMBER_OF_POSITIONS):111 for j in range (NUMBER_OF_CHARS):112 derrivative[k][i] += nn.tensor[k][j][i] * ch[j]113 return np.dot(dz, derrivative)114def match_derrivative_tensor(dz, ch, pos):115 sample_matrix = np.zeros([NUMBER_OF_CHARS, NUMBER_OF_POSITIONS])116 for i in range(NUMBER_OF_CHARS):117 for j in range(NUMBER_OF_POSITIONS):118 sample_matrix[i][j] = ch[i] * pos[j]119 derrivative = np.zeros([NUMBER_OF_POSITIONS, NUMBER_OF_CHARS, NUMBER_OF_POSITIONS])120 for i in range(NUMBER_OF_POSITIONS):121 derrivative[i] = dz[i] * sample_matrix122 return derrivative123def normalize(t):124 return t / np.sum(t)125def normalize_derrivative(dz, inp):126 derrivative = np.zeros([NUMBER_OF_POSITIONS, NUMBER_OF_POSITIONS])127 sum = np.sum(inp)128 for i in range(NUMBER_OF_POSITIONS):129 for j in range(NUMBER_OF_POSITIONS):130 if(i == j):131 derrivative[i][j] = (sum - inp[i]) / (sum ** 2)132 else:133 derrivative[i][j] = -inp[i] / (sum ** 2)134 return np.dot(dz, derrivative)135def lastsum(nn, x):136 return np.dot(nn.adder, x)137def lastsum_derrivative(nn, dz):138 return np.dot(dz, nn.adder)139def lastsum_derrivative_adder(nn, dz, inp):140 derrivative = np.multiply(inp, nn.adder)141 return np.dot(dz, derrivative)142def char_to_vector(ch):143 index = DICTIONARY.index(ch)144 vec = np.zeros(NUMBER_OF_CHARS)145 vec[index] = 1.0146 return vec147def cut(x): # activation (~relu)148 if (x > 1.0):149 return 1.0150 if (x < 0.0):151 return 0.0152 return x153f = open('generate_dataset.txt', 'r')154dataset = []155for line in f:156 arr = line.split(' ')157 isOk = 1.0158 if arr[1][0] == '0':159 isOk = 0.0160 dataset.append([arr[0], isOk])161nn = NeuralNetwork()162nn.train_online(dataset)...

Full Screen

Full Screen

stats.py

Source:stats.py Github

copy

Full Screen

...50 def run_cmd(self, cli_args):51 project = load_project()52 suites = load_suites_from_project(project, make_test_filter(cli_args))53 stats = compute_stats(suites)54 def percent_of_tests(val):55 return "%2d%%" % (float(val) / stats.tests_nb * 100)56 # Show tags57 lines = []58 for tag in sorted(stats.tags.keys(), key=lambda k: stats.tags[k], reverse=True):59 lines.append([bold(tag), stats.tags[tag], percent_of_tests(stats.tags[tag])])60 print_table(bold("Tags"), ["Tag", "Tests", "In %"], lines)61 # Show properties62 lines = []63 prop_names = sorted(64 stats.properties.keys(),65 key=lambda k: reduce(lambda x, y: x + y, stats.properties[k].values(), 0),66 reverse=True67 )68 for prop_name in prop_names:69 prop_values = sorted(70 stats.properties[prop_name].keys(),71 key=lambda k: stats.properties[prop_name][k],72 reverse=True73 )74 for prop_value in prop_values:75 lines.append([76 bold(prop_name), bold(prop_value),77 stats.properties[prop_name][prop_value],78 percent_of_tests(stats.properties[prop_name][prop_value])79 ])80 print_table(bold("Properties"), ["Property", "Value", "Tests", "In %"], lines)81 # Show links82 lines = []83 for link in sorted(stats.links.keys(), key=lambda k: stats.links[k], reverse=True):84 lines.append([85 bold(link[1] or "-"), link[0], stats.links[link], percent_of_tests(stats.links[link])86 ])87 print_table(bold("Links"), ["Name", "URL", "Tests", "In %"], lines)88 tests_info = bold("%d tests" % stats.tests_nb)89 if stats.disabled_tests_nb > 0:90 tests_info += " (among which %s disabled tests)" % stats.disabled_tests_nb91 suites_info = bold("%d suites" % stats.non_empty_suites_nb)92 if stats.suites_nb > stats.non_empty_suites_nb:93 suites_info += " (+ %d empty suites)" % (stats.suites_nb - stats.non_empty_suites_nb)94 print("Total: %s in %s" % (tests_info, suites_info))95 print()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful