Ralph Bean avatar Ralph Bean committed 47f5585

Guess modname in post_define. Fixes #18.

Comments (0)

Files changed (2)

tests/test_resources.py

 
 
 class TestResourcesMisc(TestCase):
+    real_modname = 'nose.importer'
+
     def testJSSymbol(self):
         """
         should set the src attribute
 
     def testAutoModname(self):
         l = twr.Link(filename="somefile")
-        eq_(l.modname, __name__)
+        eq_(l.modname, self.real_modname)
 
     def testAutoModnameReqPrep(self):
         l = twr.Link(filename="somefile")
         l = l.req()
         l.prepare()
-        eq_(l.modname, __name__)
+        eq_(l.modname, self.real_modname)
 
     def testAutoModnameInject(self):
         l = twr.Link(filename="somefile")
         l.inject()
         local = tw2.core.core.request_local()
-        eq_(local['resources'][0].modname, __name__)
+        eq_(local['resources'][0].modname, self.real_modname)
 
     def testDirLink(self):
         dl = twr.DirLink(modname="tw2.core", filename="somefile")

tw2/core/resources.py

         default=False,
     )
 
-    def guess_modname(self):
+    @classmethod
+    def guess_modname(cls):
         """ Try to guess my modname.
 
         If I wasn't supplied any modname, take a guess by stepping back up the
 
     @classmethod
     def post_define(cls):
+
+        if not cls.modname:
+            cls.modname = cls.guess_modname()
+
         if not cls.no_inject:
             if getattr(cls, 'filename', None) and \
                type(cls.filename) != property:
                 )
 
     def prepare(self):
-        if not self.modname:
-            self.modname = self.guess_modname()
-
         rl = core.request_local()
         if not self.no_inject:
             if not hasattr(self, 'link'):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.