• R/O
  • SSH
  • HTTPS

pyhabu: Commit


Commit MetaInfo

Revision83 (tree)
Time2007-09-28 19:22:26
Authorliris

Log Message

test

Change Summary

Incremental Difference

--- trunk/habu/test_moduleloader.py (revision 82)
+++ trunk/habu/test_moduleloader.py (revision 83)
@@ -1,7 +1,9 @@
11 from twisted.trial.unittest import TestCase
2-
2+from twisted.web.resource import Resource
3+from twisted.web import server
4+from twisted.internet import reactor
35 import moduleloader
4-import os, os.path
6+import os, os.path, shutil
57
68 class ModuleLoaderTest(TestCase):
79 def testNormal(self):
@@ -17,5 +19,54 @@
1719 self.assertRaises(ImportError, moduleloader.loadModule, "my.test.module.mytest2", pluginPath)
1820 self.assertRaises(ImportError, moduleloader.loadModule, "filter.nomod", pluginPath)
1921
22+
23+class MyResource(Resource):
24+ isLeaf = False
25+ def getChild(self, name, request):
26+ if not name:
27+ return self
28+ return Resource.getChild(self, name, request)
29+
30+class MyPyResource(Resource):
31+ def render_GET(self, request):
32+ return 'print("iyan")'
33+
34+class ModuleNetLoaderTest(TestCase):
35+ def setUp(self):
36+ moduleloader._moduleFactories = {}
37+ root = MyResource()
38+ leaf1 = MyResource()
39+ leaf2 = MyResource()
40+ root.putChild("base", leaf1)
41+ leaf1.putChild("m", leaf2)
42+ leaf2.putChild("mymod.py", MyPyResource())
43+ root.putChild("mymod.py", MyResource)
44+ site = server.Site(root)
45+ self.port = self._listen(site)
46+ self.portno = self.port.getHost().port
47+
48+ def tearDown(self):
49+ try:
50+ shutil.rmtree("./tmpDownload")
51+ except:
52+ pass
53+ return self.port.stopListening()
54+
55+ def _listen(self, site):
56+ return reactor.listenTCP(0, site, interface="127.0.0.1")
57+
58+ def getURL(self, path):
59+ return "http://127.0.0.1:%d/%s" % (self.portno, path)
60+
61+ def _checkExist(self, result, *args, **kwds):
62+ self.assertEquals(os.path.exists("./tmpDownload/mymod.py"), True)
63+ return result
64+
65+ def testDownload(self):
66+ d = moduleloader.downloadModule(self.getURL("base"),
67+ "m.mymod",
68+ "./tmpDownlaod")
69+ return d.addCallback(self._checkExist)
70+
71+
2072
21-
Show on old repository browser