<commit_before>#!/usr/bin/env python

#-----------------------------------------------------------------------------
# Copyright (c) 2013, The BiPy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

__credits__ = ["<NAME>", "<NAME>", "<NAME>",
               "<NAME>"]

import os
import sys

if sys.version_info.major == 2:
    from StringIO import StringIO
else:
    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

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<commit_msg>is_py2 check<commit_after>#!/usr/bin/env python

#-----------------------------------------------------------------------------
# Copyright (c) 2013, The BiPy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

__credits__ = ["<NAME>", "<NAME>", "<NAME>",
               "<NAME>"]

import os
import sys

from pyqi.util import is_py2

if is_py2():
    from StringIO import StringIO
else:
    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

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
{'fraction_non_alphanumeric': 0.21059164253206455, 'fraction_numerical': 0.004964832436905255, 'mean_word_length': 2.185770750988142, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7392575', 'n_tokens_mistral': 679, 'n_tokens_neox': 648, 'n_words': 201}