示例#1
0
    def test_loadNamed(self):
        """
        Modules can be loaded, by name, independent of global state.
        """
        m1 = loadNamed("exocet.test.testpackage.util", emptyMapper)
        m1.testAttribute = "a value"

        m2 = loadNamed("exocet.test.testpackage.util", emptyMapper)
        m2.testAttribute = "a different value"

        self.assertFalse(m1 is m2)
        self.assertNotEqual(m1.testAttribute, m2.testAttribute)
        self.assertFalse(m1 in sys.modules.values())
        self.assertFalse(m2 in sys.modules.values())
        self.assertEqual(m1.utilName, "hooray")
        self.assertEqual(m2.utilName, "hooray")
示例#2
0
    def test_loadNamed(self):
        """
        Modules can be loaded, by name, independent of global state.
        """
        m1 = loadNamed("exocet.test.testpackage.util", emptyMapper)
        m1.testAttribute = "a value"

        m2 = loadNamed("exocet.test.testpackage.util", emptyMapper)
        m2.testAttribute = "a different value"

        self.assertFalse(m1 is m2)
        self.assertNotEqual(m1.testAttribute, m2.testAttribute)
        self.assertFalse(m1 in sys.modules.values())
        self.assertFalse(m2 in sys.modules.values())
        self.assertEqual(m1.utilName, "hooray")
        self.assertEqual(m2.utilName, "hooray")
    def test_ospath(self):
        """
        L{pep302Mapper} deals with modules that import L{os.path} properly.
        """

        m = loadNamed("exocet.test._ospathExample", pep302Mapper)
        import os.path
        assertIdentical(self, os, m.os)
        assertIdentical(self, os.path, m.os.path)
示例#4
0
    def test_ospath(self):
        """
        L{pep302Mapper} deals with modules that import L{os.path} properly.
        """

        m = loadNamed("exocet.test._ospathExample", pep302Mapper)
        import os.path
        assertIdentical(self, os, m.os)
        assertIdentical(self, os.path, m.os.path)
示例#5
0
    def test_loadPackageAsModule(self):
        """
        Calling L{loadNamed} with the name of a package loads the package and
        returns its __init__ module.
        """

        m = loadNamed("exocet.test.testpackage", emptyMapper)
        self.assertEqual(m.topName, "top value")
        self.assertEqual(m.fooName, "hooray")
        self.assertEqual(m.utilName, "hooray")
示例#6
0
    def test_loadPackageAsModule(self):
        """
        Calling L{loadNamed} with the name of a package loads the package and
        returns its __init__ module.
        """

        m = loadNamed("exocet.test.testpackage", emptyMapper)
        self.assertEqual(m.topName, "top value")
        self.assertEqual(m.fooName, "hooray")
        self.assertEqual(m.utilName, "hooray")
    def test_loadWithLocalImports(self):
        """
        Execution of local imports are resolved in the context the
        containing module was originally loaded in.
        """
        class fakeUtil:
            utilName = "booo"

        class tpli:
            util = fakeUtil
        m = pep302Mapper.withOverrides(
            {"exocet.test.testpackage_localimports": tpli})

        foo = loadNamed("exocet.test.testpackage_localimports.foo", m)
        self.assertEqual(foo.fooName, [])
        util2 = foo.do()
        self.assertEqual(foo.fooName[0], fakeUtil.utilName)
        self.assertEqual(util2.utilName, fakeUtil.utilName)