stacktach/tests/unit/test_migrations_files.py
2013-11-15 13:52:36 -05:00

27 lines
814 B
Python

from os import listdir
import re
from stacktach import migrations
from tests.unit import StacktachBaseTestCase
class MigrationsTestCase(StacktachBaseTestCase):
def test_no_duplicate_numbers(self):
migrs = {}
migrations_file = migrations.__file__
migrations_dir = migrations_file[:-len('__init__.py')-1]
migr_match = re.compile('^[0-9]{4}.*.py$')
files = [f for f in listdir(migrations_dir)
if re.match(migr_match, f)]
for f in files:
migr_number = f[0:4]
migr_list = migrs.get(migr_number, [])
migr_list.append(f)
migrs[migr_number] = migr_list
if len(migr_list) > 1:
msg = "Duplicate migrations found for number %s." % migr_number
self.fail(msg)