a
    Dg                     @   s`   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ G dd	 d	eZd
S )z
Check that all changes to Wagtail models have had migrations created. If there
are outstanding model changes that need migrations, fail the tests.
    )apps)MigrationAutodetector)MigrationLoader)MigrationQuestioner)ProjectState)TestCasec                   @   s   e Zd Zdd ZdS )TestForMigrationsc                    s   dd t  D   D ]}t |dd  qtd dd} fdd|  D }|rdd	d
 | D }| d|  t	|
 tt t dd}|j|j pd  pd d}|rddd
 | D }| d|  d S )Nc                 S   s&   h | ]}|j d d dkr|jqS ).r   Zwagtail)namesplitlabel).0app r   \/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/tests/test_migrations.py	<setcomp>   s   z5TestForMigrations.test__migrations.<locals>.<setcomp>r	   T)Zignore_no_migrationsc                    s    h | ]\}}| v r||fqS r   r   )r   	app_labelconflictZ
app_labelsr   r   r      s   z; c                 s   s$   | ]\}}d  d||V  qdS )z{} in {}z, N)formatjoin)r   r   namesr   r   r   	<genexpr>    s   z5TestForMigrations.test__migrations.<locals>.<genexpr>z%Conflicting migrations detected (%s).)Zspecified_appsdry_run)graphZtrim_to_appsZconvert_apps
c                 s   s<   | ]4\}}|D ]&}d j |ddd |jD dV  qqdS )z  {migration}
{changes}r   c                 s   s   | ]}d |   V  qdS )z    N)Zdescribe)r   Z	operationr   r   r   r   6   s   z?TestForMigrations.test__migrations.<locals>.<genexpr>.<genexpr>)	migrationchangesN)r   r   
operations)r   _
migrationsr   r   r   r   r   3   s   
z-Model changes with no migrations detected:
%s)r   Zget_app_configsZget_app_configr   r   Zdetect_conflictsitemsr   Zfailr   Zproject_stater   Z	from_appsr   r   r   )selfr   loader	conflictsZname_strZautodetectorr   r!   r   r   r   test__migrations   s:    




z"TestForMigrations.test__migrationsN)__name__
__module____qualname__r&   r   r   r   r   r      s   r   N)__doc__Zdjango.appsr   Z!django.db.migrations.autodetectorr   Zdjango.db.migrations.loaderr   Zdjango.db.migrations.questionerr   Zdjango.db.migrations.stater   Zdjango.testr   r   r   r   r   r   <module>   s   