File: //usr/local/lib/python3.7/test/__pycache__/test_cmd_line_script.cpython-37.pyc
B
��g�t � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl Z d dl
Z
d dlZd dlm
Z
d dlmZmZmZmZmZmZmZmZ e
jZdddgZdZefdd �Zed
fdd�ZG d
d� dej�Zdd� Zedkr�e� dS )� N)�support)�make_pkg�make_script�make_zip_pkg�make_zip_script�assert_python_ok�assert_python_failure�spawn_python�kill_pythonZtest1Ztest2Ztest3a� # Script may be run with optimisation enabled, so don't rely on assert
# statements being executed
def assertEqual(lhs, rhs):
if lhs != rhs:
raise AssertionError('%r != %r' % (lhs, rhs))
def assertIdentical(lhs, rhs):
if lhs is not rhs:
raise AssertionError('%r is not %r' % (lhs, rhs))
# Check basic code execution
result = ['Top level assignment']
def f():
result.append('Lower level reference')
f()
assertEqual(result, ['Top level assignment', 'Lower level reference'])
# Check population of magic variables
assertEqual(__name__, '__main__')
from importlib.machinery import BuiltinImporter
_loader = __loader__ if __loader__ is BuiltinImporter else type(__loader__)
print('__loader__==%a' % _loader)
print('__file__==%a' % __file__)
print('__cached__==%a' % __cached__)
print('__package__==%r' % __package__)
# Check PEP 451 details
import os.path
if __package__ is not None:
print('__main__ was located through the import system')
assertIdentical(__spec__.loader, __loader__)
expected_spec_name = os.path.splitext(os.path.basename(__file__))[0]
if __package__:
expected_spec_name = __package__ + "." + expected_spec_name
assertEqual(__spec__.name, expected_spec_name)
assertEqual(__spec__.parent, __package__)
assertIdentical(__spec__.submodule_search_locations, None)
assertEqual(__spec__.origin, __file__)
if __spec__.cached is not None:
assertEqual(__spec__.cached, __cached__)
# Check the sys module
import sys
assertIdentical(globals(), sys.modules[__name__].__dict__)
if __spec__ is not None:
# XXX: We're not currently making __main__ available under its real name
pass # assertIdentical(globals(), sys.modules[__spec__.name].__dict__)
from test import test_cmd_line_script
example_args_list = test_cmd_line_script.example_args
assertEqual(sys.argv[1:], example_args_list)
print('sys.argv[0]==%a' % sys.argv[0])
print('sys.path[0]==%a' % sys.path[0])
# Check the working directory
import os
print('cwd==%a' % os.getcwd())
c C s t | ||�}t�� |S )N)r � importlib�invalidate_caches)�
script_dir�script_basename�source� to_return� r �5/usr/local/lib/python3.7/test/test_cmd_line_script.py�_make_test_scriptN s r � c C s t | |||||�}t�� |S )N)r r r )Zzip_dirZzip_basenameZpkg_namer r �depthr r r r �_make_test_zip_pkgS s
r c @ s� e Zd Zd`dd�Zdd�dd�Zdd�dd�Zd d
� Zdd� Zej dadd��Z
dbdd�Zdcdd�Zdd� Z
dd� Zdd� Zdd� Zdd� Zdd� Zd d!� Zd"d#� Zd$d%� Zd&d'� Zd(d)� Zd*d+� Zd,d-� Zd.d/� Zd0d1� Zd2d3� Zd4d5� Zd6d7� Zd8d9� Zd:d;� Z d<d=� Z!d>d?� Z"d@dA� Z#ej dBdC� �Z$dDdE� Z%dFdG� Z&dHdI� Z'dJdK� Z(dLdM� Z)dNdO� Z*dPdQ� Z+dRdS� Z,dTdU� Z-dVdW� Z.dXdY� Z/dZd[� Z0d\d]� Z1d^d_� Z2dS )d�CmdLineTestNc
C s t dkr td| � tt|�� | �|d� d| }
d| }d| }d| }
d| }| d krdt�� } d | }t dkr�td
� t|� t|� t|
� t|� | �|
�d�|� | �|�d�|� | �|�d�|� | �|
�d�|� | �|�d�|� | �|�d�|� d S )Nr zOutput from test script %r:r z__loader__==%az__file__==%az__package__==%rzsys.argv[0]==%azsys.path[0]==%azcwd==%azExpected output:zutf-8)�verbose�print�repr�assertEqual�os�getcwd�assertIn�encode)�self�script_nameZ exit_code�data�
expected_file�expected_argv0�expected_path0�expected_package�expected_loaderZexpected_cwdZprinted_loaderZprinted_fileZprinted_packageZ
printed_argv0Z
printed_path0Zprinted_cwdr r r �
_check_output[ s0 zCmdLineTest._check_output)�cwdc O s\ t |t�r|g}t�� ||t�}
t|
d|d�| ��\}}}
| �||||
||||||� d S )NF)�
__isolated�__cwd)�
isinstance�strr Z!optim_args_from_interpreter_flags�example_argsr r( )r �script_exec_argsr# r$ r% r&