How to use string_cleanup method in Nose2

Best Python code snippet using nose2

smart_title_case.py

Source: smart_title_case.py Github

copy

Full Screen

...44 word = word[0].upper() + word[1:]45 return word46def string_title_match(match_word, string):47 return title_re.sub(match_word, string)48def string_cleanup(string):49 if not string:50 return ""51 return unicodedata.normalize("NFKC", string)52def string_title_case(string):53 """Title-case a string using a less destructive method than str.title."""54 return string_title_match(match_word, string_cleanup(string))55def artist_title_case(text, artists, artists_upper):56 """57 Use the array of artists and the joined string58 to identify artists to make title case59 and the join strings to leave as-is.60 """61 find = "^(" + r")(\s+\S+?\s+)(".join((map(re.escape, map(string_cleanup,artists)))) + ")(.*$)"62 replace = "".join([r"%s\%d" % (a, x*2 + 2) for x, a in enumerate(artists_upper)])63 result = re.sub(find, replace, string_cleanup(text))64 return result65################################################66# Uncomment the following to enable unit tests #67################################################68#69# assert "Make Title Case" == string_title_case("make title case")70# assert "Already Title Case" == string_title_case("Already Title Case")71# assert "mIxEd cAsE" == string_title_case("mIxEd cAsE")72# assert "A" == string_title_case("a")73# assert "Apostrophe's Apostrophe's" == string_title_case("apostrophe's apostrophe's")74# assert "(Bracketed Text)" == string_title_case("(bracketed text)")75# assert "'Single Quotes'" == string_title_case("'single quotes'")76# assert '"Double Quotes"' == string_title_case('"double quotes"')77# assert "A,B" == string_title_case("a,b")...

Full Screen

Full Screen

file_reader.py

Source: file_reader.py Github

copy

Full Screen

...29 def remove_stop_words(self):30 with open('./​stop_words.txt', 'r') as stopwords:31 for line in stopwords:32 for word in line.split("\t")[0].split():33 self.stop_words[self.string_cleanup(word)] = 13435 def string_cleanup(self, string):36 # return string37 # return string.lower()38 return string.lower().translate(None, "\",./​][';<>|!@#$%^&=+*()|`-_~\\")3940 def create_words_bank(self):41 index = 1 # starting with 1 because 0 cant serve as a dictionary key42 with open(self.file, 'r') as reader: # open the file "file"43 for line in reader: # for each line in file44 for word in line.split("\t")[0].split(): # for each word in the line45 checked = self.string_cleanup(word)46 if checked not in (self.words.keys() or self.stop_words.keys()): # if the word doesnt already exist in the words dictionary47 self.words[checked] = index # add it48 index += 14950 def count_file_lines(self, file_to_count):51 return sum(1 for line in open(file_to_count))5253 def build_set_boolean(self, file_to_vector):54 doc_set = {}55 index = 056 with open(file_to_vector, 'r') as reader:57 for line in reader:58 vec = len(self.words)*[0, ]59 for word in line.split("\t")[0].split():60 checked = self.string_cleanup(word)61 if checked not in self.stop_words.keys():62 vec[self.words[checked]-1] = 163 doc_class = line.split("\t")[1].rstrip()64 vec.append(doc_class)65 self.indexed_line['doc'+str(index)] = str(line.split("\t")[0:-1]).strip('[]"\'')66 doc_set['doc'+str(index)] = vec67 index += 168 return doc_set6970 def build_set_tf(self, file_to_vector):71 doc_set = {}72 index = 073 with open(file_to_vector, 'r') as reader:74 for line in reader:75 vec = len(self.words)*[0, ]76 wf_vec = len(self.words)*[0, ]77 for word in line.split("\t")[0].split():78 checked = self.string_cleanup(word)79 if checked not in self.stop_words.keys():80 vec[self.words[checked]-1] += 181 for word in line.split("\t")[0].split():82 checked = self.string_cleanup(word)83 temp_index = self.words[checked]-184 if checked not in self.stop_words.keys():85 if vec[temp_index] > 0:86 wf_vec[temp_index] = 1 + math.log(vec[temp_index])87 doc_class = line.split("\t")[1].rstrip()88 wf_vec.append(doc_class)89 doc_set['doc'+str(index)] = wf_vec90 index += 191 return doc_set9293 def build_df(self, file_to_vector):94 df = {}95 with open(file_to_vector, 'r') as file:96 for line in file:97 wordlist = []98 for word in line.split("\t")[0].split():99 checked = self.string_cleanup(word)100 if checked not in self.stop_words.keys():101 wordlist.append(checked)102 wordset = set(wordlist)103 for word in wordset:104 if word in df.keys():105 df[word] += 1106 else:107 df[word] = 1108 return df109110 def build_set_tfidf(self, file_to_vector):111 tfidf_set = {}112 tf_set = self.build_set_tf(file_to_vector)113 idf = {}114 df = self.build_df(file_to_vector)115 n = self.count_file_lines(file_to_vector)116 for word in df.keys():117 idf[word] = math.log(n /​ df[word])118 with open(file_to_vector, 'r') as file:119 index = 0120 for line in file:121 doci = 'doc'+str(index)122 vec = len(self.words) * [0, ]123 for word in line.split("\t")[0].split():124 checked = self.string_cleanup(word)125 wordi = self.words[checked]-1126 if checked not in self.stop_words.keys():127 vec[wordi] = tf_set[doci][wordi] * idf[checked]128 doc_class = line.split("\t")[1].rstrip()129 vec.append(doc_class)130 self.indexed_line[doci] = str(line.split("\t")[0:-1]).strip('[]"\'')131 tfidf_set[doci] = vec132 index += 1 ...

Full Screen

Full Screen

cleanup.py

Source: cleanup.py Github

copy

Full Screen

...91 for word in word_toclean :92 # Clean word as is93 filename = re.sub(word, '', filename.strip(' \t\n\r\.'))94 # Clean word "cleaned"95 word = string_cleanup(word)96 filename = re.sub(word, '', filename.strip(' \t\n\r\.'))97 # Generic cleaning98 filename = string_cleanup(filename)99 return filename100def string_cleanup(string) :101 ''' Clean string '''102 # Generic cleaning103 string = re.sub('[^\w\s-]', '-', string.strip(' \t\n\r\.').lower())104 string = re.sub('[-\s]+', '-', string)105 return string106if __name__ == "__main__":...

Full Screen

Full Screen

crud.py

Source: crud.py Github

copy

Full Screen

...13 writer = csv.writer(csvfile)14 for row in data:15 writer.writerow(row)16 csvfile.close()17def string_cleanup(string):18 ''' Remove circle bracket, quote and space from string. '''19 string = string.strip('()').replace("'", '').replace(' ', '')20 return string21while True:22 command = input('>')23 if command.startswith('GPA'):24 # GPA Grade.csv 1 125 command = command.split()26 table = command[1] # Grade.csv27 year = command[2] # 128 semester = command[3] # 129 data = read_csvfile(table)30 select_data = [row for row in data if row[0] == year and row[1] == semester]31 credit = [int(row[-2]) for row in select_data]32 grade = []33 for row in select_data:34 if row[-1] == 'A':35 grade.append(4)36 elif row[-1] == 'B+':37 grade.append(3.5)38 elif row[-1] == 'B':39 grade.append(3)40 elif row[-1] == 'C+':41 grade.append(2.5)42 elif row[-1] == 'C':43 grade.append(2)44 elif row[-1] == 'D+':45 grade.append(1.5)46 elif row[-1] == 'D':47 grade.append(1)48 else:49 grade.append(0)50 point = [a * b for (a, b) in zip(grade, credit)] # credit * grade51 gpa = math.floor(sum(point) /​ sum(credit) * 100) /​ 10052 print(gpa)53 elif command.startswith('INSERT INTO'):54 # INSERT INTO Grade.csv VALUES ('1', '1', 'Data', '3', 'B+')55 command = command.split(' VALUES ')56 table = command[0].split()[2] # Grade.csv57 value = [string_cleanup(command[1]).split(',')] # [['1', '1', 'Data', '3', 'B+']]58 write_csvfile(table, 'a', value)59 elif command.startswith('UPDATE'):60 # UPDATE Grade.csv SET Grade='A' WHERE Subject='Data'61 command = command.split()62 table = command[1] # Grade.csv63 where_attr = command[5].split('=')[0] # Subject64 where_value = string_cleanup(command[5].split('=')[1]) # Data65 set_attr = command[3].split('=')[0] # Grade66 set_value = string_cleanup(command[3].split('=')[1]) # A67 # Read data68 data = read_csvfile(table)69 attributes = data[0]70 attr_to_change = attributes.index(set_attr)71 attr_to_find = attributes.index(where_attr)72 # Find attribute73 for row in range(len(data)):74 if where_value == data[row][attr_to_find]:75 data[row][attr_to_change] = set_value76 break77 write_csvfile(table, 'w', data)78 else:...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

What will come after “agile”?

I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.

Difference Between Web vs Hybrid vs Native Apps

Native apps are developed specifically for one platform. Hence they are fast and deliver superior performance. They can be downloaded from various app stores and are not accessible through browsers.

Considering Agile Principles from a different angle

In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.

How To Identify Locators In Appium [With Examples]

Nowadays, automation is becoming integral to the overall quality of the products being developed. Especially for mobile applications, it’s even more important to implement automation robustly.

Getting Rid of Technical Debt in Agile Projects

Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.

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 Nose2 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