# Path: pyqi/util.py
# def is_py2():
#     """Check if we're using Python 2"""
#     if sys.version_info.major == 2:
#         return True
#     else:
#         return False
# 
# Path: pyqi/core/interfaces/optparse/output_handler.py
# def write_string(result_key, data, option_value=None):
#     """Write a string to a file.
#     
#     A newline will be added to the end of the file.
#     """
#     if option_value is None:
#         raise IncompetentDeveloperError("Cannot write output without a "
#                                         "filepath.")
# 
#     if os.path.exists(option_value):
#         raise IOError("Output path '%s' already exists." % option_value)
# 
#     with open(option_value, 'w') as f:
#         f.write(data)
#         f.write('\n')
# 
# def write_list_of_strings(result_key, data, option_value=None):
#     """Write a list of strings to a file, one per line.
#     
#     A newline will be added to the end of the file.
#     """
#     if option_value is None:
#         raise IncompetentDeveloperError("Cannot write output without a "
#                                         "filepath.")
# 
#     if os.path.exists(option_value):
#         raise IOError("Output path '%s' already exists." % option_value)
# 
#     with open(option_value, 'w') as f:
#         for line in data:
#             f.write(line)
#             f.write('\n')
# 
# def print_list_of_strings(result_key, data, option_value=None):
#     """Print a list of strings to stdout, one per line.
# 
#     ``result_key`` and ``option_value`` are ignored.
#     """
#     for line in data:
#         print(line)
# 
# Path: pyqi/core/exception.py
# class IncompetentDeveloperError(CommandError):
#     pass


import os
import sys
from pyqi.util import is_py2
    from StringIO import StringIO
    from io import StringIO
from shutil import rmtree
from tempfile import mkdtemp
from unittest import TestCase, main
from pyqi.core.interfaces.optparse.output_handler import (write_string,
        write_list_of_strings, print_list_of_strings)
from pyqi.core.exception import IncompetentDeveloperError
               "Jai Ram Rideout"]



if is_py2():
else:


class OutputHandlerTests(TestCase):
    def setUp(self):
        self.output_dir = mkdtemp()
        self.fp = os.path.join(self.output_dir, 'test_file.txt')

    def tearDown(self):
        rmtree(self.output_dir)

    def test_write_string(self):
        """Correctly writes a string to file."""
        # can't write without a path
        self.assertRaises(IncompetentDeveloperError, write_string, 'a','b')

        write_string('foo', 'bar', self.fp)
        with open(self.fp, 'U') as obs_f:
            obs = obs_f.read()

        self.assertEqual(obs, 'bar\n')

    def test_write_list_of_strings(self):
        """Correctly writes a list of strings to file."""
        # can't write without a path

# Path: pyqi/util.py
# def is_py2():
#     """Check if we're using Python 2"""
#     if sys.version_info.major == 2:
#         return True
#     else:
#         return False
# 
# Path: pyqi/core/interfaces/optparse/output_handler.py
# def write_string(result_key, data, option_value=None):
#     """Write a string to a file.
#     
#     A newline will be added to the end of the file.
#     """
#     if option_value is None:
#         raise IncompetentDeveloperError("Cannot write output without a "
#                                         "filepath.")
# 
#     if os.path.exists(option_value):
#         raise IOError("Output path '%s' already exists." % option_value)
# 
#     with open(option_value, 'w') as f:
#         f.write(data)
#         f.write('\n')
# 
# def write_list_of_strings(result_key, data, option_value=None):
#     """Write a list of strings to a file, one per line.
#     
#     A newline will be added to the end of the file.
#     """
#     if option_value is None:
#         raise IncompetentDeveloperError("Cannot write output without a "
#                                         "filepath.")
# 
#     if os.path.exists(option_value):
#         raise IOError("Output path '%s' already exists." % option_value)
# 
#     with open(option_value, 'w') as f:
#         for line in data:
#             f.write(line)
#             f.write('\n')
# 
# def print_list_of_strings(result_key, data, option_value=None):
#     """Print a list of strings to stdout, one per line.
# 
#     ``result_key`` and ``option_value`` are ignored.
#     """
#     for line in data:
#         print(line)
# 
# Path: pyqi/core/exception.py
# class IncompetentDeveloperError(CommandError):
#     pass


# Path: tests/test_core/test_interfaces/test_optparse/test_output_handler.py
import os
import sys
from pyqi.util import is_py2
    from StringIO import StringIO
    from io import StringIO
from shutil import rmtree
from tempfile import mkdtemp
from unittest import TestCase, main
from pyqi.core.interfaces.optparse.output_handler import (write_string,
        write_list_of_strings, print_list_of_strings)
from pyqi.core.exception import IncompetentDeveloperError

               "Jai Ram Rideout"]



if is_py2():
else:


class OutputHandlerTests(TestCase):
    def setUp(self):
        self.output_dir = mkdtemp()
        self.fp = os.path.join(self.output_dir, 'test_file.txt')

    def tearDown(self):
        rmtree(self.output_dir)

    def test_write_string(self):
        """Correctly writes a string to file."""
        # can't write without a path
        self.assertRaises(IncompetentDeveloperError, write_string, 'a','b')

        write_string('foo', 'bar', self.fp)
        with open(self.fp, 'U') as obs_f:
            obs = obs_f.read()

        self.assertEqual(obs, 'bar\n')

    def test_write_list_of_strings(self):
        """Correctly writes a list of strings to file."""
        # can't write without a path

        self.assertRaises(IncompetentDeveloperError, write_list_of_strings,