# Path: django_migration_linter/utils.py
# def split_migration_path(migration_path):
#     from django.db.migrations.loader import MIGRATIONS_MODULE_NAME
# 
#     decomposed_path = split_path(migration_path)
#     for i, p in enumerate(decomposed_path):
#         if p == MIGRATIONS_MODULE_NAME:
#             return decomposed_path[i - 1], os.path.splitext(decomposed_path[i + 1])[0]
# 
# def split_path(path):
#     decomposed_path = []
#     while 1:
#         head, tail = os.path.split(path)
#         if head == path:  # sentinel for absolute paths
#             decomposed_path.insert(0, head)
#             break
#         elif tail == path:  # sentinel for relative paths
#             decomposed_path.insert(0, tail)
#             break
#         else:
#             path = head
#             decomposed_path.insert(0, tail)
# 
#     if not decomposed_path[-1]:
#         decomposed_path = decomposed_path[:-1]
#     return decomposed_path


import unittest
from django_migration_linter.utils import split_migration_path, split_path
    def test_split_full_path(self):
        split = split_path("/foo/bar/fuz.py")
        self.assertEqual(split, ["/", "foo", "bar", "fuz.py"])

    def test_split_folder_path(self):
        split = split_path("/foo/bar")
        self.assertEqual(split, ["/", "foo", "bar"])

    def test_split_folder_path_trailing_slash(self):
        split = split_path("/foo/bar/")
        self.assertEqual(split, ["/", "foo", "bar"])

    def test_split_folder_path_trailing_slashes(self):
        split = split_path("/foo/bar///")
        self.assertEqual(split, ["/", "foo", "bar"])

    def test_split_migration_long_path(self):
        input_path = "apps/the_app/migrations/0001_stuff.py"
        app, mig = split_migration_path(input_path)
        self.assertEqual(app, "the_app")
        self.assertEqual(mig, "0001_stuff")

    def test_split_migration_path(self):
        input_path = "the_app/migrations/0001_stuff.py"
        app, mig = split_migration_path(input_path)
        self.assertEqual(app, "the_app")
        self.assertEqual(mig, "0001_stuff")

    def test_split_migration_full_path(self):
        input_path = "/home/user/djangostuff/apps/the_app/migrations/0001_stuff.py"

# Path: django_migration_linter/utils.py
# def split_migration_path(migration_path):
#     from django.db.migrations.loader import MIGRATIONS_MODULE_NAME
# 
#     decomposed_path = split_path(migration_path)
#     for i, p in enumerate(decomposed_path):
#         if p == MIGRATIONS_MODULE_NAME:
#             return decomposed_path[i - 1], os.path.splitext(decomposed_path[i + 1])[0]
# 
# def split_path(path):
#     decomposed_path = []
#     while 1:
#         head, tail = os.path.split(path)
#         if head == path:  # sentinel for absolute paths
#             decomposed_path.insert(0, head)
#             break
#         elif tail == path:  # sentinel for relative paths
#             decomposed_path.insert(0, tail)
#             break
#         else:
#             path = head
#             decomposed_path.insert(0, tail)
# 
#     if not decomposed_path[-1]:
#         decomposed_path = decomposed_path[:-1]
#     return decomposed_path


# Path: tests/unit/test_utils.py
import unittest
from django_migration_linter.utils import split_migration_path, split_path

    def test_split_full_path(self):
        split = split_path("/foo/bar/fuz.py")
        self.assertEqual(split, ["/", "foo", "bar", "fuz.py"])

    def test_split_folder_path(self):
        split = split_path("/foo/bar")
        self.assertEqual(split, ["/", "foo", "bar"])

    def test_split_folder_path_trailing_slash(self):
        split = split_path("/foo/bar/")
        self.assertEqual(split, ["/", "foo", "bar"])

    def test_split_folder_path_trailing_slashes(self):
        split = split_path("/foo/bar///")
        self.assertEqual(split, ["/", "foo", "bar"])

    def test_split_migration_long_path(self):
        input_path = "apps/the_app/migrations/0001_stuff.py"
        app, mig = split_migration_path(input_path)
        self.assertEqual(app, "the_app")
        self.assertEqual(mig, "0001_stuff")

    def test_split_migration_path(self):
        input_path = "the_app/migrations/0001_stuff.py"
        app, mig = split_migration_path(input_path)
        self.assertEqual(app, "the_app")
        self.assertEqual(mig, "0001_stuff")

    def test_split_migration_full_path(self):
        input_path = "/home/user/djangostuff/apps/the_app/migrations/0001_stuff.py"

        app, mig = split_migration_path(input_path)