Ejemplo n.º 1
0
class _UnixFixHome(object):
    """
    Mixin class to fix the HOME environment variable to something usable.

    @ivar home: FilePath pointing at C{homePath}.
    @type home: L{FilePath}

    @ivar homePath: relative path to the directory used as HOME during the
        tests.
    @type homePath: C{str}
    """
    def setUp(self):
        path = self.mktemp()
        self.home = FilePath(path)
        self.homePath = os.path.join(*self.home.segmentsFrom(FilePath(".")))
        if len(self.home.path) >= 70:
            # UNIX_MAX_PATH is 108, and the socket file is generally of length
            # 30, so we can't rely on mktemp...
            self.homePath = "_tmp"
            self.home = FilePath(self.homePath)
        self.home.makedirs()
        self.savedEnviron = os.environ.copy()
        os.environ["HOME"] = self.homePath

    def tearDown(self):
        os.environ.clear()
        os.environ.update(self.savedEnviron)
        self.home.remove()
Ejemplo n.º 2
0
class _UnixFixHome(object):
    """
    Mixin class to fix the HOME environment variable to something usable.

    @ivar home: FilePath pointing at C{homePath}.
    @type home: L{FilePath}

    @ivar homePath: relative path to the directory used as HOME during the
        tests.
    @type homePath: C{str}
    """

    def setUp(self):
        path = self.mktemp()
        self.home = FilePath(path)
        self.homePath = os.path.join(*self.home.segmentsFrom(FilePath(".")))
        if len(self.home.path) >= 70:
            # UNIX_MAX_PATH is 108, and the socket file is generally of length
            # 30, so we can't rely on mktemp...
            self.homePath = "_tmp"
            self.home = FilePath(self.homePath)
        self.home.makedirs()
        self.savedEnviron = os.environ.copy()
        os.environ["HOME"] = self.homePath


    def tearDown(self):
        os.environ.clear()
        os.environ.update(self.savedEnviron)
        self.home.remove()
Ejemplo n.º 3
0
    def mapPath(self, fsPathString):
        """
        Map the given FS path to a ZipPath, by looking at the ZipImporter's
        "archive" attribute and using it as our ZipArchive root, then walking
        down into the archive from there.

        @return: a L{zippath.ZipPath} or L{zippath.ZipArchive} instance.
        """
        za = ZipArchive(self.importer.archive)
        myPath = FilePath(self.importer.archive)
        itsPath = FilePath(fsPathString)
        if myPath == itsPath:
            return za
        # This is NOT a general-purpose rule for sys.path or __file__:
        # zipimport specifically uses regular OS path syntax in its pathnames.
        segs = itsPath.segmentsFrom(myPath)
        zp = za
        for seg in segs:
            zp = zp.child(seg)
        return zp
Ejemplo n.º 4
0
    def mapPath(self, fsPathString):
        """
        Map the given FS path to a ZipPath, by looking at the ZipImporter's
        "archive" attribute and using it as our ZipArchive root, then walking
        down into the archive from there.

        @return: a L{zippath.ZipPath} or L{zippath.ZipArchive} instance.
        """
        za = ZipArchive(self.importer.archive)
        myPath = FilePath(self.importer.archive)
        itsPath = FilePath(fsPathString)
        if myPath == itsPath:
            return za
        # This is NOT a general-purpose rule for sys.path or __file__:
        # zipimport specifically uses regular OS path syntax in its pathnames.
        segs = itsPath.segmentsFrom(myPath)
        zp = za
        for seg in segs:
            zp = zp.child(seg)
        return zp