Ejemplo n.º 1
0
 def set_config(self, **kwargs):
     _testinternalcapi.set_config(self.old_config | kwargs)
Ejemplo n.º 2
0
    def test_set_invalid(self):
        invalid_uint = -1
        NULL = None
        invalid_wstr = NULL
        # PyWideStringList strings must be non-NULL
        invalid_wstrlist = ["abc", NULL, "def"]

        type_tests = []
        value_tests = [
            # enum
            ('_config_init', 0),
            ('_config_init', 4),
            # unsigned long
            ("hash_seed", -1),
            ("hash_seed", MAX_HASH_SEED + 1),
        ]

        # int (unsigned)
        options = [
            '_config_init',
            'isolated',
            'use_environment',
            'dev_mode',
            'install_signal_handlers',
            'use_hash_seed',
            'faulthandler',
            'tracemalloc',
            'import_time',
            'code_debug_ranges',
            'show_ref_count',
            'dump_refs',
            'malloc_stats',
            'parse_argv',
            'site_import',
            'bytes_warning',
            'inspect',
            'interactive',
            'optimization_level',
            'parser_debug',
            'write_bytecode',
            'verbose',
            'quiet',
            'user_site_directory',
            'configure_c_stdio',
            'buffered_stdio',
            'pathconfig_warnings',
            'module_search_paths_set',
            'skip_source_first_line',
            '_install_importlib',
            '_init_main',
            '_isolated_interpreter',
        ]
        if MS_WINDOWS:
            options.append('legacy_windows_stdio')
        for key in options:
            value_tests.append((key, invalid_uint))
            type_tests.append((key, "abc"))
            type_tests.append((key, 2.0))

        # wchar_t*
        for key in (
                'filesystem_encoding',
                'filesystem_errors',
                'stdio_encoding',
                'stdio_errors',
                'check_hash_pycs_mode',
                'program_name',
                'platlibdir',
                # optional wstr:
                # 'pythonpath_env'
                # 'home'
                # 'pycache_prefix'
                # 'run_command'
                # 'run_module'
                # 'run_filename'
                # 'executable'
                # 'prefix'
                # 'exec_prefix'
                # 'base_executable'
                # 'base_prefix'
                # 'base_exec_prefix'
        ):
            value_tests.append((key, invalid_wstr))
            type_tests.append((key, b'bytes'))
            type_tests.append((key, 123))

        # PyWideStringList
        for key in (
                'orig_argv',
                'argv',
                'xoptions',
                'warnoptions',
                'module_search_paths',
        ):
            value_tests.append((key, invalid_wstrlist))
            type_tests.append((key, 123))
            type_tests.append((key, "abc"))
            type_tests.append((key, [123]))
            type_tests.append((key, [b"bytes"]))

        if MS_WINDOWS:
            value_tests.append(('legacy_windows_stdio', invalid_uint))

        for exc_type, tests in (
            (ValueError, value_tests),
            (TypeError, type_tests),
        ):
            for key, value in tests:
                config = self.old_config | {key: value}
                with self.subTest(key=key, value=value, exc_type=exc_type):
                    with self.assertRaises(exc_type):
                        _testinternalcapi.set_config(config)
Ejemplo n.º 3
0
 def tearDown(self):
     _testinternalcapi.reset_path_config()
     _testinternalcapi.set_config(self.old_config)
     sys.__dict__.clear()
     sys.__dict__.update(self.sys_copy)