Пример #1
0
def details(var):
    """
    Prints a dictionary showing the attributes of a variable, and if possible,
    their corresponding values.
    """
    var_details = get_details(var)
    _display_details(var_details)
    return var_details
Пример #2
0
def details(var):
    """
    Prints a dictionary showing the attributes of a variable, and if possible,
    their corresponding values.
    """
    var_details = get_details(var)
    _display_details(var_details)
    return var_details
Пример #3
0
 def test_set_value_managers(self):
     user = self.get_context()['user']
     user_details = get_details(user)
     managers = []
     for key in user_details.keys():
         value = getattr(self.user, key, None)
         kls = getattr(getattr(value, '__class__', ''), '__name__', '')
         if kls in ('ManyRelatedManager', 'RelatedManager'):
             managers.append(key)
     for key, value in user_details.items():
         if key in managers:
             self.assertTrue(value in
                 ('ManyRelatedManager', 'RelatedManager')
             )
Пример #4
0
 def test_invalid_managers_hidden(self):
     """
     Assure managers that aren't accessible from model instances are hidden
     """
     user = self.get_context()['user']
     user_details = get_details(user)
     invalid_managers = []
     for attr in dir(user):
         try:
             getattr(user, attr)
         except:
             invalid_managers.append(attr)
     self.assertTrue(all([not manager in user_details.keys()
                          for manager in invalid_managers]))
Пример #5
0
    def test_get_details_c_extensions(self):
        """
        Ensures get_details works on objects with callables that are
        implemented in C extensions. inspect.getargspec fails with a TypeError
        for such callables, and get_details needs to handle this gracefully

        N.B. Only Python >=2.7 has bit_length C routine on Booleans so the test
        has to be skipped for Python2.6
        """
        if hasattr(True, 'bit_length'):
            try:
                details = get_details(True)
            except TypeError:
                self.fail('Fails to handle C routines for call to inspect.argspec')
            self.assertEqual(details['bit_length'], 'routine')
        user_details = get_details(self.get_context()['user'])
        self.assertTrue(any((
            user_details['META_module_name'], 'django.contrib.auth.models',
            user_details['META_module_name'], 'django.utils.functional'
        )))
        self.assertTrue(any((
            user_details['META_class_name'] == 'User',
            user_details['META_class_name'] == 'AnonymousUser'
        )))
Пример #6
0
    def test_get_details_c_extensions(self):
        """
        Ensures get_details works on objects with callables that are
        implemented in C extensions. inspect.getargspec fails with a TypeError
        for such callables, and get_details needs to handle this gracefully

        N.B. Only Python >=2.7 has bit_length C routine on Booleans so the test
        has to be skipped for Python2.6
        """
        if hasattr(True, 'bit_length'):
            try:
                details = get_details(True)
            except TypeError:
                self.fail(
                    'Fails to handle C routines for call to inspect.argspec')
            self.assertEqual(details['bit_length'], 'routine')
        user_details = get_details(self.get_context()['user'])
        self.assertTrue(
            any((user_details['META_module_name'],
                 'django.contrib.auth.models',
                 user_details['META_module_name'], 'django.utils.functional')))
        self.assertTrue(
            any((user_details['META_class_name'] == 'User',
                 user_details['META_class_name'] == 'AnonymousUser')))
Пример #7
0
 def test_set_value_managers(self):
     user = self.get_context()['user']
     user_details = get_details(user)
     managers = []
     for key in user_details.keys():
         value = getattr(self.user, key, None)
         kls = getattr(getattr(value, '__class__', ''), '__name__', '')
         if kls in ('ManyRelatedManager', 'RelatedManager', 'EmptyManager'):
             managers.append(key)
     for key, value in user_details.items():
         if key in managers:
             self.assertTrue(value in (
                 'ManyRelatedManager',
                 'RelatedManager',
                 'EmptyManager',
             ))
Пример #8
0
 def test_invalid_managers_hidden(self):
     """
     Assure managers that aren't accessible from model instances are hidden
     """
     user = self.get_context()['user']
     user_details = get_details(user)
     invalid_managers = []
     for attr in dir(user):
         try:
             getattr(user, attr)
         except:
             invalid_managers.append(attr)
     self.assertTrue(
         all([
             not manager in user_details.keys()
             for manager in invalid_managers
         ]))
Пример #9
0
 def test_module_and_class_added(self):
     user_details = get_details(self.get_context()['user'])
     self.assertEqual(user_details['META_module_name'],
                      'django.utils.functional')
     self.assertEqual(user_details['META_class_name'], 'User')
Пример #10
0
 def test_set_value_method(self):
     """Assure methods have their value set to 'method'"""
     user_details = get_details(self.get_context()['user'])
     for key, value in list(user_details.items()):
         if callable(getattr(self.user, key, None)):
             self.assertEqual(value, 'routine')
Пример #11
0
 def test_module_and_class_added(self):
     user_details = get_details(self.get_context()['user'])
     self.assertEqual(user_details['META_module_name'],
                      'django.utils.functional')
     self.assertEqual(user_details['META_class_name'], 'User')
Пример #12
0
 def test_set_value_method(self):
     """Assure methods have their value set to 'method'"""
     user_details = get_details(self.get_context()['user'])
     self.assertEqual(user_details['get_full_name'], 'routine')
Пример #13
0
 def test_set_value_method(self):
     """Assure methods have their value set to 'method'"""
     user_details = get_details(self.get_context()['user'])
     self.assertEqual(user_details['get_full_name'], 'routine')