コード例 #1
0
def tarpath(tmpdir_factory):
    """create a stub tarball for testing"""
    tmpdir = tmpdir_factory.mktemp("test_extract")

    tempdir = tmpdir.join("stubs").strpath
    stubs.create_stub(tempdir)
    filename = tmpdir.join('bundle.tar').strpath
    archive = tarfile.TarFile(filename, mode='w')
    for path in stubs.files:
        archive.add(os.path.join(tempdir, *path), arcname=os.path.join(*path))
    archive.close()

    assert os.path.exists(filename)
    return filename
コード例 #2
0
def zippath(tmpdir_factory):
    """create a stub zipfile for testing"""
    tmpdir = tmpdir_factory.mktemp("test_extract")

    tempdir = tmpdir.join("stubs").strpath
    stubs.create_stub(tempdir)
    filename = tmpdir.join('bundle.zip').strpath
    archive = zipfile.ZipFile(filename, mode='w')
    for path in stubs.files:
        archive.write(os.path.join(tempdir, *path), arcname=os.path.join(*path))
    archive.close()

    assert os.path.exists(filename)
    return filename
コード例 #3
0
    def test_copy_full_directory_with_overlapping_file(self):
        tempdir = stubs.create_stub()
        dstdir = stubs.create_empty_stub()

        filename = "i_do_exist_in_tempdir"
        for d in [tempdir, dstdir]:
            f = open(os.path.join(d, filename), "w")
            f.write("Hello " + d)
            f.close()

        self.assertTrue(os.path.isdir(tempdir))
        self.assertTrue(os.path.exists(os.path.join(tempdir, filename)))
        self.assertTrue(os.path.exists(os.path.join(dstdir, filename)))

        line = open(os.path.join(dstdir, filename), "r").readlines()[0]
        self.assertTrue(line == "Hello " + dstdir)

        mozfile.copy_contents(tempdir, dstdir)

        line = open(os.path.join(dstdir, filename), "r").readlines()[0]
        self.assertTrue(line == "Hello " + tempdir)
        self._directories_are_equal(tempdir, dstdir)

        if os.path.isdir(tempdir):
            shutil.rmtree(tempdir)
        if os.path.isdir(dstdir):
            shutil.rmtree(dstdir)
コード例 #4
0
    def test_copy_full_directory(self):
        tempdir = stubs.create_stub()
        dstdir = stubs.create_empty_stub()
        self.assertTrue(os.path.isdir(tempdir))

        mozfile.copy_contents(tempdir, dstdir)
        self._directories_are_equal(dstdir, tempdir)

        if os.path.isdir(tempdir):
            shutil.rmtree(tempdir)
        if os.path.isdir(dstdir):
            shutil.rmtree(dstdir)
コード例 #5
0
 def create_tarball(self):
     """create a stub tarball for testing"""
     tempdir = stubs.create_stub()
     filename = tempfile.mktemp(suffix=".tar")
     archive = tarfile.TarFile(filename, mode="w")
     try:
         for path in stubs.files:
             archive.add(os.path.join(tempdir, *path), arcname=os.path.join(*path))
     except:
         os.remove(archive)
         raise
     finally:
         shutil.rmtree(tempdir)
     archive.close()
     return filename
コード例 #6
0
 def create_tarball(self):
     """create a stub tarball for testing"""
     tempdir = stubs.create_stub()
     filename = tempfile.mktemp(suffix='.tar')
     archive = tarfile.TarFile(filename, mode='w')
     try:
         for path in stubs.files:
             archive.add(os.path.join(tempdir, *path), arcname=os.path.join(*path))
     except BaseException:
         os.remove(archive)
         raise
     finally:
         shutil.rmtree(tempdir)
     archive.close()
     return filename
コード例 #7
0
    def create_zip(self):
        """create a stub zipfile for testing"""

        tempdir = stubs.create_stub()
        filename = tempfile.mktemp(suffix=".zip")
        archive = zipfile.ZipFile(filename, mode="w")
        try:
            for path in stubs.files:
                archive.write(os.path.join(tempdir, *path), arcname=os.path.join(*path))
        except:
            os.remove(filename)
            raise
        finally:
            shutil.rmtree(tempdir)
        archive.close()
        return filename
コード例 #8
0
    def create_zip(self):
        """create a stub zipfile for testing"""

        tempdir = stubs.create_stub()
        filename = tempfile.mktemp(suffix='.zip')
        archive = zipfile.ZipFile(filename, mode='w')
        try:
            for path in stubs.files:
                archive.write(os.path.join(tempdir, *path), arcname=os.path.join(*path))
        except BaseException:
            os.remove(filename)
            raise
        finally:
            shutil.rmtree(tempdir)
        archive.close()
        return filename
コード例 #9
0
    def test_copy_full_directory_with_existing_file(self):
        tempdir = stubs.create_stub()
        dstdir = stubs.create_empty_stub()

        filename = "i_dont_exist_in_tempdir"
        f = open(os.path.join(dstdir, filename), "w")
        f.write("Hello World")
        f.close()

        self.assertTrue(os.path.isdir(tempdir))

        mozfile.copy_contents(tempdir, dstdir)
        self._directory_is_subset(dstdir, tempdir)
        self.assertTrue(os.path.exists(os.path.join(dstdir, filename)))

        if os.path.isdir(tempdir):
            shutil.rmtree(tempdir)
        if os.path.isdir(dstdir):
            shutil.rmtree(dstdir)
コード例 #10
0
ファイル: test_move_remove.py プロジェクト: MekliCZ/positron
 def setUp(self):
     # Generate a stub
     self.tempdir = stubs.create_stub()
コード例 #11
0
ファイル: test_move_remove.py プロジェクト: MekliCZ/positron
 def setUp(self):
     # Generate a stub
     self.tempdir = stubs.create_stub()
     self.addCleanup(mozfile.rmtree, self.tempdir)
コード例 #12
0
ファイル: test_move_remove.py プロジェクト: bocoup/gecko-dev
 def setUp(self):
     # Generate a stub
     self.tempdir = stubs.create_stub()
コード例 #13
0
ファイル: test_move_remove.py プロジェクト: bocoup/gecko-dev
 def setUp(self):
     # Generate a stub
     self.tempdir = stubs.create_stub()
     self.addCleanup(mozfile.rmtree, self.tempdir)