diff -r e5bac5b2f38d Lib/test/test_spwd.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/test_spwd.py Sun May 25 18:03:42 2014 +0700 @@ -0,0 +1,48 @@ +import os +import unittest +from test import support + +spwd = support.import_module('spwd') + + +@unittest.skipIf(spwd is None, "Needs spwd module") +@unittest.skipUnless(os.getuid() == 0, "Needs root account on POSIX") +class TestSpwdRoot(unittest.TestCase): + + def setUp(self): + self.entries = spwd.getspall() + self.random_entry = self.entries[0] + + def test_getspall(self): + for entry in self.entries: + self.assertIsInstance(entry, spwd.struct_spwd) + + def test_getspnam(self): + entry = spwd.getspnam(self.random_entry.sp_namp) + self.assertIsInstance(entry, spwd.struct_spwd) + self.assertEqual(entry.sp_namp, self.random_entry.sp_namp) + self.assertEqual(entry.sp_namp, entry[0]) + self.assertIsInstance(entry.sp_pwdp, str) + self.assertEqual(entry.sp_pwdp, entry[1]) + self.assertIsInstance(entry.sp_lstchg, int) + self.assertEqual(entry.sp_lstchg, entry[2]) + self.assertIsInstance(entry.sp_min, int) + self.assertEqual(entry.sp_min, entry[3]) + self.assertIsInstance(entry.sp_max, int) + self.assertEqual(entry.sp_max, entry[4]) + self.assertIsInstance(entry.sp_warn, int) + self.assertEqual(entry.sp_warn, entry[5]) + self.assertIsInstance(entry.sp_inact, int) + self.assertEqual(entry.sp_inact, entry[6]) + self.assertIsInstance(entry.sp_expire, int) + self.assertEqual(entry.sp_expire, entry[7]) + self.assertIsInstance(entry.sp_flag, int) + self.assertEqual(entry.sp_flag, entry[8]) + with self.assertRaises(KeyError) as cx: + spwd.getspnam('invalid user name') + self.assertEqual(str(cx.exception), "'getspnam(): name not found'") + self.assertRaises(TypeError, spwd.getspnam, 1) + + +if __name__ == "__main__": + unittest.main()