Example #1
0
 def test_get_modpath_pkg_resources_invalid(self):
     with pretty_logging(stream=StringIO()) as fd:
         self.assertEqual([], indexer.modpath_pkg_resources(None))
         self.assertIn("None does not appear to be a valid module",
                       fd.getvalue())
     with pretty_logging(stream=StringIO()) as fd:
         module = ModuleType('nothing')
         self.assertEqual([], indexer.modpath_pkg_resources(module))
         # module repr differs between python versions.
         self.assertIn("module 'nothing'", fd.getvalue())
         self.assertIn("could not be located", fd.getvalue())
Example #2
0
    def test_get_modpath_pkg_resources_missing_path(self):
        with pretty_logging(stream=StringIO()) as fd:
            self.assertEqual([],
                             indexer.modpath_pkg_resources(None, calmjs_ep))
            self.assertIn("None does not appear to be a valid module",
                          fd.getvalue())
        with pretty_logging(stream=StringIO()) as fd:
            module = ModuleType('nothing')
            self.assertEqual([],
                             indexer.modpath_pkg_resources(module, calmjs_ep))

        err = fd.getvalue()
        self.assertIn("module 'nothing' and entry_point 'demo = demo'", err)
        # the input is fetched using a working entry_point, after all
        self.assertIn("path found at '" + calmjs_dist_dir, err)
        self.assertIn("it does not exist", fd.getvalue())
Example #3
0
    def test_module3_multi_path(self):
        """
        For modules that have multiple paths.  This is typically caused
        by specifying a module that is typically used as a namespace for
        other Python modules.  Normally this can interfere with imports
        but as long as a module is produced and the multiple path
        modpath method is used, the mapper will fulfil the order.
        """

        # See setup method for how it's built.
        calmjs_base_dir = abspath(
            join(indexer.modpath_pkg_resources(indexer)[0], pardir))
        module, index_js = make_multipath_module3(self)

        def join_mod3(*a):
            return join(calmjs_base_dir, 'calmjs', 'testing', 'module3', *a)

        results = indexer.mapper(module, modpath='all', globber='recursive')
        self.assertEqual(
            results, {
                'calmjs/testing/module3/index': index_js,
                'calmjs/testing/module3/math': join_mod3('math.js'),
                'calmjs/testing/module3/mod/index': join_mod3(
                    'mod', 'index.js'),
            })
Example #4
0
 def test_get_modpath_pkg_resources_invalid(self):
     # fake both module and entry point, which will trigger an import
     # error exception internally that gets logged.
     module = ModuleType('nothing')
     ep = pkg_resources.EntryPoint.parse('nothing = nothing')
     with pretty_logging(stream=StringIO()) as fd:
         self.assertEqual([], indexer.modpath_pkg_resources(module, ep))
     self.assertIn("module 'nothing' could not be imported", fd.getvalue())
Example #5
0
 def test_get_modpath_pkg_resources_invalid(self):
     # fake both module and entry point, which will trigger an import
     # error exception internally that gets logged.
     module = ModuleType('nothing')
     ep = pkg_resources.EntryPoint.parse('nothing = nothing')
     with pretty_logging(stream=StringIO()) as fd:
         self.assertEqual([], indexer.modpath_pkg_resources(module, ep))
     self.assertIn("module 'nothing' could not be imported", fd.getvalue())
Example #6
0
    def test_get_modpath_pkg_resources_missing_path(self):
        with pretty_logging(stream=StringIO()) as fd:
            self.assertEqual([], indexer.modpath_pkg_resources(
                None, calmjs_ep))
            self.assertIn(
                "None does not appear to be a valid module", fd.getvalue())
        with pretty_logging(stream=StringIO()) as fd:
            module = ModuleType('nothing')
            self.assertEqual([], indexer.modpath_pkg_resources(
                module, calmjs_ep))

        err = fd.getvalue()
        self.assertIn(
            "module 'nothing' and entry_point 'demo = demo'", err)
        # the input is fetched using a working entry_point, after all
        self.assertIn("path found at '" + calmjs_dist_dir, err)
        self.assertIn("it does not exist", fd.getvalue())
Example #7
0
 def test_get_modpath_pkg_resources_missing(self):
     # fake just the entry point, but provide a valid module.
     nothing = ModuleType('nothing')
     nothing.__path__ = []
     self.addCleanup(sys.modules.pop, 'nothing')
     sys.modules['nothing'] = nothing
     ep = pkg_resources.EntryPoint.parse('nothing = nothing')
     with pretty_logging(stream=StringIO()) as fd:
         self.assertEqual([], indexer.modpath_pkg_resources(nothing, ep))
     self.assertIn(
         "resource path cannot be found for module 'nothing' and "
         "entry_point 'nothing = nothing'", fd.getvalue())
Example #8
0
 def test_get_modpath_pkg_resources_missing(self):
     # fake just the entry point, but provide a valid module.
     nothing = ModuleType('nothing')
     nothing.__path__ = []
     self.addCleanup(sys.modules.pop, 'nothing')
     sys.modules['nothing'] = nothing
     ep = pkg_resources.EntryPoint.parse('nothing = nothing')
     with pretty_logging(stream=StringIO()) as fd:
         self.assertEqual([], indexer.modpath_pkg_resources(nothing, ep))
     self.assertIn(
         "resource path cannot be found for module 'nothing' and "
         "entry_point 'nothing = nothing'", fd.getvalue())
Example #9
0
 def test_module1_loader_python(self):
     from calmjs.testing import module1
     calmjs_base_dir = abspath(
         join(indexer.modpath_pkg_resources(indexer)[0], pardir))
     results = {
         k: relpath(v, calmjs_base_dir)
         for k, v in indexer.mapper_python(module1).items()
     }
     self.assertEqual(
         results, {
             'calmjs.testing.module1.hello':
             to_os_sep_path('calmjs/testing/module1/hello.js'),
         })
Example #10
0
 def test_module2_recursive_es6(self):
     from calmjs.testing import module2
     calmjs_base_dir = abspath(
         join(indexer.modpath_pkg_resources(indexer)[0], pardir))
     results = {
         k: relpath(v, calmjs_base_dir)
         for k, v in indexer.mapper(module2, globber='recursive').items()
     }
     self.assertEqual(
         results, {
             'calmjs/testing/module2/index':
             to_os_sep_path('calmjs/testing/module2/index.js'),
             'calmjs/testing/module2/helper':
             to_os_sep_path('calmjs/testing/module2/helper.js'),
             'calmjs/testing/module2/mod/helper':
             to_os_sep_path('calmjs/testing/module2/mod/helper.js'),
         })
Example #11
0
 def test_get_modpath_pkg_resources_valid(self):
     from calmjs.testing import module3
     result = indexer.modpath_pkg_resources(module3)
     self.assertEqual(len(result), 1)
     self.assertTrue(result[0].endswith(
         to_os_sep_path('calmjs/testing/module3')))
Example #12
0
 def test_get_modpath_pkg_resources_valid(self):
     from calmjs.testing import module3
     result = indexer.modpath_pkg_resources(module3, calmjs_ep)
     self.assertEqual(len(result), 1)
     self.assertTrue(result[0].endswith(
         to_os_sep_path('calmjs/testing/module3')))