[py-svn] r7929 - in py/dist/py/code: . testing

hpk at codespeak.net hpk at codespeak.net
Sun Dec 19 16:40:00 CET 2004


Author: hpk
Date: Sun Dec 19 16:39:59 2004
New Revision: 7929

Added:
   py/dist/py/code/testing/
   py/dist/py/code/testing/test_cpython_features.py
      - copied unchanged from r7926, py/dist/py/code/test_cpython_features.py
   py/dist/py/code/testing/test_excinfo.py
      - copied unchanged from r7927, py/dist/py/code/test_excinfo.py
   py/dist/py/code/testing/test_frame.py
      - copied unchanged from r7927, py/dist/py/code/test_frame.py
   py/dist/py/code/testing/test_source.py
      - copied unchanged from r7928, py/dist/py/code/test_source.py
Removed:
   py/dist/py/code/test_cpython_features.py
   py/dist/py/code/test_excinfo.py
   py/dist/py/code/test_frame.py
   py/dist/py/code/test_source.py
Log:
move tests into their own directory ... 
(i think it's worth considering doing this 
always in the py lib to not clutter up the 
implementation so much, but i am not completly 
sure yet, comments welcome) 



Deleted: /py/dist/py/code/test_cpython_features.py
==============================================================================
--- /py/dist/py/code/test_cpython_features.py	Sun Dec 19 16:39:59 2004
+++ (empty file)
@@ -1,16 +0,0 @@
-
-import new 
-
-def test_new_code_object_carries_filename_through(): 
-    class mystr(str): 
-        pass 
-    filename = mystr("dummy")
-    co = compile("hello\n", filename, 'exec')
-    assert not isinstance(co.co_filename, mystr) 
-    c2 = new.code(co.co_argcount, co.co_nlocals, co.co_stacksize, 
-             co.co_flags, co.co_code, co.co_consts, 
-             co.co_names, co.co_varnames, 
-             filename, 
-             co.co_name, co.co_firstlineno, co.co_lnotab, 
-             co.co_freevars, co.co_cellvars)
-    assert c2.co_filename is filename 

Deleted: /py/dist/py/code/test_excinfo.py
==============================================================================
--- /py/dist/py/code/test_excinfo.py	Sun Dec 19 16:39:59 2004
+++ (empty file)
@@ -1,29 +0,0 @@
-import py 
-mypath = py.magic.autopath() 
-
-def test_excinfo_simple(): 
-    try: 
-        raise ValueError
-    except ValueError: 
-        info = py.code.ExceptionInfo()
-    assert info.type == ValueError 
-
-def test_excinfo_getstatement(): 
-    def g():
-        raise ValueError
-    def f(): 
-        g()
-    try: 
-        f()
-    except ValueError: 
-        info = py.code.ExceptionInfo() 
-    l = list(info) 
-    linenumbers = [f.func_code.co_firstlineno-1+3, 
-                   f.func_code.co_firstlineno-1+1, 
-                   g.func_code.co_firstlineno-1+1,]
-    foundlinenumbers = [x.lineno for x in info]
-    print l[0].frame.statement
-    assert foundlinenumbers == linenumbers  
-    #for x in info: 
-    #    print "%s:%d  %s" %(x.path.relto(root), x.lineno, x.statement)
-    #xxx

Deleted: /py/dist/py/code/test_frame.py
==============================================================================
--- /py/dist/py/code/test_frame.py	Sun Dec 19 16:39:59 2004
+++ (empty file)
@@ -1,10 +0,0 @@
-import sys
-from py.code import RunnerFrame 
-
-def test_frame_getsourcelineno_myself(): 
-    def func(): 
-        return sys._getframe(0) 
-    f = func() 
-    f = RunnerFrame(f) 
-    source, lineno = f.code.fullsource, f.lineno 
-    assert source[lineno].startswith("        return sys._getframe(0)")

Deleted: /py/dist/py/code/test_source.py
==============================================================================
--- /py/dist/py/code/test_source.py	Sun Dec 19 16:39:59 2004
+++ (empty file)
@@ -1,156 +0,0 @@
-from py.code import Source 
-import py 
-
-def test_source_str_function():
-    x = Source("3")
-    assert str(x) == "3" 
-
-    x = Source("   3")
-    assert str(x) == "3" 
-
-    x = Source("""
-        3
-    """) 
-    assert str(x) == "\n3\n    " 
-
-def test_source_indent_simple():
-    source = Source("raise ValueError")
-    source = source.putaround(
-        "try:", """\
-        except ValueError:
-            x = 42
-        else:
-            x = 23""")
-    assert str(source)=="""\
-try:
-    raise ValueError
-except ValueError:
-    x = 42
-else:
-    x = 23"""
-
-def checkparseable(source): 
-    assert source.isparseable()
-
-def test_isparseable(): 
-    assert Source("hello").isparseable()
-    assert Source("if 1:\n  pass").isparseable()
-    assert Source(" \nif 1:\n  pass").isparseable()
-    assert not Source(" \nif 1:\npass").isparseable()
-
-class TestSliceAccess: 
-    source = Source("""\
-        def f(x):
-            pass
-        def g(x):
-            pass
-    """)
-    def test_getrange(self): 
-        x = self.source[0:2]
-        assert x.isparseable() 
-        assert len(x.lines) == 2
-        assert str(x) == "def f(x):\n    pass" 
-
-    def test_getline(self): 
-        x = self.source[0]
-        assert x == "def f(x):" 
-
-class TestCodeHacks: 
-    def test_newcode(self): 
-        from py.__impl__.code.source import newcode 
-        def f(): 
-            pass
-        co_filename = 'hello'
-        c = newcode(f.func_code, co_filename=co_filename) 
-        assert c.co_filename is co_filename 
-
-    def test_newcode_withfilename(self): 
-        from py.__impl__.code.source import newcode_withfilename
-        source = py.code.Source("""
-            def f(): 
-                def g(): 
-                    pass
-        """)
-        co = compile(str(source)+'\n', 'nada', 'exec')
-        obj = 'hello'
-        newco = newcode_withfilename(co, obj) 
-        def walkcode(co): 
-            for x in co.co_consts: 
-                if isinstance(x, type(co)): 
-                    for y in walkcode(x): 
-                        yield y 
-            yield co 
-         
-        names = [] 
-        for code in walkcode(newco): 
-            assert newco.co_filename == obj 
-            assert newco.co_filename is obj 
-            names.append(code.co_name) 
-        assert 'f' in names 
-        assert 'g' in names 
-
-class TestSourceParsingAndCompiling: 
-    source = Source("""\
-        def f(x):
-            assert (x == 
-                    3 + 
-                    4)
-    """).strip()
-    def test_getstatement(self):
-        #print str(self.source)
-        ass = str(self.source[1:]) 
-        for i in range(1, 4): 
-            #print "trying start in line %r" % self.source[i]
-            s = self.source.getstatement(i) 
-            #x = s.deindent()
-            assert str(s) == ass 
-
-    def XXXtest_getstatement_within_constructs(self): 
-        source = Source("""\
-            try: 
-                raise ValueError 
-            finally: 
-                42
-        """) 
-        stmt = source.getstatement(1)
-        assert str(stmt).strip() == 'raise ValueError'
-        xxx
-        co = source.compile() 
-        try: 
-            exec co 
-        except ValueError: 
-            excinfo = py.code.ExceptionInfo(py.std.sys.exc_info()) 
-        l = list(excinfo) 
-        tb = l[0]
-        inner = l[1]
-        print "inner frame-statement:", inner.frame.statement 
-        print "inner frame-lineno:", inner.frame.lineno
-        print "inner tb-statement:", inner.statement 
-        print "inner tb-lineno:", inner.lineno
-        print "...", repr(inner.frame.code.fullsource[inner.lineno])
-
-        print "tb-statement:", tb.statement 
-        print "tb-lineno:", tb.lineno 
-        XXX
-
-    def test_compile_and_getsource(self): 
-        co = self.source.compile() 
-        exec co 
-        f(7)
-        excinfo = py.test.raises(AssertionError, "f(6)")
-        frame = excinfo[2].tb_next.tb_next.tb_frame
-        f = py.code.RunnerFrame(frame) 
-        stmt = f.code.fullsource.getstatement(f.lineno) 
-        #print "block", str(block)
-        assert str(stmt).strip().startswith('assert')
-
-def test_compile(): 
-    co = py.code.compile("x=3")
-    exec co 
-    assert x == 3 
-
-def test_compile_and_getsource(): 
-    co = py.code.compile("x=3")
-    exec co 
-    source = py.code.Source(co) 
-    assert str(source) == "x=3"



More information about the pytest-commit mailing list