SF.net SVN: fclient: [531] trunk/fcp2/src/test
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-07 07:15:48
|
Revision: 531
http://fclient.svn.sourceforge.net/fclient/?rev=531&view=rev
Author: jUrner
Date: 2008-07-07 00:15:56 -0700 (Mon, 07 Jul 2008)
Log Message:
-----------
test should work now directly from test dir
Modified Paths:
--------------
trunk/fcp2/src/test/dummy_io.py
trunk/fcp2/src/test/test_all.py
trunk/fcp2/src/test/test_client.py
trunk/fcp2/src/test/test_config.py
trunk/fcp2/src/test/test_iohandler.py
trunk/fcp2/src/test/test_key.py
trunk/fcp2/src/test/test_message.py
trunk/fcp2/src/test/test_types.py
Modified: trunk/fcp2/src/test/dummy_io.py
===================================================================
--- trunk/fcp2/src/test/dummy_io.py 2008-07-07 07:14:44 UTC (rev 530)
+++ trunk/fcp2/src/test/dummy_io.py 2008-07-07 07:15:56 UTC (rev 531)
@@ -2,24 +2,35 @@
import os, sys
-#--> rel import hack
-class _RelImportHack(object):
- def __init__(self, n):
- fpath = os.path.abspath(__file__)
- for i in xrange(n): fpath = os.path.dirname(fpath)
- sys.path.insert(0, fpath)
- def __del__(self): sys.path.pop(0)
-hack = _RelImportHack(3)
-import fcp2
-from fcp2 import iohandler
+def relimport(what):
+ import imp, os, sys
+ L = what.split('.')
+ if not L or L[0]:
+ raise ValueError('relative import must start with a dot')
+ name = os.path.abspath(__file__)
+ while L:
+ p = L.pop(0)
+ if p: name = os.path.join(name, p)
+ else:
+ name, _ = os.path.split(name)
+ if not _: break
+ if L: raise ValueError('root level exceeded')
+ mod = sys.modules.get(name, None)
+ if mod is None:
+ fpath, fname = os.path.split(name)
+ fp, fpath, suffixes = imp.find_module(fname, [fpath, ])
+ print fp, fpath, suffixes
+ try: mod = imp.load_module(name, fp, fpath, suffixes)
+ finally:
+ if fp is not None: fp.close()
+ return mod
-del hack
-#<-- rel import hack
+fcp2 = relimport('..fcp2')
#********************************************************************
#
#********************************************************************
-class DummyIO(iohandler.IOObjectBase):
+class DummyIO(fcp2.iohandler.IOObjectBase):
def __init__(self):
self.readBuffer = '' # buffer client reads from
Modified: trunk/fcp2/src/test/test_all.py
===================================================================
--- trunk/fcp2/src/test/test_all.py 2008-07-07 07:14:44 UTC (rev 530)
+++ trunk/fcp2/src/test/test_all.py 2008-07-07 07:15:56 UTC (rev 531)
@@ -17,11 +17,3 @@
suite = getattr(mod, 'suite')
unittest.TextTestRunner(verbosity=1).run(suite())
-
-
-
-
-
-
-
-
Modified: trunk/fcp2/src/test/test_client.py
===================================================================
--- trunk/fcp2/src/test/test_client.py 2008-07-07 07:14:44 UTC (rev 530)
+++ trunk/fcp2/src/test/test_client.py 2008-07-07 07:15:56 UTC (rev 531)
@@ -8,8 +8,32 @@
import time
import unittest
-import fcp2
-from dummy_io import DummyIO
+
+# hack relative imports to make in-place testing work
+def relimport(what):
+ import imp, os, sys
+ L = what.split('.')
+ if not L or L[0]:
+ raise ValueError('relative import must start with a dot')
+ name = os.path.abspath(__file__)
+ while L:
+ p = L.pop(0)
+ if p: name = os.path.join(name, p)
+ else:
+ name, _ = os.path.split(name)
+ if not _: break
+ if L: raise ValueError('root level exceeded')
+ mod = sys.modules.get(name, None)
+ if mod is None:
+ fpath, fname = os.path.split(name)
+ fp, fpath, suffixes = imp.find_module(fname, [fpath, ])
+ try: mod = imp.load_module(name, fp, fpath, suffixes)
+ finally:
+ if fp is not None: fp.close()
+ return mod
+
+fcp2 = relimport('..fcp2')
+dummy_io = relimport('.dummy_io')
#***********************************************************************************
#
#***********************************************************************************
@@ -29,7 +53,7 @@
debugVerbosity=fcp2.ConstDebugVerbosity.Quiet
)
- client.ioHandler.setIOPrototype(DummyIO)
+ client.ioHandler.setIOPrototype(dummy_io.DummyIO)
def __init__(self, *args, **kwargs):
Modified: trunk/fcp2/src/test/test_config.py
===================================================================
--- trunk/fcp2/src/test/test_config.py 2008-07-07 07:14:44 UTC (rev 530)
+++ trunk/fcp2/src/test/test_config.py 2008-07-07 07:15:56 UTC (rev 531)
@@ -4,7 +4,30 @@
import socket
import unittest
-import fcp2
+# hack relative imports to make in-place testing work
+def relimport(what):
+ import imp, os, sys
+ L = what.split('.')
+ if not L or L[0]:
+ raise ValueError('relative import must start with a dot')
+ name = os.path.abspath(__file__)
+ while L:
+ p = L.pop(0)
+ if p: name = os.path.join(name, p)
+ else:
+ name, _ = os.path.split(name)
+ if not _: break
+ if L: raise ValueError('root level exceeded')
+ mod = sys.modules.get(name, None)
+ if mod is None:
+ fpath, fname = os.path.split(name)
+ fp, fpath, suffixes = imp.find_module(fname, [fpath, ])
+ try: mod = imp.load_module(name, fp, fpath, suffixes)
+ finally:
+ if fp is not None: fp.close()
+ return mod
+
+fcp2 = relimport('..fcp2')
#****************************************************************************************
#
#****************************************************************************************
Modified: trunk/fcp2/src/test/test_iohandler.py
===================================================================
--- trunk/fcp2/src/test/test_iohandler.py 2008-07-07 07:14:44 UTC (rev 530)
+++ trunk/fcp2/src/test/test_iohandler.py 2008-07-07 07:15:56 UTC (rev 531)
@@ -4,8 +4,30 @@
import socket
import unittest
+# hack relative imports to make in-place testing work
+def relimport(what):
+ import imp, os, sys
+ L = what.split('.')
+ if not L or L[0]:
+ raise ValueError('relative import must start with a dot')
+ name = os.path.abspath(__file__)
+ while L:
+ p = L.pop(0)
+ if p: name = os.path.join(name, p)
+ else:
+ name, _ = os.path.split(name)
+ if not _: break
+ if L: raise ValueError('root level exceeded')
+ mod = sys.modules.get(name, None)
+ if mod is None:
+ fpath, fname = os.path.split(name)
+ fp, fpath, suffixes = imp.find_module(fname, [fpath, ])
+ try: mod = imp.load_module(name, fp, fpath, suffixes)
+ finally:
+ if fp is not None: fp.close()
+ return mod
-import fcp2
+fcp2 = relimport('..fcp2')
#****************************************************************************************
#
#****************************************************************************************
Modified: trunk/fcp2/src/test/test_key.py
===================================================================
--- trunk/fcp2/src/test/test_key.py 2008-07-07 07:14:44 UTC (rev 530)
+++ trunk/fcp2/src/test/test_key.py 2008-07-07 07:15:56 UTC (rev 531)
@@ -4,7 +4,30 @@
import socket
import unittest
-import fcp2
+# hack relative imports to make in-place testing work
+def relimport(what):
+ import imp, os, sys
+ L = what.split('.')
+ if not L or L[0]:
+ raise ValueError('relative import must start with a dot')
+ name = os.path.abspath(__file__)
+ while L:
+ p = L.pop(0)
+ if p: name = os.path.join(name, p)
+ else:
+ name, _ = os.path.split(name)
+ if not _: break
+ if L: raise ValueError('root level exceeded')
+ mod = sys.modules.get(name, None)
+ if mod is None:
+ fpath, fname = os.path.split(name)
+ fp, fpath, suffixes = imp.find_module(fname, [fpath, ])
+ try: mod = imp.load_module(name, fp, fpath, suffixes)
+ finally:
+ if fp is not None: fp.close()
+ return mod
+
+fcp2 = relimport('..fcp2')
#****************************************************************************************
#
#****************************************************************************************
Modified: trunk/fcp2/src/test/test_message.py
===================================================================
--- trunk/fcp2/src/test/test_message.py 2008-07-07 07:14:44 UTC (rev 530)
+++ trunk/fcp2/src/test/test_message.py 2008-07-07 07:15:56 UTC (rev 531)
@@ -4,19 +4,30 @@
import socket
import unittest
-#--> rel import hack
-class _RelImportHack(object):
- def __init__(self, n):
- fpath = os.path.abspath(__file__)
- for i in xrange(n): fpath = os.path.dirname(fpath)
- sys.path.insert(0, fpath)
- def __del__(self): sys.path.pop(0)
-hack = _RelImportHack(3)
+# hack relative imports to make in-place testing work
+def relimport(what):
+ import imp, os, sys
+ L = what.split('.')
+ if not L or L[0]:
+ raise ValueError('relative import must start with a dot')
+ name = os.path.abspath(__file__)
+ while L:
+ p = L.pop(0)
+ if p: name = os.path.join(name, p)
+ else:
+ name, _ = os.path.split(name)
+ if not _: break
+ if L: raise ValueError('root level exceeded')
+ mod = sys.modules.get(name, None)
+ if mod is None:
+ fpath, fname = os.path.split(name)
+ fp, fpath, suffixes = imp.find_module(fname, [fpath, ])
+ try: mod = imp.load_module(name, fp, fpath, suffixes)
+ finally:
+ if fp is not None: fp.close()
+ return mod
-import fcp2
-
-del hack
-#<-- rel import hack
+fcp2 = relimport('..fcp2')
#****************************************************************************************
#
#****************************************************************************************
Modified: trunk/fcp2/src/test/test_types.py
===================================================================
--- trunk/fcp2/src/test/test_types.py 2008-07-07 07:14:44 UTC (rev 530)
+++ trunk/fcp2/src/test/test_types.py 2008-07-07 07:15:56 UTC (rev 531)
@@ -4,7 +4,31 @@
import socket
import unittest
-import fcp2
+
+# hack relative imports to make in-place testing work
+def relimport(what):
+ import imp, os, sys
+ L = what.split('.')
+ if not L or L[0]:
+ raise ValueError('relative import must start with a dot')
+ name = os.path.abspath(__file__)
+ while L:
+ p = L.pop(0)
+ if p: name = os.path.join(name, p)
+ else:
+ name, _ = os.path.split(name)
+ if not _: break
+ if L: raise ValueError('root level exceeded')
+ mod = sys.modules.get(name, None)
+ if mod is None:
+ fpath, fname = os.path.split(name)
+ fp, fpath, suffixes = imp.find_module(fname, [fpath, ])
+ try: mod = imp.load_module(name, fp, fpath, suffixes)
+ finally:
+ if fp is not None: fp.close()
+ return mod
+
+fcp2 = relimport('..fcp2')
#****************************************************************************************
#
#****************************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|