"""Tests for samba.netcmd."""
-from cStringIO import StringIO
+from samba.compat import StringIO
from samba.netcmd import Command
from samba.netcmd.testparm import cmd_testparm
from samba.netcmd.main import cmd_sambatool
import samba.tests
+
class NetCmdTestCase(samba.tests.TestCase):
def run_netcmd(self, cmd_klass, args, retcode=0):
cmd = cmd_klass(outf=StringIO(), errf=StringIO())
try:
retval = cmd._run(cmd_klass.__name__, *args)
- except Exception, e:
+ except Exception as e:
cmd.show_command_error(e)
retval = 1
self.assertEquals(retcode, retval)
return cmd.outf.getvalue(), cmd.errf.getvalue()
def iter_all_subcommands(self):
- todo = []
- todo.extend(cmd_sambatool.subcommands.items())
+ todo = list(cmd_sambatool.subcommands.items())
while todo:
(path, cmd) = todo.pop()
yield path, cmd
subcmds = getattr(cmd, "subcommands", {})
todo.extend([(path + " " + k, v) for (k, v) in
- subcmds.iteritems()])
+ subcmds.items()])
class TestParmTests(NetCmdTestCase):
def test_no_client_ip(self):
out, err = self.run_netcmd(cmd_testparm, ["--client-name=foo"],
- retcode=-1)
+ retcode=-1)
self.assertEquals("", out)
self.assertEquals(
"ERROR: Both a DNS name and an IP address are "
missing.append(path)
if missing:
self.fail("The following commands do not have a synopsis set: %r" %
- missing)
+ missing)
def test_short_description_everywhere(self):
missing = []
return
self.fail(
"The following commands do not have a short description set: %r" %
- missing)
+ missing)