[py-svn] r7910 - in py/dist/py: . code execnet
hpk at codespeak.net
hpk at codespeak.net
Fri Dec 17 20:24:32 CET 2004
Author: hpk
Date: Fri Dec 17 20:24:32 2004
New Revision: 7910
Added:
py/dist/py/code/source.py (props changed)
- copied unchanged from r7904, py/dist/py/execnet/source.py
py/dist/py/code/test_source.py (contents, props changed)
- copied, changed from r7904, py/dist/py/execnet/test_source.py
Removed:
py/dist/py/execnet/source.py
py/dist/py/execnet/test_source.py
Modified:
py/dist/py/__init__.py
py/dist/py/code/ (props changed)
py/dist/py/code/__init__.py (props changed)
py/dist/py/execnet/gateway.py
py/dist/py/execnet/test_gateway.py
Log:
moved the Source class to py.code.Source along
with its test
Modified: py/dist/py/__init__.py
==============================================================================
--- py/dist/py/__init__.py (original)
+++ py/dist/py/__init__.py Fri Dec 17 20:24:32 2004
@@ -45,6 +45,7 @@
'magic.autopath' : ('./magic/autopath.py', 'autopath'),
'magic.View' : ('./magic/viewtype.py', 'View'),
'magic.AssertionError' : ('./magic/assertion.py', 'AssertionError'),
+ 'code.Source' : ('./code/source.py', 'Source'),
'execnet.SocketGateway' : ('./execnet/register.py', 'SocketGateway'),
'execnet.PopenGateway' : ('./execnet/register.py', 'PopenGateway'),
})
Copied: py/dist/py/code/test_source.py (from r7904, py/dist/py/execnet/test_source.py)
==============================================================================
--- py/dist/py/execnet/test_source.py (original)
+++ py/dist/py/code/test_source.py Fri Dec 17 20:24:32 2004
@@ -1,5 +1,5 @@
-from py.__impl__.execnet.source import Source
+from py.code import Source
def test_source_str_function():
x = Source("3")
Modified: py/dist/py/execnet/gateway.py
==============================================================================
--- py/dist/py/execnet/gateway.py (original)
+++ py/dist/py/execnet/gateway.py Fri Dec 17 20:24:32 2004
@@ -8,7 +8,7 @@
# XXX the following line should not be here
g = globals()
if 'Source' not in g:
- from py.__impl__.execnet.source import Source
+ from py.code import Source
from py.__impl__.execnet.channel import ChannelFactory, Channel
from py.__impl__.execnet.message import Message
Deleted: /py/dist/py/execnet/source.py
==============================================================================
--- /py/dist/py/execnet/source.py Fri Dec 17 20:24:32 2004
+++ (empty file)
@@ -1,57 +0,0 @@
-
-class Source(object):
- """ a mutable object holding a source code fragment,
- automatically deindenting it.
- """
- def __init__(self, *parts):
- self.lines = lines = []
- for part in parts:
- if isinstance(part, Source):
- lines.extend(part.lines)
- else:
- i = part.find('\n')
- if i != -1 and part[:i].isspace():
- part = part[i+1:]
- part = part.rstrip()
- lines.extend(deindent(part))
-
- def putaround(self, before='', after=''):
- """ return a new source object embedded/indented between before and after. """
- before = Source(before)
- after = Source(after)
- lines = [' ' + line for line in self.lines]
- self.lines = before.lines + lines + after.lines
-
- def __str__(self):
- return "\n".join(self.lines)
-
-def deindent(pysource):
- """ return a list of deindented lines from the given python
- source code. The first indentation offset of a non-blank
- line determines the deindentation-offset for all the lines.
- Subsequent lines which have a lower indentation size will
- be copied verbatim as they are assumed to be part of
- multilines.
- """
- lines = []
- indentsize = 0
- for line in pysource.split('\n'):
- if not lines:
- if not line.strip():
- continue # skip first empty lines
- indentsize = len(line) - len(line.lstrip())
- line = line.expandtabs()
- if line.strip():
- if len(line) - len(line.lstrip()) >= indentsize:
- line = line[indentsize:]
- lines.append(line)
-
- # treat trailing whitespace-containing lines correctly
- # (the python parser at least in python 2.2. is picky about it)
- #while lines:
- # line = lines.pop()
- # if not line.strip():
- # continue
- # lines.append(line)
- # break
- return lines
Modified: py/dist/py/execnet/test_gateway.py
==============================================================================
--- py/dist/py/execnet/test_gateway.py (original)
+++ py/dist/py/execnet/test_gateway.py Fri Dec 17 20:24:32 2004
@@ -1,6 +1,5 @@
import os, sys
import py
-from py.__impl__.execnet.source import Source
from py.__impl__.execnet import gateway
mypath = py.magic.autopath()
@@ -139,7 +138,7 @@
def setup_class(cls):
portrange = (7770, 7800)
cls.proxygw = py.execnet.PopenGateway()
- socketserverbootstrap = Source(
+ socketserverbootstrap = py.code.Source(
mypath.dirpath('bin', 'startserver.py').read(),
"""
import socket
Deleted: /py/dist/py/execnet/test_source.py
==============================================================================
--- /py/dist/py/execnet/test_source.py Fri Dec 17 20:24:32 2004
+++ (empty file)
@@ -1,40 +0,0 @@
-
-from py.__impl__.execnet.source import Source
-
-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) == "3"
-
-def test_source_indent_simple():
- source = Source("raise ValueError")
- source.putaround(
- "try:",
- """
- except ValueError:
- x = 42
- else:
- x = 23""")
- assert str(source)=="""\
-try:
- raise ValueError
-except ValueError:
- x = 42
-else:
- x = 23"""
-
-def XXXtest_source_indent_simple():
- x = StrSource("x=3")
- assert not x.isindented()
- x.indent("try:", "except: pass")
- assert x.read() == "try:\n x=3\nexcept: pass"
-
- #x.indent("try:",
- # """except:
More information about the pytest-commit
mailing list