
    Ah                     f    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	e      Zy
)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                       e Zd Zd Zy)TestForMigrationsc                    t        d t        j                         D              D ])  }t        j                  |j	                  d      d          + t        d d      }t        fd|j                         j                         D              }|r:dj                  d |j                         D              }| j                  d	|z         t        |j                         t        j                  t              t        d
            }|j!                  |j"                  xs d xs d       }|r;dj                  d |j                         D              }| j                  d|z         y y )Nc              3   l   K   | ],  }|j                   j                  d       s|j                   . yw)ztests.N)name
startswithlabel).0apps     O/home/dcms/DCMS/lib/python3.12/site-packages/treebeard/tests/test_migrations.py	<genexpr>z5TestForMigrations.test__migrations.<locals>.<genexpr>   s&     fsH[H[\dHefs    44.T)ignore_no_migrationsc              3   4   K   | ]  \  }}|v r||f  y w)N )r   	app_labelconflict
app_labelss      r   r   z5TestForMigrations.test__migrations.<locals>.<genexpr>   s*      
#	8J& !
s   z; c              3   N   K   | ]  \  }}d j                  |      d|  yw)z, z in N)join)r   r   namess      r   r   z5TestForMigrations.test__migrations.<locals>.<genexpr>   s"      j*#utyy/?!E js   #%z%Conflicting migrations detected (%s).)specified_appsdry_run)graphtrim_to_appsconvert_apps
c           	   3      K   | ]A  \  }}|D ]7  }d j                  |dj                  d |j                  D                     9 C yw)z  {migration}
{changes}r$   c              3   Z   K   | ]#  }d j                  |j                                % yw)z    {0}N)formatdescribe)r   	operations     r   r   z?TestForMigrations.test__migrations.<locals>.<genexpr>.<genexpr>1   s.      &M*3 '0&6&6y7I7I7K&L &Ms   )+)	migrationchangesN)r'   r   
operations)r   _
migrationsr*   s       r   r   z5TestForMigrations.test__migrations.<locals>.<genexpr>.   sl      $-
 $Q
!+$-  +11' II &M7@7K7K&M M 2 N$-N$-s   AA	z-Model changes with no migrations detected:
%s)setr   get_app_configsget_app_configsplitr   dictdetect_conflictsitemsr   failr   project_stater   	from_appsr   r+   r!   )	selfr   loader	conflictsname_strautodetectorr+   r.   r   s	           @r   test__migrationsz"TestForMigrations.test__migrations   sN   fd.B.B.Dff
# 	:I	 4R 89	: DA 
'-'>'>'@'F'F'H
 
	 yy jXaXgXgXi jjHII=HI,  """4(z4H
 &&,,#+t#+t ' 
  $-
 (/}}$- .J IIFST     N)__name__
__module____qualname__r>   r   r?   r   r
   r
      s    %Ur?   r
   N)__doc__django.appsr   !django.db.migrations.autodetectorr   django.db.migrations.loaderr   django.db.migrations.questionerr   django.db.migrations.stater   django.testr   r
   r   r?   r   <module>rJ      s,     C 7 ? 3  &U &Ur?   