import importlib

from tests.builtin_frozen_help import BuiltinFrozen_Tester

import io
import sys
from test.test_support import run_unittest


class FrozenImporterTests(BuiltinFrozen_Tester):

    """Test the frozen module importer.
    
    Python include the __hello__ and __phello__  frozen modules (as defined in
    Python/frozen.c).  Both do output to the screen, though, which should be
    suppressed during testing.
    
    """

    importer = importlib.FrozenImporter()
    module_name = '__hello__'
    bad_module_names = ('tokenize', 'time', 'sys')

    def setUp(self):
        """Importing the testing frozen modules outputs to stdout.  Redirect
        stdout to block that."""
        self._orig_stdout = sys.stdout
        sys.stdout = io.StringIO()

    def tearDown(self):
        """Reset stdout to what it is by default."""
        sys.stdout = self._orig_stdout


class FrozenPackageInitTests(FrozenImporterTests):
    
    """Tests the frozen module import for package __init__ modules."""
    
    module_name = '__phello__'


class FrozenPackageModuleTests(FrozenImporterTests):

    """Tests the frozen module import for modules in packages."""
    
    module_name = '__phello__.spam'
    
class FrozenPackageInitTests(FrozenImporterTests):
    
    """Tests the frozen module import for package __init__ modules."""
    
    module_name = '__phello__'


def test_main():
    run_unittest(FrozenImporterTests, FrozenPackageInitTests, FrozenPackageModuleTests)



if __name__ == '__main__':
    test_main()
