Ejemplo n.º 1
0
    def test_files_sizes(self, test_case):
        """
        Ensures that the files created are the correct size.

        """

        test_dir = file_utilities.create_test_directory(test_case)
        try:
            for i in test_case:
                if isinstance(i, tuple):
                    sys.stdout.write("checking size of %s\n" % (i[0], ))
                    file_size = os.stat(os.path.join(test_dir, i[0])).st_size
                    assert file_size == i[1]
        finally:
            shutil.rmtree(test_dir)
Ejemplo n.º 2
0
    def test_files_sizes(self, test_case):
        """
        Ensures that the files created are the correct size.

        """

        test_dir = file_utilities.create_test_directory(test_case)
        try:
            for i in test_case:
                if isinstance(i, tuple):
                    sys.stdout.write("checking size of %s\n" % (i[0], ))
                    file_size = os.stat(
                        os.path.join(test_dir, i[0])).st_size
                    assert file_size == i[1]
        finally:
            shutil.rmtree(test_dir)
Ejemplo n.º 3
0
    def test_existence(self, test_case):
        """
        Ensure that all the files that were supposed to get created are there,
        and ensure that none were created that weren't supposed to be.

        """

        test_dir = file_utilities.create_test_directory(test_case)
        try:
            real_contents = file_utilities.get_files(test_dir)
            expected_contents = \
                [(i[0] if isinstance(i, tuple) else i) for i in test_case]

            sys.stdout.write("real_contents = %s\n" % (real_contents, ))
            sys.stdout.write(
                "expected_contents = %s\n" % (expected_contents, ))

            assert set(real_contents) == set(expected_contents)
        finally:
            shutil.rmtree(test_dir)
Ejemplo n.º 4
0
    def zip_tree(self, request, test_case):
        try:
            # We must create these variables up front for our finally
            # statement to work correctly.
            test_dir = zip_file = unzip_dir = None

            # Create some files and directories to zip up
            test_dir = file_utilities.create_test_directory(test_case)

            # Get a temporary file that will become our zip file
            zip_file_handle = tempfile.NamedTemporaryFile(delete = False)
            zip_file_handle.close()
            zip_file = zip_file_handle.name

            # Zip up our directory tree
            zipdir.zip_directory(test_dir, zip_file)

            # Unzip our directory tree
            unzip_dir = tempfile.mkdtemp()
            with closing(zipfile.ZipFile(zip_file, "r")) as f:
                f.extractall(unzip_dir)
        except:
            if test_dir is not None:
                shutil.rmtree(test_dir)

            if zip_file is not None:
                os.remove(zip_file)

            if unzip_dir is not None:
                shutil.rmtree(unzip_dir)

            raise

        def cleanup():
            shutil.rmtree(test_dir)
            os.remove(zip_file)
            shutil.rmtree(unzip_dir)
        request.addfinalizer(cleanup)

        return test_dir, zip_file, unzip_dir