1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
# Verify that PyInstaller can load a script from a file with no extension, not just from ``.py`` files.
#
# Also check that both `__file__` attribute and the `co_filename` attribute of the code object have correct suffix.
import os
import sys
print('Hello!')
# Look up and display all relevant attributes...
print(f"__file__: {__file__}")
loader = sys.modules[__name__].__loader__
print(f"loader: {loader}")
co = loader.get_code(__name__)
print(f"co_filename: {co.co_filename}")
# ... before validating them.
# We expect a .py suffix to be added to both attributes. This behavior specific to frozen application; in unfrozen
# script, the suffix should be empty.
if getattr(sys, 'frozen', False):
assert os.path.splitext(__file__)[1] == '.py'
assert os.path.splitext(co.co_filename)[1] == '.py'
else:
assert os.path.splitext(__file__)[1] == ''
assert os.path.splitext(co.co_filename)[1] == ''
|