Convert test_nis to unittest.

This commit is contained in:
Georg Brandl 2006-10-29 19:24:43 +00:00
parent eecce795a3
commit 850b2be67e
2 changed files with 37 additions and 37 deletions

View file

@ -1,2 +0,0 @@
test_nis
nis.maps()

View file

@ -1,16 +1,16 @@
from test.test_support import verbose, TestFailed, TestSkipped from test.test_support import verbose, run_unittest
import unittest
import nis import nis
print 'nis.maps()' class NisTests(unittest.TestCase):
def test_maps(self):
try: try:
maps = nis.maps() maps = nis.maps()
except nis.error, msg: except nis.error, msg:
# NIS is probably not active, so this test isn't useful # NIS is probably not active, so this test isn't useful
if verbose: if verbose:
raise TestFailed, msg self.fail("(failing because of verbose mode) %s" % msg)
# only do this if running under the regression suite return
raise TestSkipped, msg
try: try:
# On some systems, this map is only accessible to the # On some systems, this map is only accessible to the
# super user # super user
@ -20,16 +20,12 @@ except ValueError:
done = 0 done = 0
for nismap in maps: for nismap in maps:
if verbose:
print nismap
mapping = nis.cat(nismap) mapping = nis.cat(nismap)
for k, v in mapping.items(): for k, v in mapping.items():
if verbose:
print ' ', k, v
if not k: if not k:
continue continue
if nis.match(k, nismap) != v: if nis.match(k, nismap) != v:
print "NIS match failed for key `%s' in map `%s'" % (k, nismap) self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap))
else: else:
# just test the one key, otherwise this test could take a # just test the one key, otherwise this test could take a
# very long time # very long time
@ -37,3 +33,9 @@ for nismap in maps:
break break
if done: if done:
break break
def test_main():
run_unittest(NisTests)
if __name__ == '__main__':
test_main()