def test_save_into_load_from_fd(self):
     other = copy.deepcopy(self.dict_file)
     fnm = create_temp_file()
     with open(fnm, "w") as fd:
         self.dict_file.save_into_fd(fd)
     with open(fnm, "r") as fd:
         other.load_from_fd(fd, erase_first=True)
     self.assertTrue(self.dict_file.is_equal(other))
     os.remove(fnm)
 def test_save_into_load_from_fd(self):
     other = copy.deepcopy(self.dict_file)
     fnm = create_temp_file()
     fd = open(fnm, "w")
     self.dict_file.save_into_fd(fd)
     fd.close()
     fd = open(fnm, "r")
     other.load_from_fd(fd, erase_first=True)
     fd.close()
     self.assertTrue(self.dict_file.is_equal(other))
     os.remove(fnm)
Exemplo n.º 3
0
 def setUp(self):
     self.extract_dir = tempfile.mkdtemp()
     self.working_dir = tempfile.mkdtemp()
     self.number_of_files = 5
     self.files = []
     self.strings = {
         "string1": "Why did the chicken cross the road?",
         "string2": "To get to the other side."
     }
     files_created = 0
     while not (files_created == self.number_of_files):
         path = create_temp_file(file_dir=self.working_dir)
         md5sum = extract_md5(path)
         self.files.append({"path": path, "md5sum": md5sum})
         files_created += 1
Exemplo n.º 4
0
    def extract_archive_blob(self, blob):
        # handle the tarball
        temp_path = create_temp_file(file_dir=self.working_dir,
                                     write_path_to_file=False)
        temp_file = open(temp_path, 'w')
        temp_file.write(blob)
        temp_file.seek(0)
        temp_file.close()
        shutil.move(temp_path, "%s.tar.gz" % temp_path)

        tarball = GlideinTar()
        self.assertTrue(tarball.is_tarfile("%s.tar.gz" % temp_path),
                        "Blob tarball fails tarball.is_tarfile test")

        self.extract_archive_file("%s.tar.gz" % temp_path)
Exemplo n.º 5
0
 def create_files(self, number_of_files, suffix=""):
     """
     Create temporary files using the tempfile module.  The absolute path toThe file extension to place on the temporary file
     the file is written to the file for content.
     
     @type number_of_files: int
     @param number_of_files: The number of temporary files to create
     @type file_suffix: string
     @param file_suffix: The file extension to place on the temporary file
     """
     files_created = 0
     while not (files_created == number_of_files):
         path = create_temp_file(file_suffix=suffix,
                                 file_dir=self.cleanup_dir)
         files_created += 1
Exemplo n.º 6
0
    def extract_archive_blob(self, blob):
        # handle the tarball
        temp_path = create_temp_file(file_dir=self.working_dir,
                                     write_path_to_file=False)
        # TODO #23166: Use context managers[with statement] when python 3
        # once we get rid of SL6 and tarballs
        temp_file = open(temp_path, 'w')
        temp_file.write(blob)
        temp_file.seek(0)
        temp_file.close()
        shutil.move(temp_path, "%s.tar.gz" % temp_path)

        tarball = GlideinTar()
        self.assertTrue(tarball.is_tarfile("%s.tar.gz" % temp_path),
                        "Blob tarball fails tarball.is_tarfile test")

        self.extract_archive_file("%s.tar.gz" % temp_path)
Exemplo n.º 7
0
    def create_files(self, number_of_files, suffix=""):
        """
        Create temporary files using the tempfile module.  The absolute path toThe file extension to place on the temporary file
        the file is written to the file for content.

        @type number_of_files: int
        @param number_of_files: The number of temporary files to create
        @type file_suffix: string
        @param file_suffix: The file extension to place on the temporary file
        """
        files_created = 0
        while not files_created == number_of_files:
            path = create_temp_file(
                file_suffix=suffix,
                file_dir=self.cleanup_dir)
            files_created += 1
            self.assertTrue(len(path) > 0)
Exemplo n.º 8
0
 def test_save(self):
     fnm = create_temp_file()
     os.remove(fnm)
     self.dict_file.save(fname=fnm, save_only_if_changed=False)
     self.assertTrue(os.path.exists(fnm))
     os.remove(fnm)
 def test_save(self):
     fnm = create_temp_file()
     os.remove(fnm)
     self.dict_file.save(fname=fnm, save_only_if_changed=False)
     self.assertTrue(os.path.exists(fnm))
     os.remove(fnm)
Exemplo n.º 10
0
import select
import os
import unittest2 as unittest
from glideinwms.unittests.unittest_utils import runTest
from glideinwms.unittests.unittest_utils import FakeLogger
from glideinwms.unittests.unittest_utils import create_temp_file
from glideinwms.lib.fork import ForkResultError
from glideinwms.lib.fork import fork_in_bg
from glideinwms.lib.fork import fetch_fork_result
from glideinwms.lib.fork import fetch_fork_result_list
from glideinwms.lib.fork import fetch_ready_fork_result_list
from glideinwms.lib.fork import wait_for_pids
from glideinwms.lib.fork import ForkManager
import glideinwms.lib.logSupport

LOG_FILE = create_temp_file()


def global_log_setup():
    fd = open(LOG_FILE, 'w', 0)
    glideinwms.lib.logSupport.log = FakeLogger(fd)


def global_log_cleanup():
    if os.path.exists(LOG_FILE):
        os.remove(LOG_FILE)


def sleep_fn(sleep_tm=None):
    if not sleep_tm:
        sleep_tm = 1
Exemplo n.º 11
0
import xmlrunner
import platform
import unittest2 as unittest

from glideinwms.unittests.unittest_utils import FakeLogger
from glideinwms.unittests.unittest_utils import create_temp_file
from glideinwms.lib.fork import ForkResultError
from glideinwms.lib.fork import fork_in_bg
from glideinwms.lib.fork import fetch_fork_result
from glideinwms.lib.fork import fetch_fork_result_list
from glideinwms.lib.fork import fetch_ready_fork_result_list
from glideinwms.lib.fork import wait_for_pids
from glideinwms.lib.fork import ForkManager
import glideinwms.lib.logSupport

LOG_FILE = create_temp_file()


def global_log_setup():
    fd = open(LOG_FILE, 'w', 0)
    glideinwms.lib.logSupport.log = FakeLogger(fd)


def global_log_cleanup():
    if os.path.exists(LOG_FILE):
        os.remove(LOG_FILE)


def sleep_fn(sleep_tm=None):
    if not sleep_tm:
        sleep_tm = 1