a
    C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 )a  
Check that all changes to Treebeard models have had migrations created in our test app. If there
are outstanding model changes that need migrations, fail the tests.

This module is taken from https://github.com/wagtail/wagtail/blob/master/wagtail/core/tests/test_migrations.py.
    )apps)MigrationAutodetector)MigrationLoader)MigrationQuestioner)ProjectState)TestCasec                   @   s   e Zd Zdd ZdS )TestForMigrationsc                    s   t dd t D   D ]}t|dd  qtd dd}t 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    | ]}|j d r|jV  qdS )ztests.N)name
startswithlabel).0app r   ^/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/treebeard/tests/test_migrations.py	<genexpr>       z5TestForMigrations.test__migrations.<locals>.<genexpr>.T)Zignore_no_migrationsc                 3   s"   | ]\}}| v r||fV  qd S )Nr   )r   	app_labelconflictZ
app_labelsr   r   r      s   z; c                 s   s$   | ]\}}d d ||f V  qdS )z%s in %sz, N)join)r   r   namesr   r   r   r      r   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    {0}N)formatZdescribe)r   Z	operationr   r   r   r   1   s   z?TestForMigrations.test__migrations.<locals>.<genexpr>.<genexpr>)	migrationchangesN)r   r   
operations)r   _
migrationsr   r   r   r   r   .   s   
z-Model changes with no migrations detected:
%s)setr   Zget_app_configsZget_app_configsplitr   dictZ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   s2    


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   