Python test.test_support.is_jython() Examples
The following are 30
code examples of test.test_support.is_jython().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
test.test_support
, or try the search function
.
Example #1
Source File: list_tests.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_iadd(self): super(CommonTest, self).test_iadd() u = self.type2test([0, 1]) u2 = u u += [2, 3] self.assert_(u is u2) u = self.type2test("spam") u += "eggs" self.assertEqual(u, self.type2test("spameggs")) if not test_support.is_jython: self.assertRaises(TypeError, u.__iadd__, None) else: import operator self.assertRaises(TypeError, operator.__iadd__, u, None)
Example #2
Source File: test_codeop.py From oss-ftp with MIT License | 6 votes |
def assertValid(self, str, symbol='single'): '''succeed iff str is a valid piece of code''' if is_jython: code = compile_command(str, "<input>", symbol) self.assertTrue(code) if symbol == "single": d,r = {},{} saved_stdout = sys.stdout sys.stdout = cStringIO.StringIO() try: exec code in d exec compile(str,"<input>","single") in r finally: sys.stdout = saved_stdout elif symbol == 'eval': ctx = {'a': 2} d = { 'value': eval(code,ctx) } r = { 'value': eval(str,ctx) } self.assertEqual(unify_callables(r),unify_callables(d)) else: expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT) self.assertEqual(compile_command(str, "<input>", symbol), expected)
Example #3
Source File: test_codeop.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def assertValid(self, str, symbol='single'): '''succeed iff str is a valid piece of code''' if is_jython: code = compile_command(str, "<input>", symbol) self.assertTrue(code) if symbol == "single": d,r = {},{} saved_stdout = sys.stdout sys.stdout = cStringIO.StringIO() try: exec code in d exec compile(str,"<input>","single") in r finally: sys.stdout = saved_stdout elif symbol == 'eval': ctx = {'a': 2} d = { 'value': eval(code,ctx) } r = { 'value': eval(str,ctx) } self.assertEqual(unify_callables(r),unify_callables(d)) else: expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT) self.assertEqual(compile_command(str, "<input>", symbol), expected)
Example #4
Source File: test_array.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_main(verbose=None): import sys if test_support.is_jython: # CPython specific; returns a memory address del BaseTest.test_buffer_info # No buffers in Jython del BaseTest.test_buffer test_support.run_unittest(*tests) # verify reference counting if verbose and hasattr(sys, "gettotalrefcount"): import gc counts = [None] * 5 for i in xrange(len(counts)): test_support.run_unittest(*tests) gc.collect() counts[i] = sys.gettotalrefcount() print counts
Example #5
Source File: test_array.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_iadd(self): a = array.array(self.typecode, self.example[::-1]) b = a a += array.array(self.typecode, 2*self.example) self.assert_(a is b) self.assertEqual( a, array.array(self.typecode, self.example[::-1]+2*self.example) ) b = array.array(self.badtypecode()) if test_support.is_jython: self.assertRaises(TypeError, operator.add, a, b) self.assertRaises(TypeError, operator.iadd, a, "bad") else: self.assertRaises(TypeError, a.__add__, b) self.assertRaises(TypeError, a.__iadd__, "bad")
Example #6
Source File: test_array.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_byteswap(self): if test_support.is_jython and self.typecode == 'u': # Jython unicodes are already decoded from utf16, # so this doesn't make sense return a = array.array(self.typecode, self.example) self.assertRaises(TypeError, a.byteswap, 42) if a.itemsize in (1, 2, 4, 8): b = array.array(self.typecode, self.example) b.byteswap() if a.itemsize==1: self.assertEqual(a, b) else: self.assertNotEqual(a, b) b.byteswap() self.assertEqual(a, b)
Example #7
Source File: test_codeop.py From medicare-demo with Apache License 2.0 | 6 votes |
def assertValid(self, str, symbol='single'): '''succeed iff str is a valid piece of code''' if is_jython: code = compile_command(str, "<input>", symbol) self.assertTrue(code) if symbol == "single": d,r = {},{} saved_stdout = sys.stdout sys.stdout = cStringIO.StringIO() try: exec code in d exec compile(str,"<input>","single") in r finally: sys.stdout = saved_stdout elif symbol == 'eval': ctx = {'a': 2} d = { 'value': eval(code,ctx) } r = { 'value': eval(str,ctx) } self.assertEquals(unify_callables(r),unify_callables(d)) else: expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT) self.assertEquals( compile_command(str, "<input>", symbol), expected)
Example #8
Source File: test_codeop.py From ironpython2 with Apache License 2.0 | 6 votes |
def assertValid(self, str, symbol='single'): '''succeed iff str is a valid piece of code''' if is_jython: code = compile_command(str, "<input>", symbol) self.assertTrue(code) if symbol == "single": d,r = {},{} saved_stdout = sys.stdout sys.stdout = cStringIO.StringIO() try: exec code in d exec compile(str,"<input>","single") in r finally: sys.stdout = saved_stdout elif symbol == 'eval': ctx = {'a': 2} d = { 'value': eval(code,ctx) } r = { 'value': eval(str,ctx) } self.assertEqual(unify_callables(r),unify_callables(d)) else: expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT) self.assertEqual(compile_command(str, "<input>", symbol), expected)
Example #9
Source File: test_trace.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_main(): tests = [TraceTestCase, RaisingTraceFuncTestCase] if not test_support.is_jython: tests.append(JumpTestCase) else: del TraceTestCase.test_02_arigo del TraceTestCase.test_05_no_pop_tops del TraceTestCase.test_07_raise del TraceTestCase.test_09_settrace_and_raise del TraceTestCase.test_10_ireturn del TraceTestCase.test_11_tightloop del TraceTestCase.test_12_tighterloop del TraceTestCase.test_13_genexp del TraceTestCase.test_14_onliner_if del TraceTestCase.test_15_loops test_support.run_unittest(*tests)
Example #10
Source File: test_chdir.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_main(): tests = [ChdirTestCase, ImportTestCase, ImportPackageTestCase, ZipimportTestCase, PyCompileTestCase, ExecfileTestCase, ExecfileTracebackTestCase, ListdirTestCase, DirsTestCase, FilesTestCase, SymlinkTestCase] if WINDOWS: tests.append(WindowsChdirTestCase) if test_support.is_jython: tests.extend((ImportJavaClassTestCase, ImportJarTestCase)) if test_support.is_resource_enabled('subprocess'): tests.append(SubprocessTestCase) test_support.run_unittest(*tests)
Example #11
Source File: test_profilehooks.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_main(): if test_support.is_jython: del ProfileHookTestCase.test_distant_exception del ProfileHookTestCase.test_exception del ProfileHookTestCase.test_exception_in_except_clause del ProfileHookTestCase.test_exception_propogation del ProfileHookTestCase.test_nested_exception del ProfileHookTestCase.test_raise del ProfileHookTestCase.test_raise_reraise del ProfileHookTestCase.test_raise_twice del ProfileHookTestCase.test_stop_iteration del ProfileSimulatorTestCase.test_basic_exception del ProfileSimulatorTestCase.test_distant_exception test_support.run_unittest( ProfileHookTestCase, ProfileSimulatorTestCase )
Example #12
Source File: test_compile.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_unary_minus(self): # Verify treatment of unary minus on negative numbers SF bug #660455 if sys.maxint == 2147483647: # 32-bit machine all_one_bits = '0xffffffff' self.assertEqual(eval(all_one_bits), 4294967295L) self.assertEqual(eval("-" + all_one_bits), -4294967295L) elif sys.maxint == 9223372036854775807: # 64-bit machine all_one_bits = '0xffffffffffffffff' self.assertEqual(eval(all_one_bits), 18446744073709551615L) self.assertEqual(eval("-" + all_one_bits), -18446744073709551615L) else: self.fail("How many bits *does* this machine have???") # Verify treatment of contant folding on -(sys.maxint+1) # i.e. -2147483648 on 32 bit platforms. Should return int, not long. # XXX: I'd call this an implementation detail, but one that should be # fairly easy and moderately worthwhile to implement. Still it is low # on the list, so leaving it out of jython for now. if not test_support.is_jython: self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 1)), int)) self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 2)), long))
Example #13
Source File: test_list_jy.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_setget_override(self): if not test_support.is_jython: return # http://bugs.jython.org/issue600790 class GoofyListMapThing(ArrayList): def __init__(self): self.silly = "Nothing" def __setitem__(self, key, element): self.silly = "spam" def __getitem__(self, key): self.silly = "eggs" glmt = GoofyListMapThing() glmt['my-key'] = String('el1') self.assertEquals(glmt.silly, "spam") glmt['my-key'] self.assertEquals(glmt.silly, "eggs")
Example #14
Source File: test_codeop.py From BinderFilter with MIT License | 6 votes |
def assertValid(self, str, symbol='single'): '''succeed iff str is a valid piece of code''' if is_jython: code = compile_command(str, "<input>", symbol) self.assertTrue(code) if symbol == "single": d,r = {},{} saved_stdout = sys.stdout sys.stdout = cStringIO.StringIO() try: exec code in d exec compile(str,"<input>","single") in r finally: sys.stdout = saved_stdout elif symbol == 'eval': ctx = {'a': 2} d = { 'value': eval(code,ctx) } r = { 'value': eval(str,ctx) } self.assertEqual(unify_callables(r),unify_callables(d)) else: expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT) self.assertEqual(compile_command(str, "<input>", symbol), expected)
Example #15
Source File: test_tempfile.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_mode(self): # mkdtemp creates directories with the proper mode if not has_stat: return # ugh, can't use TestSkipped. if test_support.is_jython and not os._native_posix: # Java doesn't support stating files for permissions return dir = self.do_create() try: mode = stat.S_IMODE(os.stat(dir).st_mode) mode &= 0777 # Mask off sticky bits inherited from /tmp expected = 0700 if (sys.platform in ('win32', 'os2emx', 'mac') or test_support.is_jython and os._name == 'nt'): # There's no distinction among 'user', 'group' and 'world'; # replicate the 'user' bits. user = expected >> 6 expected = user * (1 + 8 + 64) self.assertEqual(mode, expected) finally: os.rmdir(dir)
Example #16
Source File: test_traceback_jy.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_tb_across_threads(self): if not test_support.is_jython: return # http://bugs.jython.org/issue1533624 class PyRunnable(Runnable): def run(self): raise TypeError('this is only a test') try: EventQueue.invokeAndWait(PyRunnable()) except TypeError: self.assertEqual(tb_info(), [('test_tb_across_threads', 'EventQueue.invokeAndWait(PyRunnable())'), ('run', "raise TypeError('this is only a test')")]) else: self.fail('Expected TypeError')
Example #17
Source File: pickletester.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_long(self): for proto in protocols: # 256 bytes is where LONG4 begins. for nbits in 1, 8, 8*254, 8*255, 8*256, 8*257: nbase = 1L << nbits for npos in nbase-1, nbase, nbase+1: for n in npos, -npos: pickle = self.dumps(n, proto) got = self.loads(pickle) self.assertEqual(n, got) # Try a monster. This is quadratic-time in protos 0 & 1, so don't # bother with those. if is_jython:#see http://jython.org/bugs/1754225 return nbase = long("deadbeeffeedface", 16) nbase += nbase << 1000000 for n in nbase, -nbase: p = self.dumps(n, 2) got = self.loads(p) self.assertEqual(n, got)
Example #18
Source File: test_weakref.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_proxy_ref(self): o = C() o.bar = 1 ref1 = weakref.proxy(o, self.callback) ref2 = weakref.proxy(o, self.callback) del o def check(proxy): proxy.bar extra_collect() self.assertRaises(weakref.ReferenceError, check, ref1) self.assertRaises(weakref.ReferenceError, check, ref2) # XXX: CPython GC collects C() immediately. use ref1 instead on # Jython if test_support.is_jython: self.assertRaises(weakref.ReferenceError, bool, ref1) else: self.assertRaises(weakref.ReferenceError, bool, weakref.proxy(C())) self.assert_(self.cbcalled == 2)
Example #19
Source File: test_enumerate.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_main(verbose=None): if test_support.is_jython: # XXX: CPython implementation details del EnumerateTestCase.test_tuple_reuse del TestReversed.test_len del TestReversed.test_xrange_optimization testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig, TestReversed) test_support.run_unittest(*testclasses) # verify reference counting import sys if verbose and hasattr(sys, "gettotalrefcount"): counts = [None] * 5 for i in xrange(len(counts)): test_support.run_unittest(*testclasses) counts[i] = sys.gettotalrefcount() print counts
Example #20
Source File: test_sax.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_expat_locator_withinfo(): result = StringIO() xmlgen = LocatorTest(result) parser = make_parser() parser.setContentHandler(xmlgen) testfile = findfile("test.xml") parser.parse(testfile) if is_jython: # In Jython, the system id is a URL with forward slashes, and # under Windows findfile returns a path with backslashes, so # replace the backslashes with forward testfile = testfile.replace('\\', '/') # urllib.quote isn't the exact encoder (e.g. ':' isn't escaped) expected = urllib.quote(testfile).replace('%3A', ':') return xmlgen.location.getSystemId().endswith(expected) and \ xmlgen.location.getPublicId() is None # =========================================================================== # # error reporting # # ===========================================================================
Example #21
Source File: test_weakref.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_main(): if test_support.is_jython: # Probably CPython GC specific (possibly even Jython bugs) del ReferencesTestCase.test_callback_in_cycle_resurrection del ReferencesTestCase.test_callbacks_on_callback # Jython allows types to be weakref'd that CPython doesn't del MappingTestCase.test_weak_keyed_bad_delitem # CPython GC specific del MappingTestCase.test_weak_keyed_cascading_deletes test_support.run_unittest( ReferencesTestCase, MappingTestCase, WeakValueDictionaryTestCase, WeakKeyDictionaryTestCase, ) test_support.run_doctest(sys.modules[__name__])
Example #22
Source File: string_tests.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_expandtabs(self): self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs') self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8) self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 4) self.checkequal('abc\r\nab def\ng hi', 'abc\r\nab\tdef\ng\thi', 'expandtabs', 4) self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs') self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8) self.checkequal('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi', 'expandtabs', 4) self.checkequal(' a\n b', ' \ta\n\tb', 'expandtabs', 1) self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42) # This test is only valid when sizeof(int) == sizeof(void*) == 4. # Jython uses a different algorithm for which overflows cannot occur; # but memory exhaustion of course can. So not applicable. if (sys.maxint < (1 << 32) and not test_support.is_jython and struct.calcsize('P') == 4): self.checkraises(OverflowError, '\ta\n\tb', 'expandtabs', sys.maxint)
Example #23
Source File: test_cpickle.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_main(): tests = [ cPickleTests, cPicklePicklerTests, cPickleListPicklerTests, cPickleFastPicklerTests ] if test_support.is_jython: # XXX: Jython doesn't support list based picklers tests.remove(cPickleListPicklerTests) # XXX: These don't cause exceptions on Jython del cPickleFastPicklerTests.test_recursive_list del cPickleFastPicklerTests.test_recursive_inst del cPickleFastPicklerTests.test_recursive_dict del cPickleFastPicklerTests.test_recursive_multi test_support.run_unittest(*tests)
Example #24
Source File: test_inspect.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_excluding_predicates(self): #XXX: Jython's PySystemState needs more work before this #will be doable. if not test_support.is_jython: self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.isclass, 'mod.StupidGit') self.istest(inspect.iscode, 'mod.spam.func_code') self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.ismethod, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') self.istest(inspect.ismodule, 'mod') self.istest(inspect.istraceback, 'tb') self.istest(inspect.isdatadescriptor, '__builtin__.file.closed') self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace') if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') #XXX: This detail of PyFrames is not yet supported in Jython elif not test_support.is_jython: self.failIf(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) if hasattr(types, 'MemberDescriptorType'): self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') else: self.failIf(inspect.ismemberdescriptor(datetime.timedelta.days))
Example #25
Source File: test_array.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_overflow(self): a = array.array(self.typecode) lower = 0 itemsize = a.itemsize if test_support.is_jython: # unsigned itemsizes are larger than would be expected # in CPython because Jython promotes to the next size # (Java has no unsiged integers except for char) upper = long(pow(2, a.itemsize * 8 - 1)) - 1L else: upper = long(pow(2, a.itemsize * 8)) - 1L self.check_overflow(lower, upper)
Example #26
Source File: test_inspect.py From medicare-demo with Apache License 2.0 | 5 votes |
def na_for_jython(fn): if is_jython: def do_nothing(*args, **kw): pass return do_nothing else: return fn
Example #27
Source File: test_operator.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_concat(self): self.failUnlessRaises(TypeError, operator.concat) self.failUnlessRaises(TypeError, operator.concat, None, None) self.failUnless(operator.concat('py', 'thon') == 'python') self.failUnless(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4]) self.failUnless(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7]) self.failUnless(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7]) if not test_support.is_jython: # Jython concat is add self.failUnlessRaises(TypeError, operator.concat, 13, 29)
Example #28
Source File: test_operator.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_repeat(self): a = range(3) self.failUnlessRaises(TypeError, operator.repeat) self.failUnlessRaises(TypeError, operator.repeat, a, None) self.failUnless(operator.repeat(a, 2) == a+a) self.failUnless(operator.repeat(a, 1) == a) self.failUnless(operator.repeat(a, 0) == []) a = (1, 2, 3) self.failUnless(operator.repeat(a, 2) == a+a) self.failUnless(operator.repeat(a, 1) == a) self.failUnless(operator.repeat(a, 0) == ()) a = '123' self.failUnless(operator.repeat(a, 2) == a+a) self.failUnless(operator.repeat(a, 1) == a) self.failUnless(operator.repeat(a, 0) == '') a = Seq1([4, 5, 6]) self.failUnless(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6]) self.failUnless(operator.repeat(a, 1) == [4, 5, 6]) self.failUnless(operator.repeat(a, 0) == []) a = Seq2([4, 5, 6]) self.failUnless(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6]) self.failUnless(operator.repeat(a, 1) == [4, 5, 6]) self.failUnless(operator.repeat(a, 0) == []) if not test_support.is_jython: # Jython repeat is mul self.failUnlessRaises(TypeError, operator.repeat, 6, 7)
Example #29
Source File: test_trace.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def setUp(self): self.using_gc = gc.isenabled() if not test_support.is_jython: gc.disable()
Example #30
Source File: test_optparse.py From medicare-demo with Apache License 2.0 | 5 votes |
def suite(): if test_support.is_jython: # XXX: CPython ref count specific test del TestOptionParser.test_refleak suite = unittest.TestSuite() for testclass in _testclasses(): suite.addTest(unittest.makeSuite(testclass)) return suite