# /test/testutil.py
#
# Some utility functions which make testing easier
#
# See /LICENCE.md for Copyright information
"""Some utility functions which make testing easier."""

import atexit

import os

import platform

import shutil

import socket

import subprocess

import sys

import tempfile

from contextlib import contextmanager

import ciscripts.bootstrap as bootstrap
import ciscripts.util as util

from nose_parameterized import parameterized

from six import StringIO

from testtools import TestCase
from testtools.content import text_content
from testtools.matchers import Mismatch

__file__ = os.path.abspath(__file__)


# Disabled task caching in the util module - if these tests
# are run in parallel we don't want other tests to cause our
# tests to skip certain (important!) tasks or return the
# wrong container dir.
setattr(util, "_NO_TASK_CACHING", True)


class CapturedOutput(object):  # suppress(too-few-public-methods)
    """Represents the captured contents of stdout and stderr."""

    def __init__(self):
        """Initialize the class."""
        super(CapturedOutput, self).__init__()
        self.stdout = ""
        self.stderr = ""

        self._stdout_handle = None
        self._stderr_handle = None

    def __enter__(self):
        """Start capturing output."""