[CalendarServer-changes] [9011] CalendarServer/trunk/calendarserver/tools/shell

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 10 13:05:15 PDT 2012


Revision: 9011
          http://trac.macosforge.org/projects/calendarserver/changeset/9011
Author:   wsanchez at apple.com
Date:     2012-04-10 13:05:15 -0700 (Tue, 10 Apr 2012)
Log Message:
-----------
Fix test_cmd

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/shell/terminal.py
    CalendarServer/trunk/calendarserver/tools/shell/test/test_cmd.py

Modified: CalendarServer/trunk/calendarserver/tools/shell/terminal.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell/terminal.py	2012-04-10 19:49:31 UTC (rev 9010)
+++ CalendarServer/trunk/calendarserver/tools/shell/terminal.py	2012-04-10 20:05:15 UTC (rev 9011)
@@ -127,11 +127,11 @@
 
     emulation_modes = ("emacs", "none")
 
-    def __init__(self, service):
+    def __init__(self, service, commandsClass=Commands):
         ReceiveLineProtocol.__init__(self)
         self.service = service
         self.inputLines = []
-        self.commands = Commands(self, RootFolder(service))
+        self.commands = commandsClass(self, RootFolder(service))
         self.activeCommand = None
         self.emulate = "emacs"
 

Modified: CalendarServer/trunk/calendarserver/tools/shell/test/test_cmd.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell/test/test_cmd.py	2012-04-10 19:49:31 UTC (rev 9010)
+++ CalendarServer/trunk/calendarserver/tools/shell/test/test_cmd.py	2012-04-10 20:05:15 UTC (rev 9011)
@@ -22,40 +22,39 @@
 
 from calendarserver.tools.shell.cmd import CommandsBase
 from calendarserver.tools.shell.vfs import RootFolder
+from calendarserver.tools.shell.terminal import ShellProtocol
 
 
 class TestCommandsBase(twisted.trial.unittest.TestCase):
 
+    def setUp(self):
+        self.protocol = ShellProtocol(None, commandsClass=CommandsBase)
+        self.commands = self.protocol.commands
+
     @inlineCallbacks
     def test_getTargetNone(self):
-        cmd = CommandsBase(RootFolder(None))
-        target = (yield cmd.getTarget([]))
-        self.assertEquals(target, cmd.wd)
+        target = (yield self.commands.getTarget([]))
+        self.assertEquals(target, self.commands.wd)
 
     def test_getTargetMissing(self):
-        cmd = CommandsBase(RootFolder(None))
-        self.assertFailure(cmd.getTarget(["/foo"]), NotFoundError)
+        self.assertFailure(self.commands.getTarget(["/foo"]), NotFoundError)
 
     @inlineCallbacks
     def test_getTargetOne(self):
-        cmd = CommandsBase(RootFolder(None))
-        target = (yield cmd.getTarget(["users"]))
-        match = (yield cmd.wd.locate(["users"]))
+        target = (yield self.commands.getTarget(["users"]))
+        match = (yield self.commands.wd.locate(["users"]))
         self.assertEquals(target, match)
 
     @inlineCallbacks
     def test_getTargetSome(self):
-        cmd = CommandsBase(RootFolder(None))
-        target = (yield cmd.getTarget(["users", "blah"]))
-        match = (yield cmd.wd.locate(["users"]))
+        target = (yield self.commands.getTarget(["users", "blah"]))
+        match = (yield self.commands.wd.locate(["users"]))
         self.assertEquals(target, match)
 
     def test_commandsNone(self):
-        cmd = CommandsBase(RootFolder(None))
-        commands = cmd.commands()
+        allCommands = self.commands.commands()
+        self.assertEquals(sorted(allCommands), [])
 
-        self.assertEquals(sorted(commands), [])
-
     def test_commandsSome(self):
         class SomeCommands(CommandsBase):
             def cmd_a(self, tokens):
@@ -66,12 +65,14 @@
                 pass
             cmd_hidden.hidden = "Hidden"
 
-        cmd = SomeCommands(RootFolder(None))
-        commands = cmd.commands()
+        protocol = ShellProtocol(None, commandsClass=SomeCommands)
+        commands = protocol.commands
 
+        allCommands = commands.commands()
+
         self.assertEquals(
-            sorted(commands),
-            [ ("a", cmd.cmd_a), ("b", cmd.cmd_b) ]
+            sorted(allCommands),
+            [ ("a", commands.cmd_a), ("b", commands.cmd_b) ]
         )
 
     def test_complete(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120410/6ebf9861/attachment.html>


More information about the calendarserver-changes mailing list