ยปCore Development>Code coverage>Lib/test/test_importlib/source/test_file_loader.py

Python code coverage for Lib/test/test_importlib/source/test_file_loader.py

#countcontent
1n/afrom .. import abc
2n/afrom .. import util
3n/a
4n/aimportlib = util.import_importlib('importlib')
5n/aimportlib_abc = util.import_importlib('importlib.abc')
6n/amachinery = util.import_importlib('importlib.machinery')
7n/aimportlib_util = util.import_importlib('importlib.util')
8n/a
9n/aimport errno
10n/aimport marshal
11n/aimport os
12n/aimport py_compile
13n/aimport shutil
14n/aimport stat
15n/aimport sys
16n/aimport types
17n/aimport unittest
18n/aimport warnings
19n/a
20n/afrom test.support import make_legacy_pyc, unload
21n/a
22n/a
23n/aclass SimpleTest(abc.LoaderTests):
24n/a
25n/a """Should have no issue importing a source module [basic]. And if there is
26n/a a syntax error, it should raise a SyntaxError [syntax error].
27n/a
28n/a """
29n/a
30n/a def setUp(self):
31n/a self.name = 'spam'
32n/a self.filepath = os.path.join('ham', self.name + '.py')
33n/a self.loader = self.machinery.SourceFileLoader(self.name, self.filepath)
34n/a
35n/a def test_load_module_API(self):
36n/a class Tester(self.abc.FileLoader):
37n/a def get_source(self, _): return 'attr = 42'
38n/a def is_package(self, _): return False
39n/a
40n/a loader = Tester('blah', 'blah.py')
41n/a self.addCleanup(unload, 'blah')
42n/a with warnings.catch_warnings():
43n/a warnings.simplefilter('ignore', DeprecationWarning)
44n/a module = loader.load_module() # Should not raise an exception.
45n/a
46n/a def test_get_filename_API(self):
47n/a # If fullname is not set then assume self.path is desired.
48n/a class Tester(self.abc.FileLoader):
49n/a def get_code(self, _): pass
50n/a def get_source(self, _): pass
51n/a def is_package(self, _): pass
52n/a def module_repr(self, _): pass
53n/a
54n/a path = 'some_path'
55n/a name = 'some_name'
56n/a loader = Tester(name, path)
57n/a self.assertEqual(path, loader.get_filename(name))
58n/a self.assertEqual(path, loader.get_filename())
59n/a self.assertEqual(path, loader.get_filename(None))
60n/a with self.assertRaises(ImportError):
61n/a loader.get_filename(name + 'XXX')
62n/a
63n/a def test_equality(self):
64n/a other = self.machinery.SourceFileLoader(self.name, self.filepath)
65n/a self.assertEqual(self.loader, other)
66n/a
67n/a def test_inequality(self):
68n/a other = self.machinery.SourceFileLoader('_' + self.name, self.filepath)
69n/a self.assertNotEqual(self.loader, other)
70n/a
71n/a # [basic]
72n/a def test_module(self):
73n/a with util.create_modules('_temp') as mapping:
74n/a loader = self.machinery.SourceFileLoader('_temp', mapping['_temp'])
75n/a with warnings.catch_warnings():
76n/a warnings.simplefilter('ignore', DeprecationWarning)
77n/a module = loader.load_module('_temp')
78n/a self.assertIn('_temp', sys.modules)
79n/a check = {'__name__': '_temp', '__file__': mapping['_temp'],
80n/a '__package__': ''}
81n/a for attr, value in check.items():
82n/a self.assertEqual(getattr(module, attr), value)
83n/a
84n/a def test_package(self):
85n/a with util.create_modules('_pkg.__init__') as mapping:
86n/a loader = self.machinery.SourceFileLoader('_pkg',
87n/a mapping['_pkg.__init__'])
88n/a with warnings.catch_warnings():
89n/a warnings.simplefilter('ignore', DeprecationWarning)
90n/a module = loader.load_module('_pkg')
91n/a self.assertIn('_pkg', sys.modules)
92n/a check = {'__name__': '_pkg', '__file__': mapping['_pkg.__init__'],
93n/a '__path__': [os.path.dirname(mapping['_pkg.__init__'])],
94n/a '__package__': '_pkg'}
95n/a for attr, value in check.items():
96n/a self.assertEqual(getattr(module, attr), value)
97n/a
98n/a
99n/a def test_lacking_parent(self):
100n/a with util.create_modules('_pkg.__init__', '_pkg.mod')as mapping:
101n/a loader = self.machinery.SourceFileLoader('_pkg.mod',
102n/a mapping['_pkg.mod'])
103n/a with warnings.catch_warnings():
104n/a warnings.simplefilter('ignore', DeprecationWarning)
105n/a module = loader.load_module('_pkg.mod')
106n/a self.assertIn('_pkg.mod', sys.modules)
107n/a check = {'__name__': '_pkg.mod', '__file__': mapping['_pkg.mod'],
108n/a '__package__': '_pkg'}
109n/a for attr, value in check.items():
110n/a self.assertEqual(getattr(module, attr), value)
111n/a
112n/a def fake_mtime(self, fxn):
113n/a """Fake mtime to always be higher than expected."""
114n/a return lambda name: fxn(name) + 1
115n/a
116n/a def test_module_reuse(self):
117n/a with util.create_modules('_temp') as mapping:
118n/a loader = self.machinery.SourceFileLoader('_temp', mapping['_temp'])
119n/a with warnings.catch_warnings():
120n/a warnings.simplefilter('ignore', DeprecationWarning)
121n/a module = loader.load_module('_temp')
122n/a module_id = id(module)
123n/a module_dict_id = id(module.__dict__)
124n/a with open(mapping['_temp'], 'w') as file:
125n/a file.write("testing_var = 42\n")
126n/a with warnings.catch_warnings():
127n/a warnings.simplefilter('ignore', DeprecationWarning)
128n/a module = loader.load_module('_temp')
129n/a self.assertIn('testing_var', module.__dict__,
130n/a "'testing_var' not in "
131n/a "{0}".format(list(module.__dict__.keys())))
132n/a self.assertEqual(module, sys.modules['_temp'])
133n/a self.assertEqual(id(module), module_id)
134n/a self.assertEqual(id(module.__dict__), module_dict_id)
135n/a
136n/a def test_state_after_failure(self):
137n/a # A failed reload should leave the original module intact.
138n/a attributes = ('__file__', '__path__', '__package__')
139n/a value = '<test>'
140n/a name = '_temp'
141n/a with util.create_modules(name) as mapping:
142n/a orig_module = types.ModuleType(name)
143n/a for attr in attributes:
144n/a setattr(orig_module, attr, value)
145n/a with open(mapping[name], 'w') as file:
146n/a file.write('+++ bad syntax +++')
147n/a loader = self.machinery.SourceFileLoader('_temp', mapping['_temp'])
148n/a with self.assertRaises(SyntaxError):
149n/a loader.exec_module(orig_module)
150n/a for attr in attributes:
151n/a self.assertEqual(getattr(orig_module, attr), value)
152n/a with self.assertRaises(SyntaxError):
153n/a with warnings.catch_warnings():
154n/a warnings.simplefilter('ignore', DeprecationWarning)
155n/a loader.load_module(name)
156n/a for attr in attributes:
157n/a self.assertEqual(getattr(orig_module, attr), value)
158n/a
159n/a # [syntax error]
160n/a def test_bad_syntax(self):
161n/a with util.create_modules('_temp') as mapping:
162n/a with open(mapping['_temp'], 'w') as file:
163n/a file.write('=')
164n/a loader = self.machinery.SourceFileLoader('_temp', mapping['_temp'])
165n/a with self.assertRaises(SyntaxError):
166n/a with warnings.catch_warnings():
167n/a warnings.simplefilter('ignore', DeprecationWarning)
168n/a loader.load_module('_temp')
169n/a self.assertNotIn('_temp', sys.modules)
170n/a
171n/a def test_file_from_empty_string_dir(self):
172n/a # Loading a module found from an empty string entry on sys.path should
173n/a # not only work, but keep all attributes relative.
174n/a file_path = '_temp.py'
175n/a with open(file_path, 'w') as file:
176n/a file.write("# test file for importlib")
177n/a try:
178n/a with util.uncache('_temp'):
179n/a loader = self.machinery.SourceFileLoader('_temp', file_path)
180n/a with warnings.catch_warnings():
181n/a warnings.simplefilter('ignore', DeprecationWarning)
182n/a mod = loader.load_module('_temp')
183n/a self.assertEqual(file_path, mod.__file__)
184n/a self.assertEqual(self.util.cache_from_source(file_path),
185n/a mod.__cached__)
186n/a finally:
187n/a os.unlink(file_path)
188n/a pycache = os.path.dirname(self.util.cache_from_source(file_path))
189n/a if os.path.exists(pycache):
190n/a shutil.rmtree(pycache)
191n/a
192n/a @util.writes_bytecode_files
193n/a def test_timestamp_overflow(self):
194n/a # When a modification timestamp is larger than 2**32, it should be
195n/a # truncated rather than raise an OverflowError.
196n/a with util.create_modules('_temp') as mapping:
197n/a source = mapping['_temp']
198n/a compiled = self.util.cache_from_source(source)
199n/a with open(source, 'w') as f:
200n/a f.write("x = 5")
201n/a try:
202n/a os.utime(source, (2 ** 33 - 5, 2 ** 33 - 5))
203n/a except OverflowError:
204n/a self.skipTest("cannot set modification time to large integer")
205n/a except OSError as e:
206n/a if e.errno != getattr(errno, 'EOVERFLOW', None):
207n/a raise
208n/a self.skipTest("cannot set modification time to large integer ({})".format(e))
209n/a loader = self.machinery.SourceFileLoader('_temp', mapping['_temp'])
210n/a # PEP 451
211n/a module = types.ModuleType('_temp')
212n/a module.__spec__ = self.util.spec_from_loader('_temp', loader)
213n/a loader.exec_module(module)
214n/a self.assertEqual(module.x, 5)
215n/a self.assertTrue(os.path.exists(compiled))
216n/a os.unlink(compiled)
217n/a # PEP 302
218n/a with warnings.catch_warnings():
219n/a warnings.simplefilter('ignore', DeprecationWarning)
220n/a mod = loader.load_module('_temp')
221n/a # Sanity checks.
222n/a self.assertEqual(mod.__cached__, compiled)
223n/a self.assertEqual(mod.x, 5)
224n/a # The pyc file was created.
225n/a self.assertTrue(os.path.exists(compiled))
226n/a
227n/a def test_unloadable(self):
228n/a loader = self.machinery.SourceFileLoader('good name', {})
229n/a module = types.ModuleType('bad name')
230n/a module.__spec__ = self.machinery.ModuleSpec('bad name', loader)
231n/a with self.assertRaises(ImportError):
232n/a loader.exec_module(module)
233n/a with self.assertRaises(ImportError):
234n/a with warnings.catch_warnings():
235n/a warnings.simplefilter('ignore', DeprecationWarning)
236n/a loader.load_module('bad name')
237n/a
238n/a
239n/a(Frozen_SimpleTest,
240n/a Source_SimpleTest
241n/a ) = util.test_both(SimpleTest, importlib=importlib, machinery=machinery,
242n/a abc=importlib_abc, util=importlib_util)
243n/a
244n/a
245n/aclass BadBytecodeTest:
246n/a
247n/a def import_(self, file, module_name):
248n/a raise NotImplementedError
249n/a
250n/a def manipulate_bytecode(self, name, mapping, manipulator, *,
251n/a del_source=False):
252n/a """Manipulate the bytecode of a module by passing it into a callable
253n/a that returns what to use as the new bytecode."""
254n/a try:
255n/a del sys.modules['_temp']
256n/a except KeyError:
257n/a pass
258n/a py_compile.compile(mapping[name])
259n/a if not del_source:
260n/a bytecode_path = self.util.cache_from_source(mapping[name])
261n/a else:
262n/a os.unlink(mapping[name])
263n/a bytecode_path = make_legacy_pyc(mapping[name])
264n/a if manipulator:
265n/a with open(bytecode_path, 'rb') as file:
266n/a bc = file.read()
267n/a new_bc = manipulator(bc)
268n/a with open(bytecode_path, 'wb') as file:
269n/a if new_bc is not None:
270n/a file.write(new_bc)
271n/a return bytecode_path
272n/a
273n/a def _test_empty_file(self, test, *, del_source=False):
274n/a with util.create_modules('_temp') as mapping:
275n/a bc_path = self.manipulate_bytecode('_temp', mapping,
276n/a lambda bc: b'',
277n/a del_source=del_source)
278n/a test('_temp', mapping, bc_path)
279n/a
280n/a @util.writes_bytecode_files
281n/a def _test_partial_magic(self, test, *, del_source=False):
282n/a # When their are less than 4 bytes to a .pyc, regenerate it if
283n/a # possible, else raise ImportError.
284n/a with util.create_modules('_temp') as mapping:
285n/a bc_path = self.manipulate_bytecode('_temp', mapping,
286n/a lambda bc: bc[:3],
287n/a del_source=del_source)
288n/a test('_temp', mapping, bc_path)
289n/a
290n/a def _test_magic_only(self, test, *, del_source=False):
291n/a with util.create_modules('_temp') as mapping:
292n/a bc_path = self.manipulate_bytecode('_temp', mapping,
293n/a lambda bc: bc[:4],
294n/a del_source=del_source)
295n/a test('_temp', mapping, bc_path)
296n/a
297n/a def _test_partial_timestamp(self, test, *, del_source=False):
298n/a with util.create_modules('_temp') as mapping:
299n/a bc_path = self.manipulate_bytecode('_temp', mapping,
300n/a lambda bc: bc[:7],
301n/a del_source=del_source)
302n/a test('_temp', mapping, bc_path)
303n/a
304n/a def _test_partial_size(self, test, *, del_source=False):
305n/a with util.create_modules('_temp') as mapping:
306n/a bc_path = self.manipulate_bytecode('_temp', mapping,
307n/a lambda bc: bc[:11],
308n/a del_source=del_source)
309n/a test('_temp', mapping, bc_path)
310n/a
311n/a def _test_no_marshal(self, *, del_source=False):
312n/a with util.create_modules('_temp') as mapping:
313n/a bc_path = self.manipulate_bytecode('_temp', mapping,
314n/a lambda bc: bc[:12],
315n/a del_source=del_source)
316n/a file_path = mapping['_temp'] if not del_source else bc_path
317n/a with self.assertRaises(EOFError):
318n/a self.import_(file_path, '_temp')
319n/a
320n/a def _test_non_code_marshal(self, *, del_source=False):
321n/a with util.create_modules('_temp') as mapping:
322n/a bytecode_path = self.manipulate_bytecode('_temp', mapping,
323n/a lambda bc: bc[:12] + marshal.dumps(b'abcd'),
324n/a del_source=del_source)
325n/a file_path = mapping['_temp'] if not del_source else bytecode_path
326n/a with self.assertRaises(ImportError) as cm:
327n/a self.import_(file_path, '_temp')
328n/a self.assertEqual(cm.exception.name, '_temp')
329n/a self.assertEqual(cm.exception.path, bytecode_path)
330n/a
331n/a def _test_bad_marshal(self, *, del_source=False):
332n/a with util.create_modules('_temp') as mapping:
333n/a bytecode_path = self.manipulate_bytecode('_temp', mapping,
334n/a lambda bc: bc[:12] + b'<test>',
335n/a del_source=del_source)
336n/a file_path = mapping['_temp'] if not del_source else bytecode_path
337n/a with self.assertRaises(EOFError):
338n/a self.import_(file_path, '_temp')
339n/a
340n/a def _test_bad_magic(self, test, *, del_source=False):
341n/a with util.create_modules('_temp') as mapping:
342n/a bc_path = self.manipulate_bytecode('_temp', mapping,
343n/a lambda bc: b'\x00\x00\x00\x00' + bc[4:])
344n/a test('_temp', mapping, bc_path)
345n/a
346n/a
347n/aclass BadBytecodeTestPEP451(BadBytecodeTest):
348n/a
349n/a def import_(self, file, module_name):
350n/a loader = self.loader(module_name, file)
351n/a module = types.ModuleType(module_name)
352n/a module.__spec__ = self.util.spec_from_loader(module_name, loader)
353n/a loader.exec_module(module)
354n/a
355n/a
356n/aclass BadBytecodeTestPEP302(BadBytecodeTest):
357n/a
358n/a def import_(self, file, module_name):
359n/a loader = self.loader(module_name, file)
360n/a with warnings.catch_warnings():
361n/a warnings.simplefilter('ignore', DeprecationWarning)
362n/a module = loader.load_module(module_name)
363n/a self.assertIn(module_name, sys.modules)
364n/a
365n/a
366n/aclass SourceLoaderBadBytecodeTest:
367n/a
368n/a @classmethod
369n/a def setUpClass(cls):
370n/a cls.loader = cls.machinery.SourceFileLoader
371n/a
372n/a @util.writes_bytecode_files
373n/a def test_empty_file(self):
374n/a # When a .pyc is empty, regenerate it if possible, else raise
375n/a # ImportError.
376n/a def test(name, mapping, bytecode_path):
377n/a self.import_(mapping[name], name)
378n/a with open(bytecode_path, 'rb') as file:
379n/a self.assertGreater(len(file.read()), 12)
380n/a
381n/a self._test_empty_file(test)
382n/a
383n/a def test_partial_magic(self):
384n/a def test(name, mapping, bytecode_path):
385n/a self.import_(mapping[name], name)
386n/a with open(bytecode_path, 'rb') as file:
387n/a self.assertGreater(len(file.read()), 12)
388n/a
389n/a self._test_partial_magic(test)
390n/a
391n/a @util.writes_bytecode_files
392n/a def test_magic_only(self):
393n/a # When there is only the magic number, regenerate the .pyc if possible,
394n/a # else raise EOFError.
395n/a def test(name, mapping, bytecode_path):
396n/a self.import_(mapping[name], name)
397n/a with open(bytecode_path, 'rb') as file:
398n/a self.assertGreater(len(file.read()), 12)
399n/a
400n/a self._test_magic_only(test)
401n/a
402n/a @util.writes_bytecode_files
403n/a def test_bad_magic(self):
404n/a # When the magic number is different, the bytecode should be
405n/a # regenerated.
406n/a def test(name, mapping, bytecode_path):
407n/a self.import_(mapping[name], name)
408n/a with open(bytecode_path, 'rb') as bytecode_file:
409n/a self.assertEqual(bytecode_file.read(4),
410n/a self.util.MAGIC_NUMBER)
411n/a
412n/a self._test_bad_magic(test)
413n/a
414n/a @util.writes_bytecode_files
415n/a def test_partial_timestamp(self):
416n/a # When the timestamp is partial, regenerate the .pyc, else
417n/a # raise EOFError.
418n/a def test(name, mapping, bc_path):
419n/a self.import_(mapping[name], name)
420n/a with open(bc_path, 'rb') as file:
421n/a self.assertGreater(len(file.read()), 12)
422n/a
423n/a self._test_partial_timestamp(test)
424n/a
425n/a @util.writes_bytecode_files
426n/a def test_partial_size(self):
427n/a # When the size is partial, regenerate the .pyc, else
428n/a # raise EOFError.
429n/a def test(name, mapping, bc_path):
430n/a self.import_(mapping[name], name)
431n/a with open(bc_path, 'rb') as file:
432n/a self.assertGreater(len(file.read()), 12)
433n/a
434n/a self._test_partial_size(test)
435n/a
436n/a @util.writes_bytecode_files
437n/a def test_no_marshal(self):
438n/a # When there is only the magic number and timestamp, raise EOFError.
439n/a self._test_no_marshal()
440n/a
441n/a @util.writes_bytecode_files
442n/a def test_non_code_marshal(self):
443n/a self._test_non_code_marshal()
444n/a # XXX ImportError when sourceless
445n/a
446n/a # [bad marshal]
447n/a @util.writes_bytecode_files
448n/a def test_bad_marshal(self):
449n/a # Bad marshal data should raise a ValueError.
450n/a self._test_bad_marshal()
451n/a
452n/a # [bad timestamp]
453n/a @util.writes_bytecode_files
454n/a def test_old_timestamp(self):
455n/a # When the timestamp is older than the source, bytecode should be
456n/a # regenerated.
457n/a zeros = b'\x00\x00\x00\x00'
458n/a with util.create_modules('_temp') as mapping:
459n/a py_compile.compile(mapping['_temp'])
460n/a bytecode_path = self.util.cache_from_source(mapping['_temp'])
461n/a with open(bytecode_path, 'r+b') as bytecode_file:
462n/a bytecode_file.seek(4)
463n/a bytecode_file.write(zeros)
464n/a self.import_(mapping['_temp'], '_temp')
465n/a source_mtime = os.path.getmtime(mapping['_temp'])
466n/a source_timestamp = self.importlib._w_long(source_mtime)
467n/a with open(bytecode_path, 'rb') as bytecode_file:
468n/a bytecode_file.seek(4)
469n/a self.assertEqual(bytecode_file.read(4), source_timestamp)
470n/a
471n/a # [bytecode read-only]
472n/a @util.writes_bytecode_files
473n/a def test_read_only_bytecode(self):
474n/a # When bytecode is read-only but should be rewritten, fail silently.
475n/a with util.create_modules('_temp') as mapping:
476n/a # Create bytecode that will need to be re-created.
477n/a py_compile.compile(mapping['_temp'])
478n/a bytecode_path = self.util.cache_from_source(mapping['_temp'])
479n/a with open(bytecode_path, 'r+b') as bytecode_file:
480n/a bytecode_file.seek(0)
481n/a bytecode_file.write(b'\x00\x00\x00\x00')
482n/a # Make the bytecode read-only.
483n/a os.chmod(bytecode_path,
484n/a stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
485n/a try:
486n/a # Should not raise OSError!
487n/a self.import_(mapping['_temp'], '_temp')
488n/a finally:
489n/a # Make writable for eventual clean-up.
490n/a os.chmod(bytecode_path, stat.S_IWUSR)
491n/a
492n/a
493n/aclass SourceLoaderBadBytecodeTestPEP451(
494n/a SourceLoaderBadBytecodeTest, BadBytecodeTestPEP451):
495n/a pass
496n/a
497n/a
498n/a(Frozen_SourceBadBytecodePEP451,
499n/a Source_SourceBadBytecodePEP451
500n/a ) = util.test_both(SourceLoaderBadBytecodeTestPEP451, importlib=importlib,
501n/a machinery=machinery, abc=importlib_abc,
502n/a util=importlib_util)
503n/a
504n/a
505n/aclass SourceLoaderBadBytecodeTestPEP302(
506n/a SourceLoaderBadBytecodeTest, BadBytecodeTestPEP302):
507n/a pass
508n/a
509n/a
510n/a(Frozen_SourceBadBytecodePEP302,
511n/a Source_SourceBadBytecodePEP302
512n/a ) = util.test_both(SourceLoaderBadBytecodeTestPEP302, importlib=importlib,
513n/a machinery=machinery, abc=importlib_abc,
514n/a util=importlib_util)
515n/a
516n/a
517n/aclass SourcelessLoaderBadBytecodeTest:
518n/a
519n/a @classmethod
520n/a def setUpClass(cls):
521n/a cls.loader = cls.machinery.SourcelessFileLoader
522n/a
523n/a def test_empty_file(self):
524n/a def test(name, mapping, bytecode_path):
525n/a with self.assertRaises(ImportError) as cm:
526n/a self.import_(bytecode_path, name)
527n/a self.assertEqual(cm.exception.name, name)
528n/a self.assertEqual(cm.exception.path, bytecode_path)
529n/a
530n/a self._test_empty_file(test, del_source=True)
531n/a
532n/a def test_partial_magic(self):
533n/a def test(name, mapping, bytecode_path):
534n/a with self.assertRaises(ImportError) as cm:
535n/a self.import_(bytecode_path, name)
536n/a self.assertEqual(cm.exception.name, name)
537n/a self.assertEqual(cm.exception.path, bytecode_path)
538n/a self._test_partial_magic(test, del_source=True)
539n/a
540n/a def test_magic_only(self):
541n/a def test(name, mapping, bytecode_path):
542n/a with self.assertRaises(EOFError):
543n/a self.import_(bytecode_path, name)
544n/a
545n/a self._test_magic_only(test, del_source=True)
546n/a
547n/a def test_bad_magic(self):
548n/a def test(name, mapping, bytecode_path):
549n/a with self.assertRaises(ImportError) as cm:
550n/a self.import_(bytecode_path, name)
551n/a self.assertEqual(cm.exception.name, name)
552n/a self.assertEqual(cm.exception.path, bytecode_path)
553n/a
554n/a self._test_bad_magic(test, del_source=True)
555n/a
556n/a def test_partial_timestamp(self):
557n/a def test(name, mapping, bytecode_path):
558n/a with self.assertRaises(EOFError):
559n/a self.import_(bytecode_path, name)
560n/a
561n/a self._test_partial_timestamp(test, del_source=True)
562n/a
563n/a def test_partial_size(self):
564n/a def test(name, mapping, bytecode_path):
565n/a with self.assertRaises(EOFError):
566n/a self.import_(bytecode_path, name)
567n/a
568n/a self._test_partial_size(test, del_source=True)
569n/a
570n/a def test_no_marshal(self):
571n/a self._test_no_marshal(del_source=True)
572n/a
573n/a def test_non_code_marshal(self):
574n/a self._test_non_code_marshal(del_source=True)
575n/a
576n/a
577n/aclass SourcelessLoaderBadBytecodeTestPEP451(SourcelessLoaderBadBytecodeTest,
578n/a BadBytecodeTestPEP451):
579n/a pass
580n/a
581n/a
582n/a(Frozen_SourcelessBadBytecodePEP451,
583n/a Source_SourcelessBadBytecodePEP451
584n/a ) = util.test_both(SourcelessLoaderBadBytecodeTestPEP451, importlib=importlib,
585n/a machinery=machinery, abc=importlib_abc,
586n/a util=importlib_util)
587n/a
588n/a
589n/aclass SourcelessLoaderBadBytecodeTestPEP302(SourcelessLoaderBadBytecodeTest,
590n/a BadBytecodeTestPEP302):
591n/a pass
592n/a
593n/a
594n/a(Frozen_SourcelessBadBytecodePEP302,
595n/a Source_SourcelessBadBytecodePEP302
596n/a ) = util.test_both(SourcelessLoaderBadBytecodeTestPEP302, importlib=importlib,
597n/a machinery=machinery, abc=importlib_abc,
598n/a util=importlib_util)
599n/a
600n/a
601n/aif __name__ == '__main__':
602n/a unittest.main()