[py-svn] r37494 - in py/trunk/py/test: . testing
hpk at codespeak.net
hpk at codespeak.net
Sun Jan 28 18:53:46 CET 2007
Author: hpk
Date: Sun Jan 28 18:53:43 2007
New Revision: 37494
Added:
py/trunk/py/test/host.py
py/trunk/py/test/testing/test_host.py
Log:
the start of factoring out common and unified
host handling within py.test
Added: py/trunk/py/test/host.py
==============================================================================
--- (empty file)
+++ py/trunk/py/test/host.py Sun Jan 28 18:53:43 2007
@@ -0,0 +1,37 @@
+
+class InvalidHostSpec(ValueError):
+ pass
+
+def parsehostspec(spec):
+ parts = spec.split(":", 2)
+ if len(parts) < 2:
+ raise InvalidHostSpec(spec)
+ type = parts.pop(0)
+ if type == 'ssh':
+ sshaddress = parts.pop(0)
+ basedir = parts and ":".join(parts) or ''
+ return SpecSSH(sshaddress, basedir)
+ elif type == 'socket':
+ host = parts.pop(0)
+ if not parts:
+ raise InvalidHostSpec(spec)
+ remainder = parts.pop(0)
+ parts = remainder.split(":", 1)
+ port = int(parts.pop(0))
+ basedir = parts and ":".join(parts) or ''
+ return SpecSocket(host, port, basedir)
+ else:
+ raise InvalidHostSpec(spec)
+
+class SpecSSH(object):
+ def __init__(self, sshaddress, basedir):
+ self.sshaddress = sshaddress
+ self.basedir = basedir
+ self.host = sshaddress.split('@', 1)[-1]
+
+class SpecSocket(object):
+ def __init__(self, host, port, basedir):
+ self.host = host
+ self.port = port
+ self.basedir = basedir
+
Added: py/trunk/py/test/testing/test_host.py
==============================================================================
--- (empty file)
+++ py/trunk/py/test/testing/test_host.py Sun Jan 28 18:53:43 2007
@@ -0,0 +1,56 @@
+"""
+
+Testing Host setup and rsyncing operations.
+
+"""
+
+import py
+from py.__.test.host import parsehostspec
+
+def test_parse_hostspec_ssh():
+ hostspec = parsehostspec("ssh:xyz at domain.net:directory")
+ assert hostspec.host == "domain.net"
+ assert hostspec.basedir == "directory"
+ assert hostspec.sshaddress == "xyz at domain.net"
+
+ hostspec = parsehostspec("ssh:xyz at domain.net:direc:tory")
+ assert hostspec.host == "domain.net"
+ assert hostspec.basedir == "direc:tory"
+ assert hostspec.sshaddress == "xyz at domain.net"
+
+ hostspec = parsehostspec("ssh:xyz at domain.net")
+ assert hostspec.host == "domain.net"
+ assert hostspec.basedir == ""
+ assert hostspec.sshaddress == "xyz at domain.net"
+
+ hostspec = parsehostspec("ssh:domain.net:directory")
+ assert hostspec.host == "domain.net"
+ assert hostspec.basedir == "directory"
+ assert hostspec.sshaddress == "domain.net"
+
+ hostspec = parsehostspec("ssh:domain.net:/tmp/hello")
+ assert hostspec.host == "domain.net"
+ assert hostspec.basedir == "/tmp/hello"
+ assert hostspec.sshaddress == "domain.net"
+
+def test_parse_hostspec_socket():
+ hostspec = parsehostspec("socket:domain.net:1234:directory")
+ assert hostspec.host == "domain.net"
+ assert hostspec.port == 1234
+ assert hostspec.basedir == "directory"
+
+ hostspec = parsehostspec("socket:domain.net:1234")
+ assert hostspec.host == "domain.net"
+ assert hostspec.port == 1234
+ assert hostspec.basedir == ""
+
+def test_parse_hostspec_error():
+ py.test.raises(ValueError, """
+ parsehostspec('alksd:qweqwe')
+ """)
+ py.test.raises(ValueError, """
+ parsehostspec('ssh')
+ """)
+ py.test.raises(ValueError, """
+ parsehostspec('socket:qweqwe')
+ """)
More information about the pytest-commit
mailing list