Commit 850b2be6 authored by Georg Brandl's avatar Georg Brandl

Convert test_nis to unittest.

parent eecce795
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):
try: def test_maps(self):
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
maps.remove("passwd.adjunct.byname") maps.remove("passwd.adjunct.byname")
except ValueError: except ValueError:
pass pass
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: ...@@ -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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment