Skip to content

Commit

Permalink
Guess modname in post_define. Fixes #18.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed May 18, 2012
1 parent 5b1c1da commit d3d2aeb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions tests/test_resources.py
Expand Up @@ -284,6 +284,8 @@ def test_find_charset():


class TestResourcesMisc(TestCase):
real_modname = 'nose.importer'

def testJSSymbol(self):
"""
should set the src attribute
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 6 additions & 4 deletions tw2/core/resources.py
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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'):
Expand Down

0 comments on commit d3d2aeb

Please sign in to comment.