tidu 0.2.0

Automatic-differentiation transforms (linearize, transpose, eager reverse-mode) for primitive computation graphs.
Documentation
�

e��i0��J�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	e	e
�j�jdZ
e
dzdzZe
dzdzZde	ded	dfd
�Zde	d	dfd�Zd	efd
�Zd	efd�ZGd�dej*�Zedk(rej0�yy)�N)�Path��scripts�check-repo-settings.sh�configure-repo-settings.sh�path�content�returnc��|j|d��|j|j�jtjz�y)N�utf-8��encoding)�
write_text�chmod�stat�st_mode�S_IXUSR)rr	s  �W/sharehome/shinaoka/projects/tensor4all/template-rs/tests/test_repo_settings_scripts.py�write_executablers3���O�O�G�g�O�.��J�J�t�y�y�{�"�"�T�\�\�1�2��rootc��|dzj�|dzdzjtjddddgd�d�ddd�d	��d
��y)N�aizrepo-settings.json�mainT��rustfmtzcargo test (ubuntu-latest)zcargo test (macos-latest)�coveragez	docs-site��strict�contexts�workflow)�enabled�
build_type)�default_branch�allow_auto_merge�delete_branch_on_merge�required_status_checks�pagesrr
)�mkdirr�json�dumps)rs r�write_repo_settingsr,sh��	�D�[����	�D�[�'�'�3�3��
�
�"(�$(�*.�"�!�	+� $�",��
�	
�*�-4�rc�2�tjddd��S)NT)r%r&�r*r+�rr�	repo_jsonr02s���:�:� $�&*�	
��rc�:�tjddgd�d�i�S)Nr'Trrr.r/rr�protection_jsonr2;s(���:�:�$���	'�	
�
�
rc�d�eZdZdededeejeeffd�Zd
d�Z	d
d�Z
d
d�Zd
d	�Zy)�RepoSettingsScriptTests�script_name�	gh_scriptr
c��tj�}|j|j�t	|j
�}|dzj
�tjt|dzdz�tjt|dzdz�t|�|dz}|j
�|dz}|j
�|dzjdd�	�t|d
z|�tjj!�}|�d|d��|d<t#|�|d
<t%j&dt#|dz|z�g|dd|d��}||fS)Nrrr�bin�state�gh-log.jsonl�rr
�gh�:�PATH�FAKE_GH_STATE_DIR�bashTF)�cwd�text�capture_output�env�check)�tempfile�TemporaryDirectory�
addCleanup�cleanupr�namer)�shutil�copy2�CHECK_SCRIPT�CONFIGURE_SCRIPTr,rr�os�environ�copy�str�
subprocess�run)	�selfr5r6�temp_dirr�bin_dir�	state_dirrD�results	         r�
run_scriptz"RepoSettingsScriptTests.run_scriptMs>���.�.�0������(�(�)��H�M�M�"��	
�	�	� � �"����\�4�)�#3�6N�#N�O����%�t�i�'7�:V�'V�W��D�!���,���
�
���7�N�	�����	�^�	#�/�/��W�/�E���4���3��j�j�o�o��� �	��3�v�;�-�0��F��#&�y�>��� ����
�S��	�)�K�7�8�9������

���t�|�rNc
�*�|jdtjdt��dt	��d���\}}|j|jdd|j�d|j����|jd	|j�y)
Nr�L                #!/usr/bin/env bash
                set -euo pipefail

                if [[ "$1" == "repo" && "$2" == "view" ]]; then
                  printf 'example/repo\n'
                  exit 0
                fi

                if [[ "$1" == "api" && "$2" == "repos/example/repo" ]]; then
                  printf '%s\n' '��'
                  exit 0
                fi

                if [[ "$1" == "api" && "$2" == "repos/example/repo/branches/main/protection" ]]; then
                  printf '%s\n' 'a�'
                  exit 0
                fi

                if [[ "$1" == "api" && "$2" == "repos/example/repo/pages" ]]; then
                  printf '{"message":"Not Found","status":"404"}\n'
                  printf 'gh: Not Found (HTTP 404)\n' >&2
                  exit 1
                fi

                printf 'unexpected gh invocation: %s\n' "$*" >&2
                exit 1
                r�'expected failure, got success:\nstdout=�	\nstderr=��msgzpages is not enabled�
rZ�textwrap�dedentr0r2�assertNotEqual�
returncode�stdout�stderr�assertIn�rUrY�_s   r�9test_check_repo_settings_fails_when_pages_site_is_missingzQRepoSettingsScriptTests.test_check_repo_settings_fails_when_pages_site_is_missingls����O�O�$��O�O�
#�$-�;�-�0#�
$3�#4�"5�6��
� 
�	���D	
������
�:�6�=�=�/��TZ�Ta�Ta�Sb�c�	�	
�
	
�
�
�,�f�m�m�<rc
���|jdtjdt��dt	��d���\}}|j|jdd|j�d|j����|jd	|j�|d
zdzjd�
�j�D�cgc]}|rtj|���}}|jgd�|�ycc}w)Nra�                #!/usr/bin/env bash
                set -euo pipefail

                state_dir="${FAKE_GH_STATE_DIR:?}"
                log_file="$state_dir/gh-log.jsonl"
                pages_file="$state_dir/pages.json"

                log_call() {
                  python3 - "$log_file" "$@" <<'PY'
import json
import pathlib
import sys

path = pathlib.Path(sys.argv[1])
entry = sys.argv[2:]
with path.open("a", encoding="utf-8") as handle:
    handle.write(json.dumps(entry) + "\n")
PY
                }

                if [[ "$1" == "repo" && "$2" == "view" ]]; then
                  log_call "$@"
                  printf 'example/repo\n'
                  exit 0
                fi

                if [[ "$1" == "repo" && "$2" == "edit" ]]; then
                  log_call "$@"
                  exit 0
                fi

                if [[ "$1" == "api" && "$2" == "repos/example/repo" ]]; then
                  log_call "$@"
                  printf '%s\n' '��'
                  exit 0
                fi

                if [[ "$1" == "api" && "$2" == "repos/example/repo/branches/main/protection" ]]; then
                  log_call "$@"
                  printf '%s\n' 'a5'
                  exit 0
                fi

                if [[ "$1" == "api" && "${4-}" == "repos/example/repo/branches/main/protection" ]]; then
                  log_call "$@"
                  cat >/dev/null
                  exit 0
                fi

                if [[ "$1" == "api" && "$2" == "repos/example/repo/pages" ]]; then
                  log_call "$@"
                  if [[ -f "$pages_file" ]]; then
                    cat "$pages_file"
                    exit 0
                  fi

                  printf '{"message":"Not Found","status":"404"}\n'
                  printf 'gh: Not Found (HTTP 404)\n' >&2
                  exit 1
                fi

                if [[ "$1" == "api" && "${4-}" == "repos/example/repo/pages" ]]; then
                  log_call "$@"
                  printf '{"build_type":"workflow"}\n' >"$pages_file"
                  printf '{"build_type":"workflow"}\n'
                  exit 0
                fi

                printf 'unexpected gh invocation: %s\n' "$*" >&2
                exit 1
                r�stdout=r_r`zrepo-settings-ok: example/repor9r:rr
)�api�-X�POST�repos/example/repo/pages�-H�#Accept: application/vnd.github+json�-f�build_type=workflow)rZrcrdr0r2�assertEqualrfrgrhri�	read_text�
splitlinesr*�loads�rUrYr�line�gh_logs     r�Ctest_configure_repo_settings_creates_pages_site_for_workflow_buildsz[RepoSettingsScriptTests.test_configure_repo_settings_creates_pages_site_for_workflow_builds�s�����(��O�O�"#�D$-�;�-�0#�$3�#4�"5�6�QG�I
�L
����\	
����*�*�A�W�V�]�]�O�:�V\�Vc�Vc�Ud�3e��f��
�
�6��
�
�F����.�8�C�C�W�C�U�`�`�b�
���
�J�J�t��
��
�
	
�
�
�	
�
�	
��
s�<C1c
�*�|jdtjdt��dt	��d���\}}|j|jdd|j�d|j����|jd	|j�y)
Nrr\r]aL'
                  exit 0
                fi

                if [[ "$1" == "api" && "$2" == "repos/example/repo/pages" ]]; then
                  printf '{"build_type":"legacy"}\n'
                  exit 0
                fi

                printf 'unexpected gh invocation: %s\n' "$*" >&2
                exit 1
                rr^r_r`zpages.build_type mismatchrbrjs   r�=test_check_repo_settings_fails_when_pages_build_type_is_wrongzURepoSettingsScriptTests.test_check_repo_settings_fails_when_pages_build_type_is_wrong�s����O�O�$��O�O�
#�$-�;�-�0#�
$3�#4�"5�6��
�
�	���B	
������
�:�6�=�=�/��TZ�Ta�Ta�Sb�c�	�	
�
	
�
�
�1�6�=�=�Arc
��|jdtjdt��dt	��d���\}}|j|jdd|j�d|j����|d	zd
zjd��j�D�cgc]}|rtj|���}}|jgd
�|�ycc}w)Nra\                #!/usr/bin/env bash
                set -euo pipefail

                state_dir="${FAKE_GH_STATE_DIR:?}"
                log_file="$state_dir/gh-log.jsonl"
                pages_file="$state_dir/pages.json"
                if [[ ! -f "$pages_file" ]]; then
                  printf '{"build_type":"legacy"}\n' >"$pages_file"
                fi

                log_call() {
                  python3 - "$log_file" "$@" <<'PY'
import json
import pathlib
import sys

path = pathlib.Path(sys.argv[1])
entry = sys.argv[2:]
with path.open("a", encoding="utf-8") as handle:
    handle.write(json.dumps(entry) + "\n")
PY
                }

                if [[ "$1" == "repo" && "$2" == "view" ]]; then
                  log_call "$@"
                  printf 'example/repo\n'
                  exit 0
                fi

                if [[ "$1" == "repo" && "$2" == "edit" ]]; then
                  log_call "$@"
                  exit 0
                fi

                if [[ "$1" == "api" && "$2" == "repos/example/repo" ]]; then
                  log_call "$@"
                  printf '%s\n' 'rnaR'
                  exit 0
                fi

                if [[ "$1" == "api" && "${4-}" == "repos/example/repo/branches/main/protection" ]]; then
                  log_call "$@"
                  cat >/dev/null
                  exit 0
                fi

                if [[ "$1" == "api" && "$2" == "repos/example/repo/pages" ]]; then
                  log_call "$@"
                  cat "$pages_file"
                  exit 0
                fi

                if [[ "$1" == "api" && "${4-}" == "repos/example/repo/pages" ]]; then
                  log_call "$@"
                  printf '{"build_type":"workflow"}\n' >"$pages_file"
                  printf '{"build_type":"workflow"}\n'
                  exit 0
                fi

                printf 'unexpected gh invocation: %s\n' "$*" >&2
                exit 1
                rror_r`r9r:rr
)rprq�PUTrsrtrurvrw)rZrcrdr0r2rxrfrgrhryrzr*r{rir|s     r�Ktest_configure_repo_settings_updates_existing_pages_site_to_workflow_buildszcRepoSettingsScriptTests.test_configure_repo_settings_updates_existing_pages_site_to_workflow_builds#s������(��O�O�%#�J$-�;�-�0#�$3�#4�"5�6�WD�F
�I
����V	
����*�*�A�W�V�]�]�O�:�V\�Vc�Vc�Ud�3e��f����.�8�C�C�W�C�U�`�`�b�
���
�J�J�t��
��
�
	
�
�
�	
�
�	
��
s� C)r
N)
�__name__�
__module__�__qualname__rR�tuplerS�CompletedProcessrrZrlrr�r�r/rrr4r4LsM���c��c��e�J�D_�D_�`c�Dd�fj�Dj�>k��>(=�Tb
�H'B�R^
rr4�__main__)r*rOrKrrSrFrc�unittest�pathlibr�__file__�resolve�parents�	REPO_ROOTrMrNrRrr,r0r2�TestCaser4r�rr/rr�<module>r�s����	�
�������
��N�"�"�$�,�,�Q�/�	��9�$�'?�?���y�(�+G�G��3�4�3�#�3�$�3�
�d��t��8�3�����"u
�h�/�/�u
�p	�z���H�M�M�O�r