How to use test_method method in Slash

Best Python code snippet using slash

test_test_component.py

Source:test_test_component.py Github

copy

Full Screen

...107 exc_val = sys.exc_info()[1]108 ok = issubclass(exc_typ, expected_exception)109 if not ok:110 print_error("*** Wrong exception setting '%s' to '%r'- got '%s: %s', expected '%s'" % (attr_name, new_value, exc_typ, exc_val, expected_exception))111def test_method(method, args, expected_results):112 if xpcom.verbose:113 print "Testing %s%s" % (method.__name__, `args`)114 ret = method(*args)115 if ret != expected_results:116 print_error("calling method %s - expected %r, but got %r" % (method.__name__, expected_results, ret))117def test_int_method(meth):118 test_method(meth, (0,0), (0,0,0))119 test_method(meth, (1,1), (2,0,1))120 test_method(meth, (5,2), (7,3,10))121# test_method(meth, (2,5), (7,-3,10))122def test_constant(ob, cname, val):123 v = getattr(ob, cname)124 if v != val:125 print_error("Bad value for constant '%s' - got '%r'" % (cname, v))126 try:127 setattr(ob, cname, 0)128 print_error("The object allowed us to set the constant '%s'" % (cname,))129 except AttributeError:130 pass131def test_base_interface(c):132 test_attribute(c, "boolean_value", 1, 0)133 test_attribute(c, "boolean_value", 1, -1, 1) # Set a bool to anything, you should always get back 0 or 1134 test_attribute(c, "boolean_value", 1, 4, 1) # Set a bool to anything, you should always get back 0 or 1135 test_attribute(c, "boolean_value", 1, "1", 1) # This works by virtual of PyNumber_Int - not sure I agree, but...136 test_attribute_failure(c, "boolean_value", "boo", ValueError)137 test_attribute_failure(c, "boolean_value", test_base_interface, TypeError)138 test_attribute(c, "octet_value", 2, 5)139 test_attribute(c, "octet_value", 2, 0)140 test_attribute(c, "octet_value", 2, 128) # octet is unsigned 8 bit141 test_attribute(c, "octet_value", 2, 255) # octet is unsigned 8 bit142 test_attribute(c, "octet_value", 2, -1, 255) # octet is unsigned 8 bit143 test_attribute_failure(c, "octet_value", "boo", ValueError)144 test_attribute(c, "short_value", 3, 10)145 test_attribute(c, "short_value", 3, -1) # 16 bit signed146 test_attribute(c, "short_value", 3, 0xFFFF, -1) # 16 bit signed147 test_attribute(c, "short_value", 3, 0L)148 test_attribute(c, "short_value", 3, 1L)149 test_attribute(c, "short_value", 3, -1L)150 test_attribute(c, "short_value", 3, 0xFFFFL, -1)151 test_attribute_failure(c, "short_value", "boo", ValueError)152 test_attribute(c, "ushort_value", 4, 5)153 test_attribute(c, "ushort_value", 4, 0)154 test_attribute(c, "ushort_value", 4, -1, 0xFFFF) # 16 bit signed155 test_attribute(c, "ushort_value", 4, 0xFFFF) # 16 bit signed156 test_attribute(c, "ushort_value", 4, 0L)157 test_attribute(c, "ushort_value", 4, 1L)158 test_attribute(c, "ushort_value", 4, -1L, 0xFFFF)159 test_attribute_failure(c, "ushort_value", "boo", ValueError)160 test_attribute(c, "long_value", 5, 7)161 test_attribute(c, "long_value", 5, 0)162 test_attribute(c, "long_value", 5, 0xFFFFFFFF, -1) # 32 bit signed.163 test_attribute(c, "long_value", 5, -1) # 32 bit signed.164 test_attribute(c, "long_value", 5, 0L)165 test_attribute(c, "long_value", 5, 1L)166 test_attribute(c, "long_value", 5, -1L)167 test_attribute_failure(c, "long_value", 0xFFFFL * 0xFFFF, OverflowError) # long int too long to convert168 test_attribute_failure(c, "long_value", "boo", ValueError)169 test_attribute(c, "ulong_value", 6, 7)170 test_attribute(c, "ulong_value", 6, 0)171 test_attribute(c, "ulong_value", 6, 0xFFFFFFFF) # 32 bit signed.172 test_attribute_failure(c, "ulong_value", "boo", ValueError)173 174 test_attribute(c, "long_long_value", 7, 8)175 test_attribute(c, "long_long_value", 7, 0)176 test_attribute(c, "long_long_value", 7, -1)177 test_attribute(c, "long_long_value", 7, 0xFFFF)178 test_attribute(c, "long_long_value", 7, 0xFFFFL * 2)179 test_attribute_failure(c, "long_long_value", 0xFFFFL * 0xFFFF * 0xFFFF * 0xFFFF, OverflowError) # long int too long to convert180 test_attribute_failure(c, "long_long_value", "boo", ValueError)181 182 test_attribute(c, "ulong_long_value", 8, 9)183 test_attribute(c, "ulong_long_value", 8, 0)184 test_attribute_failure(c, "ulong_long_value", "boo", ValueError)185 test_attribute_failure(c, "ulong_long_value", -1, UnsignedMismatchException) # can't convert negative value to unsigned long)186 187 test_attribute(c, "float_value", 9.0, 10.2)188 test_attribute(c, "float_value", 9.0, 0)189 test_attribute(c, "float_value", 9.0, -1)190 test_attribute(c, "float_value", 9.0, 1L)191 test_attribute_failure(c, "float_value", "boo", ValueError)192 test_attribute(c, "double_value", 10.0, 9.0)193 test_attribute(c, "double_value", 10.0, 0)194 test_attribute(c, "double_value", 10.0, -1)195 test_attribute(c, "double_value", 10.0, 1L)196 test_attribute_failure(c, "double_value", "boo", ValueError)197 198 test_attribute(c, "char_value", "a", "b")199 test_attribute(c, "char_value", "a", "\0")200 test_attribute_failure(c, "char_value", "xy", ValueError)201 test_attribute(c, "char_value", "a", u"c")202 test_attribute(c, "char_value", "a", u"\0")203 test_attribute_failure(c, "char_value", u"xy", ValueError)204 205 test_attribute(c, "wchar_value", "b", "a")206 test_attribute(c, "wchar_value", "b", "\0")207 test_attribute_failure(c, "wchar_value", "hi", ValueError)208 test_attribute(c, "wchar_value", "b", u"a")209 test_attribute(c, "wchar_value", "b", u"\0")210 test_attribute_failure(c, "wchar_value", u"hi", ValueError)211 212 test_string_attribute(c, "string_value", "cee", is_dumb_sz = True, ascii_only = True)213 test_string_attribute(c, "wstring_value", "dee", is_dumb_sz = True)214 test_string_attribute(c, "astring_value", "astring")215 test_string_attribute(c, "acstring_value", "acstring", ascii_only = True)216 test_string_attribute(c, "utf8string_value", "utf8string")217 # Test a string already encoded gets through correctly.218 test_attribute(c, "utf8string_value", "utf8string", extended_unicode_string.encode("utf8"), extended_unicode_string)219 # This will fail internal string representation :( Test we don't crash220 try:221 c.wstring_value = "a big char >" + chr(129) + "<"222 print_error("strings with chars > 128 appear to have stopped failing?")223 except UnicodeError:224 pass225 test_attribute(c, "iid_value", component_iid, new_iid)226 test_attribute(c, "iid_value", component_iid, str(new_iid), new_iid)227 test_attribute(c, "iid_value", component_iid, xpcom._xpcom.IID(new_iid))228 test_attribute_failure(c, "no_attribute", "boo", AttributeError)229 test_attribute(c, "interface_value", None, c)230 test_attribute_failure(c, "interface_value", 2, TypeError)231 test_attribute(c, "isupports_value", None, c)232 # The methods233 test_method(c.do_boolean, (0,1), (1,0,1))234 test_method(c.do_boolean, (1,0), (1,0,1))235 test_method(c.do_boolean, (1,1), (0,1,0))236 test_int_method(c.do_octet)237 test_int_method(c.do_short)238 test_int_method(c.do_unsigned_short)239 test_int_method(c.do_long)240 test_int_method(c.do_unsigned_long)241 test_int_method(c.do_long_long)242 test_int_method(c.do_unsigned_long)243 test_int_method(c.do_float)244 test_int_method(c.do_double)245 test_method(c.do_char, ("A", " "), (chr(ord("A")+ord(" ")), " ","A") )246 test_method(c.do_char, ("A", "\0"), ("A", "\0","A") )247 test_method(c.do_wchar, ("A", " "), (chr(ord("A")+ord(" ")), " ","A") )248 test_method(c.do_wchar, ("A", "\0"), ("A", "\0","A") )249 test_method(c.do_string, ("Hello from ", "Python"), ("Hello from Python", "Hello from ", "Python") )250 test_method(c.do_string, (u"Hello from ", u"Python"), ("Hello from Python", "Hello from ", "Python") )251 test_method(c.do_string, (None, u"Python"), ("Python", None, "Python") )252 test_method(c.do_string, (None, really_big_string), (really_big_string, None, really_big_string) )253 test_method(c.do_string, (None, really_big_wstring), (really_big_string, None, really_big_string) )254 test_method(c.do_wstring, ("Hello from ", "Python"), ("Hello from Python", "Hello from ", "Python") )255 test_method(c.do_wstring, (u"Hello from ", u"Python"), ("Hello from Python", "Hello from ", "Python") )256 test_method(c.do_string, (None, really_big_wstring), (really_big_wstring, None, really_big_wstring) )257 test_method(c.do_string, (None, really_big_string), (really_big_wstring, None, really_big_wstring) )258 test_method(c.do_nsIIDRef, (component_iid, new_iid), (component_iid, component_iid, new_iid))259 test_method(c.do_nsIIDRef, (new_iid, component_iid), (new_iid, component_iid, component_iid))260 test_method(c.do_nsIPythonTestInterface, (None, None), (None, None, c))261 test_method(c.do_nsIPythonTestInterface, (c, c), (c, c, c))262 test_method(c.do_nsISupports, (None, None), (c, None, None))263 test_method(c.do_nsISupports, (c,c), (c, c, c))264 test_method(c.do_nsISupportsIs, (xpcom._xpcom.IID_nsISupports,), c)265 test_method(c.do_nsISupportsIs, (xpcom.components.interfaces.nsIPythonTestInterface,), c)266## test_method(c.do_nsISupportsIs2, (xpcom.components.interfaces.nsIPythonTestInterface,c), (xpcom.components.interfaces.nsIPythonTestInterface,c))267## test_method(c.do_nsISupportsIs3, (c,), (xpcom.components.interfaces.nsIPythonTestInterface,c))268## test_method(c.do_nsISupportsIs4, (), (xpcom.components.interfaces.nsIPythonTestInterface,c))269 # Test the constants.270 test_constant(c, "One", 1)271 test_constant(c, "Two", 2)272 test_constant(c, "MinusOne", -1)273 test_constant(c, "BigLong", 0x7FFFFFFF)274 test_constant(c, "BiggerLong", 0xFFFFFFFF)275 test_constant(c, "BigULong", 0xFFFFFFFF)276 # Test the components.Interfaces semantics277 i = xpcom.components.interfaces.nsIPythonTestInterface278 test_constant(i, "One", 1)279 test_constant(i, "Two", 2)280 test_constant(i, "MinusOne", -1)281 test_constant(i, "BigLong", 0x7FFFFFFF)282 test_constant(i, "BigULong", 0xFFFFFFFF)283def test_derived_interface(c, test_flat = 0):284 val = "Hello\0there"285 expected = val * 2286 test_method(c.DoubleString, (val,), expected)287 test_method(c.DoubleString2, (val,), expected)288 test_method(c.DoubleString3, (val,), expected)289 test_method(c.DoubleString4, (val,), expected)290 test_method(c.UpString, (val,), val.upper())291 test_method(c.UpString2, (val,), val.upper())292 test_method(c.GetFixedString, (20,), "A"*20)293 val = u"Hello\0there"294 expected = val * 2295 test_method(c.DoubleWideString, (val,), expected)296 test_method(c.DoubleWideString2, (val,), expected)297 test_method(c.DoubleWideString3, (val,), expected)298 test_method(c.DoubleWideString4, (val,), expected)299 test_method(c.UpWideString, (val,), val.upper())300 test_method(c.UpWideString2, (val,), val.upper())301 test_method(c.GetFixedWideString, (20,), u"A"*20)302 val = extended_unicode_string303 test_method(c.CopyUTF8String, ("foo",), "foo")304 test_method(c.CopyUTF8String, (u"foo",), "foo")305 test_method(c.CopyUTF8String, (val,), val)306 test_method(c.CopyUTF8String, (val.encode("utf8"),), val)307 test_method(c.CopyUTF8String2, ("foo",), "foo")308 test_method(c.CopyUTF8String2, (u"foo",), "foo")309 test_method(c.CopyUTF8String2, (val,), val)310 test_method(c.CopyUTF8String2, (val.encode("utf8"),), val)311 items = [1,2,3,4,5]312 test_method(c.MultiplyEachItemInIntegerArray, (3, items,), map(lambda i:i*3, items))313 test_method(c.MultiplyEachItemInIntegerArrayAndAppend, (3, items), items + map(lambda i:i*3, items))314 items = "Hello from Python".split()315 expected = map( lambda x: x*2, items)316 test_method(c.DoubleStringArray, (items,), expected)317 test_method(c.CompareStringArrays, (items, items), cmp(items, items))318 # Can we pass lists and tuples correctly?319 test_method(c.CompareStringArrays, (items, tuple(items)), cmp(items, items))320 items2 = ["Not", "the", "same"]321 test_method(c.CompareStringArrays, (items, items2), cmp(items, items2))322 expected = items[:]323 expected.reverse()324 test_method(c.ReverseStringArray, (items,), expected)325 expected = "Hello from the Python test component".split()326 test_method(c.GetStrings, (), expected)327 val = "Hello\0there"328 test_method(c.UpOctetArray, (val,), val.upper())329 test_method(c.UpOctetArray, (unicode(val),), val.upper())330 # Passing Unicode objects here used to cause us grief.331 test_method(c.UpOctetArray2, (val,), val.upper())332 test_method(c.CheckInterfaceArray, ((c, c),), 1)333 test_method(c.CheckInterfaceArray, ((c, None),), 0)334 test_method(c.CheckInterfaceArray, ((),), 1)335 test_method(c.CopyInterfaceArray, ((c, c),), [c,c])336 test_method(c.GetInterfaceArray, (), [c,c,c, None])337 test_method(c.ExtendInterfaceArray, ((c,c,c, None),), [c,c,c,None,c,c,c,None] )338 expected = [xpcom.components.interfaces.nsIPythonTestInterfaceDOMStrings, xpcom.components.classes[contractid].clsid]339 test_method(c.GetIIDArray, (), expected)340 val = [xpcom.components.interfaces.nsIPythonTestInterfaceExtra, xpcom.components.classes[contractid].clsid]341 expected = val * 2342 test_method(c.ExtendIIDArray, (val,), expected)343 test_method(c.GetArrays, (), ( [1,2,3], [4,5,6] ) )344 test_method(c.CopyArray, ([1,2,3],), [1,2,3] )345 test_method(c.CopyAndDoubleArray, ([1,2,3],), [1,2,3,1,2,3] )346 test_method(c.AppendArray, ([1,2,3],), [1,2,3])347 test_method(c.AppendArray, ([1,2,3],[4,5,6]), [1,2,3,4,5,6])348 test_method(c.CopyVariant, (None,), None)349 test_method(c.CopyVariant, (1,), 1)350 test_method(c.CopyVariant, (1.0,), 1.0)351 test_method(c.CopyVariant, (-1,), -1)352 test_method(c.CopyVariant, (sys.maxint+1,), sys.maxint+1)353 test_method(c.CopyVariant, ("foo",), "foo")354 test_method(c.CopyVariant, (u"foo",), u"foo")355 test_method(c.CopyVariant, (c,), c)356 test_method(c.CopyVariant, (component_iid,), component_iid)357 test_method(c.CopyVariant, ((1,2),), [1,2])358 test_method(c.CopyVariant, ((1.2,2.1),), [1.2,2.1])359 test_method(c.CopyVariant, (("foo","bar"),), ["foo", "bar"])360 test_method(c.CopyVariant, ((component_iid,component_iid),), [component_iid,component_iid])361 test_method(c.CopyVariant, ((c,c),), [c,c])362 test_method(c.AppendVariant, (1,2), 3)363 test_method(c.AppendVariant, ((1,2),(3,4)), 10)364 test_method(c.AppendVariant, ("bar", "foo"), "foobar")365 test_method(c.AppendVariant, (None, None), None)366 if not test_flat:367 c = c.queryInterface(xpcom.components.interfaces.nsIPythonTestInterfaceDOMStrings)368# NULL DOM strings don't work yet.369# test_method(c.GetDOMStringResult, (-1,), None)370 test_method(c.GetDOMStringResult, (3,), "PPP")371# test_method(c.GetDOMStringOut, (-1,), None)372 test_method(c.GetDOMStringOut, (4,), "yyyy")373 val = "Hello there"374 test_method(c.GetDOMStringLength, (val,), len(val))375 test_method(c.GetDOMStringRefLength, (val,), len(val))376 test_method(c.GetDOMStringPtrLength, (val,), len(val))377 test_method(c.ConcatDOMStrings, (val,val), val+val)378 test_attribute(c, "domstring_value", "dom", "new dom")379 if c.domstring_value_ro != "dom":380 print "Read-only DOMString not correct - got", c.domstring_ro381 try:382 c.dom_string_ro = "new dom"383 print "Managed to set a readonly attribute - eek!"384 except AttributeError:385 pass386 except:387 print "Unexpected exception when setting readonly attribute: %s: %s" % (sys.exc_info()[0], sys.exc_info()[1])388 if c.domstring_value_ro != "dom":389 print "Read-only DOMString not correct after failed set attempt - got", c.domstring_ro390def do_test_failures():391 c = xpcom.client.Component(contractid, xpcom.components.interfaces.nsIPythonTestInterfaceExtra)...

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