Rev 5518: (gz) Throw valid SyntaxError from shell-like tests when a command is not in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Oct 28 01:07:01 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5518 [merge]
revision-id: pqm at pqm.ubuntu.com-20101028000659-ctg5tomt4f7in3bp
parent: pqm at pqm.ubuntu.com-20101026154436-e7lv5qz41x1jh7gl
parent: gzlist at googlemail.com-20101027232741-08684075trtt6d0t
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2010-10-28 01:06:59 +0100
message:
  (gz) Throw valid SyntaxError from shell-like tests when a command is not
   found (Martin [gz])
modified:
  bzrlib/tests/script.py         script.py-20090901081155-yk3tiy1nunxg16ne-1
  bzrlib/tests/test_script.py    test_script.py-20090901081156-y90z4w2t62fv7e7b-1
=== modified file 'bzrlib/tests/script.py'
--- a/bzrlib/tests/script.py	2010-10-20 12:06:13 +0000
+++ b/bzrlib/tests/script.py	2010-10-28 00:06:59 +0000
@@ -213,7 +213,7 @@
         method = getattr(self, mname, None)
         if method is None:
             raise SyntaxError('Command not found "%s"' % (cmd[0],),
-                              None, 1, ' '.join(cmd))
+                              (None, 1, 1, ' '.join(cmd)))
         if input is None:
             str_input = ''
         else:

=== modified file 'bzrlib/tests/test_script.py'
--- a/bzrlib/tests/test_script.py	2010-10-08 06:34:10 +0000
+++ b/bzrlib/tests/test_script.py	2010-10-27 23:27:41 +0000
@@ -161,7 +161,18 @@
 class TestExecution(script.TestCaseWithTransportAndScript):
 
     def test_unknown_command(self):
-        self.assertRaises(SyntaxError, self.run_script, 'foo')
+        """A clear error is reported for commands that aren't recognised
+
+        Testing the attributes of the SyntaxError instance is equivalent to
+        using traceback.format_exception_only and comparing with:
+          File "<string>", line 1
+            foo --frob
+            ^
+        SyntaxError: Command not found "foo"
+        """
+        e = self.assertRaises(SyntaxError, self.run_script, "$ foo --frob")
+        self.assertContainsRe(e.msg, "not found.*foo")
+        self.assertEquals(e.text, "foo --frob")
 
     def test_blank_output_mismatches_output(self):
         """If you give output, the output must actually be blank.




More information about the bazaar-commits mailing list