Back to index

python3.2  3.2.2
Public Member Functions
test.test_grp.GroupDatabaseTestCase Class Reference

List of all members.

Public Member Functions

def check_value
def test_values
def test_errors

Detailed Description

Definition at line 8 of file test_grp.py.


Member Function Documentation

Definition at line 10 of file test_grp.py.

00010 
00011     def check_value(self, value):
00012         # check that a grp tuple has the entries and
00013         # attributes promised by the docs
00014         self.assertEqual(len(value), 4)
00015         self.assertEqual(value[0], value.gr_name)
00016         self.assertIsInstance(value.gr_name, str)
00017         self.assertEqual(value[1], value.gr_passwd)
00018         self.assertIsInstance(value.gr_passwd, str)
00019         self.assertEqual(value[2], value.gr_gid)
00020         self.assertIsInstance(value.gr_gid, int)
00021         self.assertEqual(value[3], value.gr_mem)
00022         self.assertIsInstance(value.gr_mem, list)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 47 of file test_grp.py.

00047 
00048     def test_errors(self):
00049         self.assertRaises(TypeError, grp.getgrgid)
00050         self.assertRaises(TypeError, grp.getgrnam)
00051         self.assertRaises(TypeError, grp.getgrall, 42)
00052 
00053         # try to get some errors
00054         bynames = {}
00055         bygids = {}
00056         for (n, p, g, mem) in grp.getgrall():
00057             if not n or n == '+':
00058                 continue # skip NIS entries etc.
00059             bynames[n] = g
00060             bygids[g] = n
00061 
00062         allnames = list(bynames.keys())
00063         namei = 0
00064         fakename = allnames[namei]
00065         while fakename in bynames:
00066             chars = list(fakename)
00067             for i in range(len(chars)):
00068                 if chars[i] == 'z':
00069                     chars[i] = 'A'
00070                     break
00071                 elif chars[i] == 'Z':
00072                     continue
00073                 else:
00074                     chars[i] = chr(ord(chars[i]) + 1)
00075                     break
00076             else:
00077                 namei = namei + 1
00078                 try:
00079                     fakename = allnames[namei]
00080                 except IndexError:
00081                     # should never happen... if so, just forget it
00082                     break
00083             fakename = ''.join(chars)
00084 
00085         self.assertRaises(KeyError, grp.getgrnam, fakename)
00086 
00087         # Choose a non-existent gid.
00088         fakegid = 4127
00089         while fakegid in bygids:
00090             fakegid = (fakegid * 3) % 0x10000
00091 
00092         self.assertRaises(KeyError, grp.getgrgid, fakegid)

Here is the call graph for this function:

Definition at line 23 of file test_grp.py.

00023 
00024     def test_values(self):
00025         entries = grp.getgrall()
00026 
00027         for e in entries:
00028             self.check_value(e)
00029 
00030         if len(entries) > 1000:  # Huge group file (NIS?) -- skip the rest
00031             return
00032 
00033         for e in entries:
00034             e2 = grp.getgrgid(e.gr_gid)
00035             self.check_value(e2)
00036             self.assertEqual(e2.gr_gid, e.gr_gid)
00037             name = e.gr_name
00038             if name.startswith('+') or name.startswith('-'):
00039                 # NIS-related entry
00040                 continue
00041             e2 = grp.getgrnam(name)
00042             self.check_value(e2)
00043             # There are instances where getgrall() returns group names in
00044             # lowercase while getgrgid() returns proper casing.
00045             # Discovered on Ubuntu 5.04 (custom).
00046             self.assertEqual(e2.gr_name.lower(), name.lower())

Here is the call graph for this function:


The documentation for this class was generated from the following file: