Permalink
Browse files

Guess modname in post_define. Fixes #18.

  • Loading branch information...
ralphbean committed May 18, 2012
1 parent 5b1c1da commit d3d2aeb35a973e75c947ff9ecae9d9350b51ea60
Showing with 11 additions and 7 deletions.
  1. +5 −3 tests/test_resources.py
  2. +6 −4 tw2/core/resources.py
@@ -284,6 +284,8 @@ def test_find_charset():
class TestResourcesMisc(TestCase):
real_modname = 'nose.importer'
def testJSSymbol(self):
"""
should set the src attribute
@@ -317,19 +319,19 @@ def testLinkHash(self):
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")
@@ -120,7 +120,8 @@ class Link(Resource):
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
@@ -138,6 +139,10 @@ def guess_modname(self):
@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:
@@ -147,9 +152,6 @@ def post_define(cls):
)
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'):

0 comments on commit d3d2aeb

Please sign in to comment.