Ticket #5825: user_command_with_test.patch

File user_command_with_test.patch, 2.1 KB (added by abozanich, 16 years ago)
  • django/core/management/__init__.py

     
    3737    parts = app_name.split('.')
    3838    parts.append('management')
    3939    parts.reverse()
     40    part = parts.pop()
    4041    path = None
     42
     43    # Skip the first module if we're in a directory of the same name.
     44    # Without this ./manage.py doesn't pick up your app's management modules
     45    try:
     46        f, path, descr = find_module(part,path)
     47    except ImportError,e:
     48        if os.path.basename(os.getcwd()) != part:
     49            raise e
     50
    4151    while parts:
    4252        part = parts.pop()
    4353        f, path, descr = find_module(part, path and [path] or None)
  • tests/modeltests/user_commands/tests.py

     
     1from django.test import TestCase
     2from os import getcwd, chdir, path
     3from django.core.management import find_management_module, get_commands
     4import sys
     5
     6class TestUserCommand(TestCase):
     7
     8    command_name = 'dance'
     9   
     10    def setUp(self):
     11        self.old_wd   = getcwd()
     12        self.app_wd   = path.dirname(__file__)
     13        self.cur_wd   = path.dirname(self.app_wd)
     14        self.test_wd  = path.dirname(self.cur_wd)
     15        self.app_name = ".".join(map(path.basename,(self.cur_wd,self.app_wd)))
     16
     17        if '' not in sys.path:
     18            sys.path.insert(0,'')
     19        if self.test_wd in sys.path:
     20            sys.path.remove(self.test_wd)
     21        chdir(self.cur_wd)
     22
     23    def testFindManagementModule(self):
     24        find_management_module(self.app_name)
     25        self.assertRaises(ImportError,find_management_module,self.app_name + "xxxxxx")
     26
     27    def testGetCommands(self):
     28        self.assertTrue( self.command_name in get_commands().keys() )
     29
     30    def tearDown(self):
     31        chdir(self.old_wd)
     32        sys.path.insert(0,self.test_wd)
Back to Top