Example #1
0
def getDependencies(fname,
                    ignore=[],
                    bootstrap=_TEST_BOOTSTRAP,
                    packages=None):
    """
    Get the javascript modules that the code in the file with name C{fname}
    depends on, recursively

    @param fname: javascript source file name
    @type fname: C{str}

    @param ignore: names of javascript modules to exclude from dependency list
    @type ignore: sequence

    @param bootstrap: names of javascript modules to always include, regardless
    of explicit dependencies (defaults to L{LivePage}'s list of bootstrap
    modules, plus the mock browser implementation.)
    @type boostrap: sequence

    @param packages: all javascript packages we know about.  defaults to the
    result of L{allJavascriptPackages}
    @type packages: C{dict}

    @return: modules included by javascript in file named C{fname}
    @rtype: dependency-ordered list of L{AthenaModule} instances
    """
    if packages is None:
        packages = allJavascriptPackages()

    # TODO if a module is ignored, we should ignore its dependencies
    bootstrapModules = [
        AthenaModule.getOrCreate(m, packages) for m in bootstrap
        if m not in ignore
    ]

    packages[_DUMMY_MODULE_NAME] = fname
    module = AthenaModule(_DUMMY_MODULE_NAME, packages)

    return (bootstrapModules + [
        dep for dep in module.allDependencies()
        if (dep.name not in bootstrap and dep.name != _DUMMY_MODULE_NAME
            and dep.name not in ignore)
    ])
Example #2
0
def getDependencies(fname, ignore=[],
                    bootstrap=_TEST_BOOTSTRAP,
                    packages=None):
    """
    Get the javascript modules that the code in the file with name C{fname}
    depends on, recursively

    @param fname: javascript source file name
    @type fname: C{str}

    @param ignore: names of javascript modules to exclude from dependency list
    @type ignore: sequence

    @param bootstrap: names of javascript modules to always include, regardless
    of explicit dependencies (defaults to L{LivePage}'s list of bootstrap
    modules, plus the mock browser implementation.)
    @type boostrap: sequence

    @param packages: all javascript packages we know about.  defaults to the
    result of L{allJavascriptPackages}
    @type packages: C{dict}

    @return: modules included by javascript in file named C{fname}
    @rtype: dependency-ordered list of L{AthenaModule} instances
    """
    if packages is None:
        packages = allJavascriptPackages()

    # TODO if a module is ignored, we should ignore its dependencies
    bootstrapModules = [AthenaModule.getOrCreate(m, packages)
                        for m in bootstrap if m not in ignore]

    packages[_DUMMY_MODULE_NAME] = fname
    module = AthenaModule(_DUMMY_MODULE_NAME, packages)

    return (bootstrapModules +
            [dep for dep in module.allDependencies()
             if (dep.name not in bootstrap
                 and dep.name != _DUMMY_MODULE_NAME
                 and dep.name not in ignore)])
Example #3
0
 def _getPackages(self):
     """
     @return: the mapping of all javascript packages plus some fake modules
     """
     packages = athena.allJavascriptPackages()
     packages.update(
         {'ConsoleJSTestFoo': self._outputToTempFile(
                     'print("hello from ConsoleJSTestFoo");'),
          'ConsoleJSTestFoo.Bar': self._outputToTempFile(
                         dedent(
                             '''
                             // import ConsoleJSTestFoo
                             print("hello from ConsoleJSTestFoo.Bar");
                             ''')),
          'ConsoleJSTestFoo.Baz': self._outputToTempFile(
                         dedent(
                             '''
                             // import ConsoleJSTestFoo
                             // import ConsoleJSTestFoo.Bar
                             print("hello from ConsoleJSTestFoo.Baz");
                             '''))})
     return packages
Example #4
0
        def test():
            jsPackages = athena.allJavascriptPackages()
            rr = example.AthenaPage(jsModules=athena.MappingResource(jsPackages))
            rr._becomeLive(url.URL('/app'))
            rendered = yield flat.flatten(rr)
            self.assertSubstring('Rate: 50', rendered)

            # set the rate to be too infrequent to have any race possibilities
            # during this test
            rr.rate = 0.00001 # = 100000 seconds between updates

            rr.wid.setFilter(0)
            self.assertEqual(rr.wid.filter, 0)

            rr.wid.liveFragmentChildren = []


            callRemote = fudge.Fake("callRemote", expect_call=True)
            callRemote.with_args("number", 486000).returns(defer.succeed(u'ok'))
            fudge.patch_object(rr.wid, 'callRemote', callRemote)

            random.seed(10)

            # make two calls to random() with this seed.  They should return
            # the tested values, using Python's documented PRNG: Mersenne
            # Twister, and this seed.

            num = yield rr.wid.number()
            self.assertEqual(num, 614262)

            num = yield rr.wid.number()
            self.assertEqual(num, 486000)

            fudge.verify()

            rr.wid._athenaDetachServer()
            rr.action_close(None)
            defer.returnValue(None)
Example #5
0
 def _getPackages(self):
     """
     @return: the mapping of all javascript packages plus some fake modules
     """
     packages = athena.allJavascriptPackages()
     packages.update({
         'ConsoleJSTestFoo':
         self._outputToTempFile('print("hello from ConsoleJSTestFoo");'),
         'ConsoleJSTestFoo.Bar':
         self._outputToTempFile(
             dedent('''
                             // import ConsoleJSTestFoo
                             print("hello from ConsoleJSTestFoo.Bar");
                             ''')),
         'ConsoleJSTestFoo.Baz':
         self._outputToTempFile(
             dedent('''
                             // import ConsoleJSTestFoo
                             // import ConsoleJSTestFoo.Bar
                             print("hello from ConsoleJSTestFoo.Baz");
                             '''))
     })
     return packages
Example #6
0
if sys.platform.find('freebsd') == 0:
  stripDistribution()

tacpath = os.getcwd()
print 'this is                     : ', __file__
print 'on path                     : ', tacpath

sys.path.append(os.path.join(tacpath, 'py'))

mainPkgName = 'qxcomscroll'
import qxcomscroll
qxcomscroll.mainPkgName = mainPkgName
print '...using main module        : ', qxcomscroll.mainPkgName

athena.allJavascriptPackages()        #maps the basic runtime packages

#hunt down the related js files. Please note that the js.src is preferred over
#js, meaning that when in production the js.src could be killed and obfuscated
#and compressed js will be delivered out of packaged js directory
modulepath = os.path.join(os.path.split(qxcomscroll.__file__)[0], '..')

qxcomscroll.js = 'js'

#the JS source is preferred over the packaged version
if os.path.isdir(util.sibpath(modulepath, 'js.src')):
  qxcomscroll.js = 'js.src'

qxcomscroll.jspath = util.sibpath(modulepath, qxcomscroll.js)
qxcomscroll.siteJSPackage = athena.AutoJSPackage(qxcomscroll.jspath)
print '...using JS packages on path: ', qxcomscroll.jspath
Example #7
0
 def setUp(self):
     self.jsPackages = athena.allJavascriptPackages()