<commit_before>"""
Tests for the future.standard_library module
"""

from __future__ import absolute_import, unicode_literals, print_function
from future import standard_library
from future import six

import sys
import textwrap
import unittest
from subprocess import check_output

from future.standard_library import RENAMES, REPLACED_MODULES


class TestStandardLibraryRenames(unittest.TestCase):

    def setUp(self):
        self.interpreter = 'python'

    @unittest.skipIf(six.PY3, 'generic import tests are for Py2 only')
    def test_all(self):
        """
        Tests whether all of the old imports in RENAMES are accessible
        under their new names.
        """
        for (oldname, newname) in RENAMES.items():
            if newname == 'winreg' and sys.platform not in ['win32', 'win64']:
                continue
            if newname in REPLACED_MODULES:
                # Skip this check for e.g. the stdlib's ``test`` module,
                # which we have replaced completely.
                continue
            oldmod = __import__(oldname)
            newmod = __import__(newname)
            if '.' not in oldname:
                self.assertEqual(oldmod, newmod)

    def test_old_urllib_import(self):
        """
        Tests whether an imported module can import the old urllib package.
        """
        code1 = '''
                from future import standard_library
                import module_importing_old_urllib
                '''
        code2 = '''
                import urllib
                assert 'urlopen' in dir(urllib)
                print('Import succeeded!')
                '''
        with open('runme.py', 'w') as f:
            f.write(textwrap.dedent(code1))
        with open('module_importing_old_urllib.py', 'w') as f:
            f.write(textwrap.dedent(code2))
        output = check_output([self.interpreter, 'runme.py'])
        print(output)
        self.assertTrue(True)

    def test_sys_intern(self):
        """
        Py2's builtin intern() has been moved to the sys module. Tests whether sys.intern is
        available.
        """<commit_msg>Skip test for old urllib.py on Py3<commit_after>"""
Tests for the future.standard_library module
"""

from __future__ import absolute_import, unicode_literals, print_function
from future import standard_library
from future import six

import sys
import textwrap
import unittest
from subprocess import check_output

from future.standard_library import RENAMES, REPLACED_MODULES


class TestStandardLibraryRenames(unittest.TestCase):

    def setUp(self):
        self.interpreter = 'python'

    @unittest.skipIf(six.PY3, 'generic import tests are for Py2 only')
    def test_all(self):
        """
        Tests whether all of the old imports in RENAMES are accessible
        under their new names.
        """
        for (oldname, newname) in RENAMES.items():
            if newname == 'winreg' and sys.platform not in ['win32', 'win64']:
                continue
            if newname in REPLACED_MODULES:
                # Skip this check for e.g. the stdlib's ``test`` module,
                # which we have replaced completely.
                continue
            oldmod = __import__(oldname)
            newmod = __import__(newname)
            if '.' not in oldname:
                self.assertEqual(oldmod, newmod)

    @unittest.skipIf(six.PY3, 'not testing for old urllib on Py3')
    def test_old_urllib_import(self):
        """
        Tests whether an imported module can import the old urllib package.
        """
        code1 = '''
                from future import standard_library
                import module_importing_old_urllib
                '''
        code2 = '''
                import urllib
                assert 'urlopen' in dir(urllib)
                print('Import succeeded!')
                '''
        with open('runme.py', 'w') as f:
            f.write(textwrap.dedent(code1))
        with open('module_importing_old_urllib.py', 'w') as f:
            f.write(textwrap.dedent(code2))
        output = check_output([self.interpreter, 'runme.py'])
        print(output)
        self.assertTrue(True)

    def test_sys_intern(self):
        """
        Py2's builtin intern() has been moved to the sys module. Tests whether sys.intern is
        available.
        """
{'fraction_non_alphanumeric': 0.08606368251038302, 'fraction_numerical': 0.005768343331795108, 'mean_word_length': 2.1142241379310347, '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': '361293', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1191, 'n_words': 360}