How to use test_strings method in assertpy

Best Python code snippet using assertpy_python

test_editdistance.py

Source:test_editdistance.py Github

copy

Full Screen

...4import numpy as np5import pytest6from symspellpy.editdistance import (AbstractDistanceComparer, DamerauOsa,7 EditDistance, Levenshtein)8def build_test_strings():9 alphabet = "abcd"10 strings = [""]11 for i in range(1, len(alphabet) + 1):12 for combi in combinations(alphabet, i):13 strings += ["".join(p) for p in permutations(combi)]14 return strings15def get_levenshtein(string_1, string_2, max_distance):16 max_distance = max_distance = int(min(2 ** 31 - 1, max_distance))17 len_1 = len(string_1)18 len_2 = len(string_2)19 d = np.zeros((len_1 + 1, len_2 + 1))20 for i in range(len_1 + 1):21 d[i, 0] = i22 for i in range(len_2 + 1):23 d[0, i] = i24 for j in range(1, len_2 + 1):25 for i in range(1, len_1 + 1):26 if string_1[i - 1] == string_2[j - 1]:27 # no operation28 d[i, j] = d[i - 1, j - 1]29 else:30 d[i, j] = min(min(d[i - 1, j] + 1,31 d[i, j - 1] + 1),32 d[i - 1, j - 1] + 1)33 distance = d[len_1, len_2]34 return distance if distance <= max_distance else -135def get_damerau_osa(string_1, string_2, max_distance):36 max_distance = max_distance = int(min(2 ** 31 - 1, max_distance))37 len_1 = len(string_1)38 len_2 = len(string_2)39 d = np.zeros((len_1 + 1, len_2 + 1))40 for i in range(len_1 + 1):41 d[i, 0] = i42 for i in range(len_2 + 1):43 d[0, i] = i44 for i in range(1, len_1 + 1):45 for j in range(1, len_2 + 1):46 cost = 0 if string_1[i - 1] == string_2[j - 1] else 147 d[i, j] = min(min(d[i - 1, j] + 1,48 d[i, j - 1] + 1),49 d[i - 1, j - 1] + cost)50 if (i > 1 and j > 1 and string_1[i - 1] == string_2[j - 2]51 and string_1[i - 2] == string_2[j - 1]):52 d[i, j] = min(d[i, j], d[i - 2, j - 2] + cost)53 distance = d[len_1, len_2]54 return distance if distance <= max_distance else -155class TestEditDistance(unittest.TestCase):56 test_strings = build_test_strings()57 def test_unknown_distance_algorithm(self):58 with pytest.raises(ValueError) as excinfo:59 __ = EditDistance(2)60 self.assertEqual("Unknown distance algorithm", str(excinfo.value))61 def test_abstract_distance_comparer(self):62 with pytest.raises(NotImplementedError) as excinfo:63 comparer = AbstractDistanceComparer()64 __ = comparer.distance("string_1", "string_2", 10)65 self.assertEqual("Should have implemented this", str(excinfo.value))66 def test_levenshtein_match_ref_max_0(self):67 max_distance = 068 comparer = Levenshtein()69 for s1 in self.test_strings:70 for s2 in self.test_strings:...

Full Screen

Full Screen

nodes.py

Source:nodes.py Github

copy

Full Screen

1from NENV import *2import ctypes.test.test_strings3class NodeBase(Node):4 pass5class Array_Node(NodeBase):6 """7 """8 9 title = 'ARRAY'10 type_ = 'ctypes.test.test_strings'11 init_inputs = [12 NodeInputBP(label='typ'),13 NodeInputBP(label='len'),14 ]15 init_outputs = [16 NodeOutputBP(type_='data'),17 ]18 color = '#32DA22'19 def update_event(self, inp=-1):20 self.set_output_val(0, ctypes.test.test_strings.ARRAY(self.input(0), self.input(1)))21 22class Cfunctype_Node(NodeBase):23 """24 CFUNCTYPE(restype, *argtypes,25 use_errno=False, use_last_error=False) -> function prototype.26 restype: the result type27 argtypes: a sequence specifying the argument types28 The function prototype can be called in different ways to create a29 callable object:30 prototype(integer address) -> foreign function31 prototype(callable) -> create and return a C callable function from callable32 prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method33 prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal34 prototype((function name, dll object)[, paramflags]) -> foreign function exported by name35 """36 37 title = 'CFUNCTYPE'38 type_ = 'ctypes.test.test_strings'39 init_inputs = [40 NodeInputBP(label='restype'),41 ]42 init_outputs = [43 NodeOutputBP(type_='data'),44 ]45 color = '#32DA22'46 def update_event(self, inp=-1):47 self.set_output_val(0, ctypes.test.test_strings.CFUNCTYPE(self.input(0)))48 49class Dllcanunloadnow_Node(NodeBase):50 """51 """52 53 title = 'DllCanUnloadNow'54 type_ = 'ctypes.test.test_strings'55 init_inputs = [56 57 ]58 init_outputs = [59 NodeOutputBP(type_='data'),60 ]61 color = '#32DA22'62 def update_event(self, inp=-1):63 self.set_output_val(0, ctypes.test.test_strings.DllCanUnloadNow())64 65class Dllgetclassobject_Node(NodeBase):66 """67 """68 69 title = 'DllGetClassObject'70 type_ = 'ctypes.test.test_strings'71 init_inputs = [72 NodeInputBP(label='rclsid'),73 NodeInputBP(label='riid'),74 NodeInputBP(label='ppv'),75 ]76 init_outputs = [77 NodeOutputBP(type_='data'),78 ]79 color = '#32DA22'80 def update_event(self, inp=-1):81 self.set_output_val(0, ctypes.test.test_strings.DllGetClassObject(self.input(0), self.input(1), self.input(2)))82 83class Pyfunctype_Node(NodeBase):84 """85 """86 87 title = 'PYFUNCTYPE'88 type_ = 'ctypes.test.test_strings'89 init_inputs = [90 NodeInputBP(label='restype'),91 ]92 init_outputs = [93 NodeOutputBP(type_='data'),94 ]95 color = '#32DA22'96 def update_event(self, inp=-1):97 self.set_output_val(0, ctypes.test.test_strings.PYFUNCTYPE(self.input(0)))98 99class Setpointertype_Node(NodeBase):100 """101 """102 103 title = 'SetPointerType'104 type_ = 'ctypes.test.test_strings'105 init_inputs = [106 NodeInputBP(label='pointer'),107 NodeInputBP(label='cls'),108 ]109 init_outputs = [110 NodeOutputBP(type_='data'),111 ]112 color = '#32DA22'113 def update_event(self, inp=-1):114 self.set_output_val(0, ctypes.test.test_strings.SetPointerType(self.input(0), self.input(1)))115 116class Winfunctype_Node(NodeBase):117 """118 """119 120 title = 'WINFUNCTYPE'121 type_ = 'ctypes.test.test_strings'122 init_inputs = [123 NodeInputBP(label='restype'),124 ]125 init_outputs = [126 NodeOutputBP(type_='data'),127 ]128 color = '#32DA22'129 def update_event(self, inp=-1):130 self.set_output_val(0, ctypes.test.test_strings.WINFUNCTYPE(self.input(0)))131 132class Winerror_Node(NodeBase):133 """134 """135 136 title = 'WinError'137 type_ = 'ctypes.test.test_strings'138 init_inputs = [139 NodeInputBP(label='code', dtype=dtypes.Data(default=None, size='s')),140 NodeInputBP(label='descr', dtype=dtypes.Data(default=None, size='s')),141 ]142 init_outputs = [143 NodeOutputBP(type_='data'),144 ]145 color = '#32DA22'146 def update_event(self, inp=-1):147 self.set_output_val(0, ctypes.test.test_strings.WinError(self.input(0), self.input(1)))148 149class _Calcsize_Node(NodeBase):150 """151 Return size in bytes of the struct described by the format string."""152 153 title = '_calcsize'154 type_ = 'ctypes.test.test_strings'155 init_inputs = [156 NodeInputBP(label='format'),157 ]158 init_outputs = [159 NodeOutputBP(type_='data'),160 ]161 color = '#32DA22'162 def update_event(self, inp=-1):163 self.set_output_val(0, ctypes.test.test_strings._calcsize(self.input(0)))164 165class _Check_Size_Node(NodeBase):166 """167 """168 169 title = '_check_size'170 type_ = 'ctypes.test.test_strings'171 init_inputs = [172 NodeInputBP(label='typ'),173 NodeInputBP(label='typecode', dtype=dtypes.Data(default=None, size='s')),174 ]175 init_outputs = [176 NodeOutputBP(type_='data'),177 ]178 color = '#32DA22'179 def update_event(self, inp=-1):180 self.set_output_val(0, ctypes.test.test_strings._check_size(self.input(0), self.input(1)))181 182class _Reset_Cache_Node(NodeBase):183 """184 """185 186 title = '_reset_cache'187 type_ = 'ctypes.test.test_strings'188 init_inputs = [189 190 ]191 init_outputs = [192 NodeOutputBP(type_='data'),193 ]194 color = '#32DA22'195 def update_event(self, inp=-1):196 self.set_output_val(0, ctypes.test.test_strings._reset_cache())197 198class C_Buffer_Node(NodeBase):199 """200 """201 202 title = 'c_buffer'203 type_ = 'ctypes.test.test_strings'204 init_inputs = [205 NodeInputBP(label='init'),206 NodeInputBP(label='size', dtype=dtypes.Data(default=None, size='s')),207 ]208 init_outputs = [209 NodeOutputBP(type_='data'),210 ]211 color = '#32DA22'212 def update_event(self, inp=-1):213 self.set_output_val(0, ctypes.test.test_strings.c_buffer(self.input(0), self.input(1)))214 215class Cast_Node(NodeBase):216 """217 """218 219 title = 'cast'220 type_ = 'ctypes.test.test_strings'221 init_inputs = [222 NodeInputBP(label='obj'),223 NodeInputBP(label='typ'),224 ]225 init_outputs = [226 NodeOutputBP(type_='data'),227 ]228 color = '#32DA22'229 def update_event(self, inp=-1):230 self.set_output_val(0, ctypes.test.test_strings.cast(self.input(0), self.input(1)))231 232class Create_String_Buffer_Node(NodeBase):233 """234 create_string_buffer(aBytes) -> character array235 create_string_buffer(anInteger) -> character array236 create_string_buffer(aBytes, anInteger) -> character array237 """238 239 title = 'create_string_buffer'240 type_ = 'ctypes.test.test_strings'241 init_inputs = [242 NodeInputBP(label='init'),243 NodeInputBP(label='size', dtype=dtypes.Data(default=None, size='s')),244 ]245 init_outputs = [246 NodeOutputBP(type_='data'),247 ]248 color = '#32DA22'249 def update_event(self, inp=-1):250 self.set_output_val(0, ctypes.test.test_strings.create_string_buffer(self.input(0), self.input(1)))251 252class Create_Unicode_Buffer_Node(NodeBase):253 """254 create_unicode_buffer(aString) -> character array255 create_unicode_buffer(anInteger) -> character array256 create_unicode_buffer(aString, anInteger) -> character array257 """258 259 title = 'create_unicode_buffer'260 type_ = 'ctypes.test.test_strings'261 init_inputs = [262 NodeInputBP(label='init'),263 NodeInputBP(label='size', dtype=dtypes.Data(default=None, size='s')),264 ]265 init_outputs = [266 NodeOutputBP(type_='data'),267 ]268 color = '#32DA22'269 def update_event(self, inp=-1):270 self.set_output_val(0, ctypes.test.test_strings.create_unicode_buffer(self.input(0), self.input(1)))271 272class String_At_Node(NodeBase):273 """274 string_at(addr[, size]) -> string275 Return the string at addr."""276 277 title = 'string_at'278 type_ = 'ctypes.test.test_strings'279 init_inputs = [280 NodeInputBP(label='ptr'),281 NodeInputBP(label='size', dtype=dtypes.Data(default=-1, size='s')),282 ]283 init_outputs = [284 NodeOutputBP(type_='data'),285 ]286 color = '#32DA22'287 def update_event(self, inp=-1):288 self.set_output_val(0, ctypes.test.test_strings.string_at(self.input(0), self.input(1)))289 290class Wstring_At_Node(NodeBase):291 """292 wstring_at(addr[, size]) -> string293 Return the string at addr."""294 295 title = 'wstring_at'296 type_ = 'ctypes.test.test_strings'297 init_inputs = [298 NodeInputBP(label='ptr'),299 NodeInputBP(label='size', dtype=dtypes.Data(default=-1, size='s')),300 ]301 init_outputs = [302 NodeOutputBP(type_='data'),303 ]304 color = '#32DA22'305 def update_event(self, inp=-1):306 self.set_output_val(0, ctypes.test.test_strings.wstring_at(self.input(0), self.input(1)))307 308export_nodes(309 Array_Node,310 Cfunctype_Node,311 Dllcanunloadnow_Node,312 Dllgetclassobject_Node,313 Pyfunctype_Node,314 Setpointertype_Node,315 Winfunctype_Node,316 Winerror_Node,317 _Calcsize_Node,318 _Check_Size_Node,319 _Reset_Cache_Node,320 C_Buffer_Node,321 Cast_Node,322 Create_String_Buffer_Node,323 Create_Unicode_Buffer_Node,324 String_At_Node,325 Wstring_At_Node,...

Full Screen

Full Screen

test_string_reader.py

Source:test_string_reader.py Github

copy

Full Screen

1import addpath2import dunlin as dn3import dunlin._utils_model.dun_string_reader as dsr4if __name__ == '__main__':5 6 ###############################################################################7 #DN Subsection Code Strings without Errors8 ###############################################################################9 def test_string_without_error(test_string, answer, **kwargs):10 r = dsr.read_dun(test_string, **kwargs)11 assert r == answer12 13 #Test dict values14 test_strings = [['x : 0', 15 {'x': 0}],16 ['x : 0, y : 1', 17 {'x': 0, 'y': 1}],18 ['x : 0, y : 1, z : [a : 2, b : 3]', 19 {'x': 0, 'y': 1, 'z': {'a': 2, 'b': 3}}],20 ['x : 0, y : 1, z : [a : [c : 2, d : 3 ], b : [e : 4, f : 5]]',21 {'x': 0, 'y': 1, 'z': {'a': {'c': 2, 'd': 3}, 'b': {'e': 4, 'f': 5}}}],22 ['x : 0, y : 1, z : [a : [c : 2, d : 3 ], b : [e : 4, f : 5]], j : 6',23 {'x': 0, 'y': 1, 'z': {'a': {'c': 2, 'd': 3}, 'b': {'e': 4, 'f': 5}}, 'j': 6}]24 ]25 26 for test_string, answer in test_strings:27 test_string_without_error(test_string, answer)28 29 #Test list values and mixing30 test_strings = [['x : [0, 1]',31 {'x': [0, 1]}],32 ['x : [0, 1]*2, y : [0, 1, 2]',33 {'x': [0, 1], 'y': [0, 1, 2]}],34 ['x : [0, 1], y : [[0, 1, 2], [0, 1, 2]]',35 {'x': [0, 1], 'y': [[0, 1, 2], [0, 1, 2]]}],36 ['x : [0, 1], y : [[0, 1, 2], [0, 1, 2]], z : [a : 3, b : 4]',37 {'x': [0, 1], 'y': [[0, 1, 2], [0, 1, 2]], 'z': {'a': 3, 'b': 4}}],38 ]39 40 for test_string, answer in test_strings:41 test_string_without_error(test_string, answer)42 43 ###############################################################################44 #DN Subsection Code Strings with Errors45 ###############################################################################46 def read_dun_with_error(test_string, num, **kwargs):47 expected : False48 try:49 dsr.read_dun(test_string, **kwargs)50 except dsr.DunlinStringError as e:51 expected = e.num == num52 except Exception as e:53 raise e54 assert expected55 56 #Test inconsistent data types57 test_strings = ['x : [0, g : 1]',58 'x : [g : 0, 1], y : [0, 1, 2]',59 'x : [g : 0, h : 1], y : [0, j : 1, 2]',60 ]61 62 for test_string in test_strings:63 read_dun_with_error(test_string, 1)64 65 #Test for values outside brackets66 test_strings = ['x : 0 [a : 1, b : 2]',67 'x : [a : 1, b : 2] 0',68 'x : [a : 1, b : 2], y : 0 [1, 2]'69 ]70 71 for test_string in test_strings:72 read_dun_with_error(test_string, 2)73 74 #Test for top level list75 test_strings = ['[0, 1, 2]',76 '0, 1, 2'77 ]78 79 for test_string in test_strings:80 read_dun_with_error(test_string, 3)81 82 #Test for missing brackets83 test_strings = ['x : [0,',84 'x : [0, 1]]'85 ]86 87 for test_string in test_strings:88 read_dun_with_error(test_string, 4)89 90 #Test for invalid values91 test_strings = ['x : ?',92 'x : ;',93 'x : `',94 ''95 ]96 for test_string in test_strings:97 read_dun_with_error(test_string, 5)98 99 #Test depth 100 test_strings = ['x : [a : [g : [j : 0, k : 0] ], b : [g : [j : 0, k : 0] ]],',101 'x : [0, 1]'102 ]103 104 for test_string in test_strings:...

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