mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-07-28 12:58:29 -06:00
Removed the Requirement to Install Python and NodeJS (Now Bundled with Borealis)
This commit is contained in:
5
Dependencies/Python/Lib/test/test_importlib/frozen/__init__.py
vendored
Normal file
5
Dependencies/Python/Lib/test/test_importlib/frozen/__init__.py
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import os
|
||||
from test.support import load_package_tests
|
||||
|
||||
def load_tests(*args):
|
||||
return load_package_tests(os.path.dirname(__file__), *args)
|
4
Dependencies/Python/Lib/test/test_importlib/frozen/__main__.py
vendored
Normal file
4
Dependencies/Python/Lib/test/test_importlib/frozen/__main__.py
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
from . import load_tests
|
||||
import unittest
|
||||
|
||||
unittest.main()
|
183
Dependencies/Python/Lib/test/test_importlib/frozen/test_finder.py
vendored
Normal file
183
Dependencies/Python/Lib/test/test_importlib/frozen/test_finder.py
vendored
Normal file
@ -0,0 +1,183 @@
|
||||
from test.test_importlib import abc, util
|
||||
|
||||
machinery = util.import_importlib('importlib.machinery')
|
||||
|
||||
import os.path
|
||||
import unittest
|
||||
|
||||
from test.support import import_helper, REPO_ROOT, STDLIB_DIR
|
||||
|
||||
|
||||
def resolve_stdlib_file(name, ispkg=False):
|
||||
assert name
|
||||
if ispkg:
|
||||
return os.path.join(STDLIB_DIR, *name.split('.'), '__init__.py')
|
||||
else:
|
||||
return os.path.join(STDLIB_DIR, *name.split('.')) + '.py'
|
||||
|
||||
|
||||
class FindSpecTests(abc.FinderTests):
|
||||
|
||||
"""Test finding frozen modules."""
|
||||
|
||||
def find(self, name, **kwargs):
|
||||
finder = self.machinery.FrozenImporter
|
||||
with import_helper.frozen_modules():
|
||||
return finder.find_spec(name, **kwargs)
|
||||
|
||||
def check_basic(self, spec, name, ispkg=False):
|
||||
self.assertEqual(spec.name, name)
|
||||
self.assertIs(spec.loader, self.machinery.FrozenImporter)
|
||||
self.assertEqual(spec.origin, 'frozen')
|
||||
self.assertFalse(spec.has_location)
|
||||
if ispkg:
|
||||
self.assertIsNotNone(spec.submodule_search_locations)
|
||||
else:
|
||||
self.assertIsNone(spec.submodule_search_locations)
|
||||
self.assertIsNotNone(spec.loader_state)
|
||||
|
||||
def check_loader_state(self, spec, origname=None, filename=None):
|
||||
if not filename:
|
||||
if not origname:
|
||||
origname = spec.name
|
||||
filename = resolve_stdlib_file(origname)
|
||||
|
||||
actual = dict(vars(spec.loader_state))
|
||||
|
||||
# Check the rest of spec.loader_state.
|
||||
expected = dict(
|
||||
origname=origname,
|
||||
filename=filename if origname else None,
|
||||
)
|
||||
self.assertDictEqual(actual, expected)
|
||||
|
||||
def check_search_locations(self, spec):
|
||||
"""This is only called when testing packages."""
|
||||
missing = object()
|
||||
filename = getattr(spec.loader_state, 'filename', missing)
|
||||
origname = getattr(spec.loader_state, 'origname', None)
|
||||
if not origname or filename is missing:
|
||||
# We deal with this in check_loader_state().
|
||||
return
|
||||
if not filename:
|
||||
expected = []
|
||||
elif origname != spec.name and not origname.startswith('<'):
|
||||
expected = []
|
||||
else:
|
||||
expected = [os.path.dirname(filename)]
|
||||
self.assertListEqual(spec.submodule_search_locations, expected)
|
||||
|
||||
def test_module(self):
|
||||
modules = [
|
||||
'__hello__',
|
||||
'__phello__.spam',
|
||||
'__phello__.ham.eggs',
|
||||
]
|
||||
for name in modules:
|
||||
with self.subTest(f'{name} -> {name}'):
|
||||
spec = self.find(name)
|
||||
self.check_basic(spec, name)
|
||||
self.check_loader_state(spec)
|
||||
modules = {
|
||||
'__hello_alias__': '__hello__',
|
||||
'_frozen_importlib': 'importlib._bootstrap',
|
||||
}
|
||||
for name, origname in modules.items():
|
||||
with self.subTest(f'{name} -> {origname}'):
|
||||
spec = self.find(name)
|
||||
self.check_basic(spec, name)
|
||||
self.check_loader_state(spec, origname)
|
||||
modules = [
|
||||
'__phello__.__init__',
|
||||
'__phello__.ham.__init__',
|
||||
]
|
||||
for name in modules:
|
||||
origname = '<' + name.rpartition('.')[0]
|
||||
filename = resolve_stdlib_file(name)
|
||||
with self.subTest(f'{name} -> {origname}'):
|
||||
spec = self.find(name)
|
||||
self.check_basic(spec, name)
|
||||
self.check_loader_state(spec, origname, filename)
|
||||
modules = {
|
||||
'__hello_only__': ('Tools', 'freeze', 'flag.py'),
|
||||
}
|
||||
for name, path in modules.items():
|
||||
origname = None
|
||||
filename = os.path.join(REPO_ROOT, *path)
|
||||
with self.subTest(f'{name} -> {filename}'):
|
||||
spec = self.find(name)
|
||||
self.check_basic(spec, name)
|
||||
self.check_loader_state(spec, origname, filename)
|
||||
|
||||
def test_package(self):
|
||||
packages = [
|
||||
'__phello__',
|
||||
'__phello__.ham',
|
||||
]
|
||||
for name in packages:
|
||||
filename = resolve_stdlib_file(name, ispkg=True)
|
||||
with self.subTest(f'{name} -> {name}'):
|
||||
spec = self.find(name)
|
||||
self.check_basic(spec, name, ispkg=True)
|
||||
self.check_loader_state(spec, name, filename)
|
||||
self.check_search_locations(spec)
|
||||
packages = {
|
||||
'__phello_alias__': '__hello__',
|
||||
}
|
||||
for name, origname in packages.items():
|
||||
filename = resolve_stdlib_file(origname, ispkg=False)
|
||||
with self.subTest(f'{name} -> {origname}'):
|
||||
spec = self.find(name)
|
||||
self.check_basic(spec, name, ispkg=True)
|
||||
self.check_loader_state(spec, origname, filename)
|
||||
self.check_search_locations(spec)
|
||||
|
||||
# These are covered by test_module() and test_package().
|
||||
test_module_in_package = None
|
||||
test_package_in_package = None
|
||||
|
||||
# No easy way to test.
|
||||
test_package_over_module = None
|
||||
|
||||
def test_path_ignored(self):
|
||||
for name in ('__hello__', '__phello__', '__phello__.spam'):
|
||||
actual = self.find(name)
|
||||
for path in (None, object(), '', 'eggs', [], [''], ['eggs']):
|
||||
with self.subTest((name, path)):
|
||||
spec = self.find(name, path=path)
|
||||
self.assertEqual(spec, actual)
|
||||
|
||||
def test_target_ignored(self):
|
||||
imported = ('__hello__', '__phello__')
|
||||
with import_helper.CleanImport(*imported, usefrozen=True):
|
||||
import __hello__ as match
|
||||
import __phello__ as nonmatch
|
||||
name = '__hello__'
|
||||
actual = self.find(name)
|
||||
for target in (None, match, nonmatch, object(), 'not-a-module-object'):
|
||||
with self.subTest(target):
|
||||
spec = self.find(name, target=target)
|
||||
self.assertEqual(spec, actual)
|
||||
|
||||
def test_failure(self):
|
||||
spec = self.find('<not real>')
|
||||
self.assertIsNone(spec)
|
||||
|
||||
def test_not_using_frozen(self):
|
||||
finder = self.machinery.FrozenImporter
|
||||
with import_helper.frozen_modules(enabled=False):
|
||||
# both frozen and not frozen
|
||||
spec1 = finder.find_spec('__hello__')
|
||||
# only frozen
|
||||
spec2 = finder.find_spec('__hello_only__')
|
||||
self.assertIsNone(spec1)
|
||||
self.assertIsNone(spec2)
|
||||
|
||||
|
||||
(Frozen_FindSpecTests,
|
||||
Source_FindSpecTests
|
||||
) = util.test_both(FindSpecTests, machinery=machinery)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
172
Dependencies/Python/Lib/test/test_importlib/frozen/test_loader.py
vendored
Normal file
172
Dependencies/Python/Lib/test/test_importlib/frozen/test_loader.py
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
from test.test_importlib import abc, util
|
||||
|
||||
machinery = util.import_importlib('importlib.machinery')
|
||||
|
||||
from test.support import captured_stdout, import_helper, STDLIB_DIR
|
||||
import contextlib
|
||||
import os.path
|
||||
import types
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def deprecated():
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', DeprecationWarning)
|
||||
yield
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def fresh(name, *, oldapi=False):
|
||||
with util.uncache(name):
|
||||
with import_helper.frozen_modules():
|
||||
if oldapi:
|
||||
with deprecated():
|
||||
yield
|
||||
else:
|
||||
yield
|
||||
|
||||
|
||||
def resolve_stdlib_file(name, ispkg=False):
|
||||
assert name
|
||||
if ispkg:
|
||||
return os.path.join(STDLIB_DIR, *name.split('.'), '__init__.py')
|
||||
else:
|
||||
return os.path.join(STDLIB_DIR, *name.split('.')) + '.py'
|
||||
|
||||
|
||||
class ExecModuleTests(abc.LoaderTests):
|
||||
|
||||
def exec_module(self, name, origname=None):
|
||||
with import_helper.frozen_modules():
|
||||
is_package = self.machinery.FrozenImporter.is_package(name)
|
||||
spec = self.machinery.ModuleSpec(
|
||||
name,
|
||||
self.machinery.FrozenImporter,
|
||||
origin='frozen',
|
||||
is_package=is_package,
|
||||
loader_state=types.SimpleNamespace(
|
||||
origname=origname or name,
|
||||
filename=resolve_stdlib_file(origname or name, is_package),
|
||||
),
|
||||
)
|
||||
module = types.ModuleType(name)
|
||||
module.__spec__ = spec
|
||||
assert not hasattr(module, 'initialized')
|
||||
|
||||
with fresh(name):
|
||||
self.machinery.FrozenImporter.exec_module(module)
|
||||
with captured_stdout() as stdout:
|
||||
module.main()
|
||||
|
||||
self.assertTrue(module.initialized)
|
||||
self.assertHasAttr(module, '__spec__')
|
||||
self.assertEqual(module.__spec__.origin, 'frozen')
|
||||
return module, stdout.getvalue()
|
||||
|
||||
def test_module(self):
|
||||
name = '__hello__'
|
||||
module, output = self.exec_module(name)
|
||||
check = {'__name__': name}
|
||||
for attr, value in check.items():
|
||||
self.assertEqual(getattr(module, attr), value)
|
||||
self.assertEqual(output, 'Hello world!\n')
|
||||
self.assertHasAttr(module, '__spec__')
|
||||
self.assertEqual(module.__spec__.loader_state.origname, name)
|
||||
|
||||
def test_package(self):
|
||||
name = '__phello__'
|
||||
module, output = self.exec_module(name)
|
||||
check = {'__name__': name}
|
||||
for attr, value in check.items():
|
||||
attr_value = getattr(module, attr)
|
||||
self.assertEqual(attr_value, value,
|
||||
'for {name}.{attr}, {given!r} != {expected!r}'.format(
|
||||
name=name, attr=attr, given=attr_value,
|
||||
expected=value))
|
||||
self.assertEqual(output, 'Hello world!\n')
|
||||
self.assertEqual(module.__spec__.loader_state.origname, name)
|
||||
|
||||
def test_lacking_parent(self):
|
||||
name = '__phello__.spam'
|
||||
with util.uncache('__phello__'):
|
||||
module, output = self.exec_module(name)
|
||||
check = {'__name__': name}
|
||||
for attr, value in check.items():
|
||||
attr_value = getattr(module, attr)
|
||||
self.assertEqual(attr_value, value,
|
||||
'for {name}.{attr}, {given} != {expected!r}'.format(
|
||||
name=name, attr=attr, given=attr_value,
|
||||
expected=value))
|
||||
self.assertEqual(output, 'Hello world!\n')
|
||||
|
||||
def test_module_repr_indirect_through_spec(self):
|
||||
name = '__hello__'
|
||||
module, output = self.exec_module(name)
|
||||
self.assertEqual(repr(module),
|
||||
"<module '__hello__' (frozen)>")
|
||||
|
||||
# No way to trigger an error in a frozen module.
|
||||
test_state_after_failure = None
|
||||
|
||||
def test_unloadable(self):
|
||||
with import_helper.frozen_modules():
|
||||
assert self.machinery.FrozenImporter.find_spec('_not_real') is None
|
||||
with self.assertRaises(ImportError) as cm:
|
||||
self.exec_module('_not_real')
|
||||
self.assertEqual(cm.exception.name, '_not_real')
|
||||
|
||||
|
||||
(Frozen_ExecModuleTests,
|
||||
Source_ExecModuleTests
|
||||
) = util.test_both(ExecModuleTests, machinery=machinery)
|
||||
|
||||
|
||||
class InspectLoaderTests:
|
||||
|
||||
"""Tests for the InspectLoader methods for FrozenImporter."""
|
||||
|
||||
def test_get_code(self):
|
||||
# Make sure that the code object is good.
|
||||
name = '__hello__'
|
||||
with import_helper.frozen_modules():
|
||||
code = self.machinery.FrozenImporter.get_code(name)
|
||||
mod = types.ModuleType(name)
|
||||
exec(code, mod.__dict__)
|
||||
with captured_stdout() as stdout:
|
||||
mod.main()
|
||||
self.assertHasAttr(mod, 'initialized')
|
||||
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
|
||||
|
||||
def test_get_source(self):
|
||||
# Should always return None.
|
||||
with import_helper.frozen_modules():
|
||||
result = self.machinery.FrozenImporter.get_source('__hello__')
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_is_package(self):
|
||||
# Should be able to tell what is a package.
|
||||
test_for = (('__hello__', False), ('__phello__', True),
|
||||
('__phello__.spam', False))
|
||||
for name, is_package in test_for:
|
||||
with import_helper.frozen_modules():
|
||||
result = self.machinery.FrozenImporter.is_package(name)
|
||||
self.assertEqual(bool(result), is_package)
|
||||
|
||||
def test_failure(self):
|
||||
# Raise ImportError for modules that are not frozen.
|
||||
for meth_name in ('get_code', 'get_source', 'is_package'):
|
||||
method = getattr(self.machinery.FrozenImporter, meth_name)
|
||||
with self.assertRaises(ImportError) as cm:
|
||||
with import_helper.frozen_modules():
|
||||
method('importlib')
|
||||
self.assertEqual(cm.exception.name, 'importlib')
|
||||
|
||||
(Frozen_ILTests,
|
||||
Source_ILTests
|
||||
) = util.test_both(InspectLoaderTests, machinery=machinery)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user