cli: Use difflib to compare expected vs output.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 4 Dec 2012 06:31:58 +0000 (06:31 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 4 Dec 2012 06:31:58 +0000 (06:31 +0000)
cli_driver.py

index 5139b1de27c6c7bdbc22e5449375fb7f711c4031..8016d1853abe76ac77f0ad2a6f46c9c3b4c1a418 100644 (file)
 
 '''Test driver for scripts in the cli directory.'''
 
-import json, errno, shutil, subprocess
+import json
+import errno
+import shutil
+import subprocess
+import difflib
 
 from base_driver import *
 
@@ -49,7 +53,10 @@ class CliDriver(Driver):
     def do_expect(self, args):
         expected = json.loads(args)
         if (self.output != expected):
-            fail("Unexpected output:\n    Expected: %s\n    Received: %s\n" % (expected, self.output))
+            differ = difflib.Differ()
+            diff = differ.compare(expected.splitlines(1), self.output.splitlines(1))
+            diff = ''.join(diff)
+            fail("Unexpected output:\n%s\n" % diff)
 
     def do_rm_and_mkdir(self, args):