• R/O
  • SSH
  • HTTPS

pyhabu: Commit


Commit MetaInfo

Revision84 (tree)
Time2007-09-28 22:59:48
Authorliris

Log Message

test codes

Change Summary

Incremental Difference

--- trunk/habu/test_moduleloader.py (revision 83)
+++ trunk/habu/test_moduleloader.py (revision 84)
@@ -1,7 +1,7 @@
11 from twisted.trial.unittest import TestCase
22 from twisted.web.resource import Resource
33 from twisted.web import server
4-from twisted.internet import reactor
4+from twisted.internet import reactor, defer
55 import moduleloader
66 import os, os.path, shutil
77
@@ -31,6 +31,8 @@
3131 def render_GET(self, request):
3232 return 'print("iyan")'
3333
34+from twisted.python import failure
35+
3436 class ModuleNetLoaderTest(TestCase):
3537 def setUp(self):
3638 moduleloader._moduleFactories = {}
@@ -59,14 +61,57 @@
5961 return "http://127.0.0.1:%d/%s" % (self.portno, path)
6062
6163 def _checkExist(self, result, *args, **kwds):
62- self.assertEquals(os.path.exists("./tmpDownload/mymod.py"), True)
64+ self.assertEquals(os.path.exists("./tmpDownload/m/mymod.py"), True)
6365 return result
6466
6567 def testDownload(self):
6668 d = moduleloader.downloadModule(self.getURL("base"),
6769 "m.mymod",
68- "./tmpDownlaod")
70+ "./tmpDownload")
6971 return d.addCallback(self._checkExist)
7072
73+ def testDownloadFail(self):
74+ d = moduleloader.downloadModule(self.getURL("base"),
75+ "m.mymod2",
76+ "./tmpDownload")
77+ def got(result):
78+ self.assertEquals(1, 0)
7179
80+ def gotErr(failure):
81+ pass
7282
83+ return d.addCallback(got).addErrback(gotErr)
84+
85+ def testNetLoader(self):
86+ d = moduleloader.loadModuleFromNet("m.mymod", ["./tmpDownload"],
87+ url = self.getURL("base"),
88+ )
89+ if isinstance(d, defer.Deferred):
90+ return d.addCallback(self._checkExist)
91+
92+ self.assertEquals(not d, False)
93+
94+ def testNetLoaderExist(self):
95+ os.makedirs("./tmpDownload/m")
96+ fp = open("./tmpDownload/m/mymod.py", "w")
97+ fp.write("import sys")
98+ fp.close()
99+ d = moduleloader.loadModuleFromNet("m.mymod", ["./tmpDownload"],
100+ url = self.getURL("base"),
101+ )
102+ if isinstance(d, defer.Deferred):
103+ self.assertEquals(0, 1)
104+
105+ self.assertEquals(not d, False)
106+
107+
108+ def testNetLoaderBadPy(self):
109+ os.makedirs("./tmpDownload/m")
110+ fp = open("./tmpDownload/m/mymod.py", "w")
111+ fp.write("hogehoge fuga")
112+ fp.close()
113+ self.assertRaises(Exception, moduleloader.loadModuleFromNet,
114+ "m.mymod", ["./tmpDownload"],
115+ url = self.getURL("base"),
116+ )
117+
Show on old repository browser