<commit_before># -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2010, 2011 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""Unit tests for the inveniocfg script."""


import sys
import StringIO
import logging

from invenio.inveniocfg import main
from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase
from invenio.config import CFG_PREFIX


class InveniocfgTest(InvenioTestCase):
    """
    Test suite for inveniocfg
    """

    def setUp(self):
        """ Save original stdout/err so they can be set back. """
        self.default_stdout = sys.stdout
        self.default_stderr = sys.stderr
        self.output = None
        self.error = None

    def tearDown(self):
        """ Ensure that stdout/err capturing is stopped. """
        self.stop_capture()

    def stop_capture(self):
        """ Helper method to *stop* capture stdout and stderr """
        sys.stdout = self.default_stdout
        sys.stderr = self.default_stderr

        # Inveniocfg sets up some loggers
        # At shutdown, they try to close their stream so we close them here
        # in order to not leave them which a closed stream they will fail to
        # close
        logging.shutdown()

        if self.output:
            self.output.close()
        if self.error:
            self.error.close()

    def capture(self):
        """ Helper method to *start* capture stdout and stderr """
        if self.output:
            self.output.close()
        if self.error:
            self.error.close()
        self.output = StringIO.StringIO()
        self.error = StringIO.StringIO()
        sys.stdout = self.output
        sys.stderr = self.error

    def assertExitValue(self, exit_val, func, *args, **kwargs):
        """ Assert method to ensure a specific system exit value is called. """
        try:
            func(*args, **kwargs)
            self.fail()
        except SystemExit, e:
            self.assertEqual(exit_val, e.code)

    #
    # Tests
    #
    def test_invalid_cmd(self):<commit_msg>inveniocfg: stop logging capture fix<commit_after># -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2010, 2011 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""Unit tests for the inveniocfg script."""


import sys
import StringIO
import logging

from invenio.inveniocfg import main
from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase
from invenio.config import CFG_PREFIX


class InveniocfgTest(InvenioTestCase):
    """
    Test suite for inveniocfg
    """

    def setUp(self):
        """ Save original stdout/err so they can be set back. """
        self.default_stdout = sys.stdout
        self.default_stderr = sys.stderr
        self.output = None
        self.error = None

    def tearDown(self):
        """ Ensure that stdout/err capturing is stopped. """
        self.stop_capture()

    def stop_capture(self):
        """ Helper method to *stop* capture stdout and stderr """
        sys.stdout = self.default_stdout
        sys.stderr = self.default_stderr

        # Inveniocfg sets up some loggers
        # At shutdown, they try to close their stream so we close them here
        # in order to not leave them which a closed stream they will fail to
        # close
        try:
            logging.shutdown()
        except:
            # No loggers are open?
            pass

        if self.output:
            self.output.close()
        if self.error:
            self.error.close()

    def capture(self):
        """ Helper method to *start* capture stdout and stderr """
        if self.output:
            self.output.close()
        if self.error:
            self.error.close()
        self.output = StringIO.StringIO()
        self.error = StringIO.StringIO()
        sys.stdout = self.output
        sys.stderr = self.error

    def assertExitValue(self, exit_val, func, *args, **kwargs):
        """ Assert method to ensure a specific system exit value is called. """
        try:
            func(*args, **kwargs)
            self.fail()
        except SystemExit, e:
            self.assertEqual(exit_val, e.code)

    #
    # Tests
    #
    def test_invalid_cmd(self):
{'fraction_non_alphanumeric': 0.08941473988439307, 'fraction_numerical': 0.008670520231213872, 'mean_word_length': 2.5155555555555558, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2226313', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1507, 'n_words': 592}