Python test.test_support.check_py3k_warnings() Examples

The following are 30 code examples of test.test_support.check_py3k_warnings(). 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: test_getargs2.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_w_star(self):
        # getargs_w_star() modifies first and last byte
        from _testcapi import getargs_w_star
        self.assertRaises(TypeError, getargs_w_star, 'abc')
        self.assertRaises(TypeError, getargs_w_star, u'abc')
        self.assertRaises(TypeError, getargs_w_star, memoryview('bytes'))
        buf = bytearray('bytearray')
        self.assertEqual(getargs_w_star(buf), '[ytearra]')
        self.assertEqual(buf, bytearray('[ytearra]'))
        buf = bytearray(b'memoryview')
        self.assertEqual(getargs_w_star(memoryview(buf)), '[emoryvie]')
        self.assertEqual(buf, bytearray('[emoryvie]'))
        with test_support.check_py3k_warnings():
            self.assertRaises(TypeError, getargs_w_star, buffer('buffer'))
            self.assertRaises(TypeError, getargs_w_star,
                              buffer(bytearray('buffer')))
        self.assertRaises(TypeError, getargs_w_star, None) 
Example #2
Source File: test_file2k.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def testAttributes(self):
        # verify expected attributes exist
        f = self.f
        with test_support.check_py3k_warnings():
            softspace = f.softspace
        f.name     # merely shouldn't blow up
        f.mode     # ditto
        f.closed   # ditto

        with test_support.check_py3k_warnings():
            # verify softspace is writable
            f.softspace = softspace    # merely shouldn't blow up

        # verify the others aren't
        for attr in 'name', 'mode', 'closed':
            self.assertRaises((AttributeError, TypeError), setattr, f, attr, 'oops') 
Example #3
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_builtin_function_or_method_comparisons(self):
        expected = ('builtin_function_or_method '
                    'order comparisons not supported in 3.x')
        func = eval
        meth = {}.get
        with check_py3k_warnings() as w:
            self.assertWarning(func < meth, w, expected)
            w.reset()
            self.assertWarning(func > meth, w, expected)
            w.reset()
            self.assertWarning(meth <= func, w, expected)
            w.reset()
            self.assertWarning(meth >= func, w, expected)
            w.reset()
            self.assertNoWarning(meth == func, w)
            self.assertNoWarning(meth != func, w)
            lam = lambda x: x
            self.assertNoWarning(lam == func, w)
            self.assertNoWarning(lam != func, w) 
Example #4
Source File: userfunctions.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        self.con = sqlite.connect(":memory:")
        cur = self.con.cursor()
        cur.execute("""
            create table test(
                t text,
                i integer,
                f float,
                n,
                b blob
                )
            """)
        with test_support.check_py3k_warnings():
            cur.execute("insert into test(t, i, f, n, b) values (?, ?, ?, ?, ?)",
                ("foo", 5, 3.14, None, buffer("blob"),))

        self.con.create_aggregate("nostep", 1, AggrNoStep)
        self.con.create_aggregate("nofinalize", 1, AggrNoFinalize)
        self.con.create_aggregate("excInit", 1, AggrExceptionInInit)
        self.con.create_aggregate("excStep", 1, AggrExceptionInStep)
        self.con.create_aggregate("excFinalize", 1, AggrExceptionInFinalize)
        self.con.create_aggregate("checkType", 2, AggrCheckType)
        self.con.create_aggregate("mysum", 1, AggrSum) 
Example #5
Source File: test_cfgparser.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_issue_12717(self):
        d1 = dict(red=1, green=2)
        d2 = dict(green=3, blue=4)
        dcomb = d2.copy()
        dcomb.update(d1)
        cm = ConfigParser._Chainmap(d1, d2)
        self.assertIsInstance(cm.keys(), list)
        self.assertEqual(set(cm.keys()), set(dcomb.keys()))      # keys()
        self.assertEqual(set(cm.values()), set(dcomb.values()))  # values()
        self.assertEqual(set(cm.items()), set(dcomb.items()))    # items()
        self.assertEqual(set(cm), set(dcomb))                    # __iter__ ()
        self.assertEqual(cm, dcomb)                              # __eq__()
        self.assertEqual([cm[k] for k in dcomb], dcomb.values()) # __getitem__()
        klist = 'red green blue black brown'.split()
        self.assertEqual([cm.get(k, 10) for k in klist],
                         [dcomb.get(k, 10) for k in klist])      # get()
        self.assertEqual([k in cm for k in klist],
                         [k in dcomb for k in klist])            # __contains__()
        with test_support.check_py3k_warnings():
            self.assertEqual([cm.has_key(k) for k in klist],
                             [dcomb.has_key(k) for k in klist])  # has_key() 
Example #6
Source File: test_peepholer.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_main(verbose=None):
    import sys
    from test import test_support
    test_classes = (TestTranforms,)

    with test_support.check_py3k_warnings(
            ("backquote not supported", SyntaxWarning)):
        test_support.run_unittest(*test_classes)

        # verify reference counting
        if verbose and hasattr(sys, "gettotalrefcount"):
            import gc
            counts = [None] * 5
            for i in xrange(len(counts)):
                test_support.run_unittest(*test_classes)
                gc.collect()
                counts[i] = sys.gettotalrefcount()
            print counts 
Example #7
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_slice_methods(self):
        class Spam(object):
            def __getslice__(self, i, j): pass
            def __setslice__(self, i, j, what): pass
            def __delslice__(self, i, j): pass
        class Egg:
            def __getslice__(self, i, h): pass
            def __setslice__(self, i, j, what): pass
            def __delslice__(self, i, j): pass

        expected = "in 3.x, __{0}slice__ has been removed; use __{0}item__"

        for obj in (Spam(), Egg()):
            with check_py3k_warnings() as w:
                self.assertWarning(obj[1:2], w, expected.format('get'))
                w.reset()
                del obj[3:4]
                self.assertWarning(None, w, expected.format('del'))
                w.reset()
                obj[4:5] = "eggs"
                self.assertWarning(None, w, expected.format('set')) 
Example #8
Source File: test_getargs2.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_es(self):
        from _testcapi import getargs_es
        self.assertEqual(getargs_es('abc'), 'abc')
        self.assertEqual(getargs_es(u'abc'), 'abc')
        self.assertEqual(getargs_es('abc', 'ascii'), 'abc')
        self.assertEqual(getargs_es(u'abc\xe9', 'latin1'), 'abc\xe9')
        self.assertRaises(UnicodeEncodeError, getargs_es, u'abc\xe9', 'ascii')
        self.assertRaises(LookupError, getargs_es, u'abc', 'spam')
        self.assertRaises(TypeError, getargs_es,
                          bytearray('bytearray'), 'latin1')
        self.assertRaises(TypeError, getargs_es,
                          memoryview('memoryview'), 'latin1')
        with test_support.check_py3k_warnings():
            self.assertEqual(getargs_es(buffer('abc'), 'ascii'), 'abc')
            self.assertEqual(getargs_es(buffer(u'abc'), 'ascii'), 'abc')
        self.assertRaises(TypeError, getargs_es, None, 'latin1')
        self.assertRaises(TypeError, getargs_es, 'nul:\0', 'latin1')
        self.assertRaises(TypeError, getargs_es, u'nul:\0', 'latin1') 
Example #9
Source File: test_getargs2.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_u(self):
        from _testcapi import getargs_u
        self.assertEqual(getargs_u(u'abc\xe9'), u'abc\xe9')
        self.assertRaises(TypeError, getargs_u, u'nul:\0')
        self.assertRaises(TypeError, getargs_u, 'bytes')
        self.assertRaises(TypeError, getargs_u, bytearray('bytearray'))
        self.assertRaises(TypeError, getargs_u, memoryview('memoryview'))
        with test_support.check_py3k_warnings():
            self.assertRaises(TypeError, getargs_u, buffer('buffer'))
        self.assertRaises(TypeError, getargs_u, None) 
Example #10
Source File: list_tests.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_sort(self):
        with test_support.check_py3k_warnings(
                ("the cmp argument is not supported", DeprecationWarning)):
            self._test_sort() 
Example #11
Source File: test_dict.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_main():
    with test_support.check_py3k_warnings(
        ('dict(.has_key..| inequality comparisons) not supported in 3.x',
         DeprecationWarning)):
        test_support.run_unittest(
            DictTest,
            GeneralMappingTests,
            SubclassMappingTests,
        ) 
Example #12
Source File: test_slice.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_setslice_without_getslice(self):
        tmp = []
        class X(object):
            def __setslice__(self, i, j, k):
                tmp.append((i, j, k))

        x = X()
        with test_support.check_py3k_warnings():
            x[1:2] = 42
        self.assertEqual(tmp, [(1, 2, 42)]) 
Example #13
Source File: test_getargs2.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_et_hash(self):
        from _testcapi import getargs_et_hash
        self.assertEqual(getargs_et_hash('abc\xe9'), 'abc\xe9')
        self.assertEqual(getargs_et_hash(u'abc'), 'abc')
        self.assertEqual(getargs_et_hash('abc\xe9', 'ascii'), 'abc\xe9')
        self.assertEqual(getargs_et_hash(u'abc\xe9', 'latin1'), 'abc\xe9')
        self.assertRaises(UnicodeEncodeError, getargs_et_hash,
                          u'abc\xe9', 'ascii')
        self.assertRaises(LookupError, getargs_et_hash, u'abc', 'spam')
        self.assertRaises(TypeError, getargs_et_hash,
                          bytearray('bytearray'), 'latin1')
        self.assertRaises(TypeError, getargs_et_hash,
                          memoryview('memoryview'), 'latin1')
        with test_support.check_py3k_warnings():
            self.assertEqual(getargs_et_hash(buffer('abc'), 'ascii'), 'abc')
            self.assertEqual(getargs_et_hash(buffer(u'abc'), 'ascii'), 'abc')
        self.assertRaises(TypeError, getargs_et_hash, None, 'latin1')
        self.assertEqual(getargs_et_hash('nul:\0', 'latin1'), 'nul:\0')
        self.assertEqual(getargs_et_hash(u'nul:\0', 'latin1'), 'nul:\0')

        buf = bytearray('x'*8)
        self.assertEqual(getargs_et_hash(u'abc\xe9', 'latin1', buf), 'abc\xe9')
        self.assertEqual(buf, bytearray('abc\xe9\x00xxx'))
        buf = bytearray('x'*5)
        self.assertEqual(getargs_et_hash(u'abc\xe9', 'latin1', buf), 'abc\xe9')
        self.assertEqual(buf, bytearray('abc\xe9\x00'))
        buf = bytearray('x'*4)
        self.assertRaises(TypeError, getargs_et_hash, u'abc\xe9', 'latin1', buf)
        self.assertEqual(buf, bytearray('x'*4))
        buf = bytearray()
        self.assertRaises(TypeError, getargs_et_hash, u'abc\xe9', 'latin1', buf) 
Example #14
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_operator(self):
        from operator import isCallable, sequenceIncludes

        callable_warn = ("operator.isCallable() is not supported in 3.x. "
                         "Use hasattr(obj, '__call__').")
        seq_warn = ("operator.sequenceIncludes() is not supported "
                    "in 3.x. Use operator.contains().")
        with check_py3k_warnings() as w:
            self.assertWarning(isCallable(self), w, callable_warn)
            w.reset()
            self.assertWarning(sequenceIncludes(range(3), 2), w, seq_warn) 
Example #15
Source File: test_getargs2.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_u_hash(self):
        from _testcapi import getargs_u_hash
        self.assertEqual(getargs_u_hash(u'abc\xe9'), u'abc\xe9')
        self.assertEqual(getargs_u_hash(u'nul:\0'), u'nul:\0')
        self.assertRaises(TypeError, getargs_u_hash, 'bytes')
        self.assertRaises(TypeError, getargs_u_hash, bytearray('bytearray'))
        self.assertRaises(TypeError, getargs_u_hash, memoryview('memoryview'))
        with test_support.check_py3k_warnings():
            self.assertRaises(TypeError, getargs_u_hash, buffer('buffer'))
        self.assertRaises(TypeError, getargs_u_hash, None) 
Example #16
Source File: test_weakref.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_basic_proxy(self):
        o = C()
        self.check_proxy(o, weakref.proxy(o))

        L = UserList.UserList()
        p = weakref.proxy(L)
        self.assertFalse(p, "proxy for empty UserList should be false")
        p.append(12)
        self.assertEqual(len(L), 1)
        self.assertTrue(p, "proxy for non-empty UserList should be true")
        with test_support.check_py3k_warnings():
            p[:] = [2, 3]
        self.assertEqual(len(L), 2)
        self.assertEqual(len(p), 2)
        self.assertIn(3, p, "proxy didn't support __contains__() properly")
        p[1] = 5
        self.assertEqual(L[1], 5)
        self.assertEqual(p[1], 5)
        L2 = UserList.UserList(L)
        p2 = weakref.proxy(L2)
        self.assertEqual(p, p2)
        ## self.assertEqual(repr(L2), repr(p2))
        L3 = UserList.UserList(range(10))
        p3 = weakref.proxy(L3)
        with test_support.check_py3k_warnings():
            self.assertEqual(L3[:], p3[:])
            self.assertEqual(L3[5:], p3[5:])
            self.assertEqual(L3[:5], p3[:5])
            self.assertEqual(L3[2:5], p3[2:5]) 
Example #17
Source File: test_fileio.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testWriteUnicode(self):
        with check_py3k_warnings():
            self.f.write(u'') 
Example #18
Source File: test_operator.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_isCallable(self):
        self.assertRaises(TypeError, operator.isCallable)
        class C:
            pass
        def check(self, o, v):
            with test_support.check_py3k_warnings():
                self.assertEqual(operator.isCallable(o), v)
                self.assertEqual(callable(o), v)
        check(self, 4, 0)
        check(self, operator.isCallable, 1)
        check(self, C, 1)
        check(self, C(), 0) 
Example #19
Source File: test_xml_etree.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_constructor_args(self):
        # Positional args. The first (html) is not supported, but should be
        # nevertheless correctly accepted.
        with support.check_py3k_warnings((r'.*\bhtml\b', DeprecationWarning)):
            parser = ET.XMLParser(None, ET.TreeBuilder(), 'utf-8')
        parser.feed(self.sample1)
        self._check_sample_element(parser.close())

        # Now as keyword args.
        parser2 = ET.XMLParser(encoding='utf-8',
                               target=ET.TreeBuilder())
        parser2.feed(self.sample1)
        self._check_sample_element(parser2.close()) 
Example #20
Source File: test_StringIO.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_main():
    test_support.run_unittest(TestStringIO, TestcStringIO)
    with test_support.check_py3k_warnings(("buffer.. not supported",
                                             DeprecationWarning)):
        test_support.run_unittest(TestBufferStringIO, TestBuffercStringIO)
    test_support.run_unittest(TestMemoryviewcStringIO) 
Example #21
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_nonascii_bytes_literals(self):
        expected = "non-ascii bytes literals not supported in 3.x"
        with check_py3k_warnings((expected, SyntaxWarning)):
            exec "b'\xbd'" 
Example #22
Source File: test_getargs2.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_w_hash(self):
        from _testcapi import getargs_w_hash
        self.assertRaises(TypeError, getargs_w_hash, 'abc')
        self.assertRaises(TypeError, getargs_w_hash, u'abc')
        self.assertRaises(TypeError, getargs_w_hash, bytearray('bytes'))
        self.assertRaises(TypeError, getargs_w_hash, memoryview('bytes'))
        self.assertRaises(TypeError, getargs_w_hash,
                          memoryview(bytearray('bytes')))
        with test_support.check_py3k_warnings():
            self.assertRaises(TypeError, getargs_w_hash, buffer('bytes'))
            self.assertRaises(TypeError, getargs_w_hash,
                              buffer(bytearray('bytes')))
        self.assertRaises(TypeError, getargs_w_hash, None) 
Example #23
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_file_xreadlines(self):
        expected = ("f.xreadlines() not supported in 3.x, "
                    "try 'for line in f' instead")
        with file(__file__) as f:
            with check_py3k_warnings() as w:
                self.assertWarning(f.xreadlines(), w, expected) 
Example #24
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_buffer(self):
        expected = 'buffer() not supported in 3.x'
        with check_py3k_warnings() as w:
            self.assertWarning(buffer('a'), w, expected) 
Example #25
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_softspace(self):
        expected = 'file.softspace not supported in 3.x'
        with file(__file__) as f:
            with check_py3k_warnings() as w:
                self.assertWarning(f.softspace, w, expected)
            def set():
                f.softspace = 0
            with check_py3k_warnings() as w:
                self.assertWarning(set(), w, expected) 
Example #26
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_methods_members(self):
        expected = '__members__ and __methods__ not supported in 3.x'
        class C:
            __methods__ = ['a']
            __members__ = ['b']
        c = C()
        with check_py3k_warnings() as w:
            self.assertWarning(dir(c), w, expected) 
Example #27
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_sys_exc_clear(self):
        expected = 'sys.exc_clear() not supported in 3.x; use except clauses'
        with check_py3k_warnings() as w:
            self.assertWarning(sys.exc_clear(), w, expected) 
Example #28
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_sort_cmp_arg(self):
        expected = "the cmp argument is not supported in 3.x"
        lst = range(5)
        cmp = lambda x,y: -1

        with check_py3k_warnings() as w:
            self.assertWarning(lst.sort(cmp=cmp), w, expected)
            w.reset()
            self.assertWarning(sorted(lst, cmp=cmp), w, expected)
            w.reset()
            self.assertWarning(lst.sort(cmp), w, expected)
            w.reset()
            self.assertWarning(sorted(lst, cmp), w, expected) 
Example #29
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_code_inequality_comparisons(self):
        expected = 'code inequality comparisons not supported in 3.x'
        def f(x):
            pass
        def g(x):
            pass
        with check_py3k_warnings() as w:
            self.assertWarning(f.func_code < g.func_code, w, expected)
            w.reset()
            self.assertWarning(f.func_code <= g.func_code, w, expected)
            w.reset()
            self.assertWarning(f.func_code >= g.func_code, w, expected)
            w.reset()
            self.assertWarning(f.func_code > g.func_code, w, expected) 
Example #30
Source File: test_py3kwarn.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_cell_inequality_comparisons(self):
        expected = 'cell comparisons not supported in 3.x'
        def f(x):
            def g():
                return x
            return g
        cell0, = f(0).func_closure
        cell1, = f(1).func_closure
        with check_py3k_warnings() as w:
            self.assertWarning(cell0 == cell1, w, expected)
            w.reset()
            self.assertWarning(cell0 < cell1, w, expected)