import sys
import os

def dcopid():
  '''Get dcop id of karm.  Fail if more than one instance running.'''
  id = stdin = stdout = None
  try:
    ( stdin, stdout ) = os.popen2( "dcop" )
    l = stdout.readline()
    while l:
      if l.startswith( "karm" ):
        if not id: id = l
        else: raise "Only one instance of karm may be running."
      l = stdout.readline()
    if not id:
      raise "No karm instance found.  Try running dcop at command-line to verify it works."
  except:
    if stdin: stdin.close()
    if stdout: stdout.close()
    print sys.exc_info()[0]
    sys.exit(1)
  stdin.close()
  stdout.close()

  # strip trailing newline
  return id.strip()

def test( goal, actual ):
  '''Raise exception if goal != actual.'''
  if goal != actual:
    path, scriptname = os.path.split( sys.argv[0] )
    raise "%s: expected '%s', got '%s'" % ( scriptname, goal, actual )

import sys
import os

class KarmTestError( Exception ): pass

def dcopid():
  '''Get dcop id of karm.  Fail if more than one instance running.'''
  id = stdin = stdout = None
  ( stdin, stdout ) = os.popen2( "dcop" )
  l = stdout.readline()
  while l:
    if l.startswith( "karm" ):
      if not id: id = l
      else: raise KarmTestError( "Only one instance of karm may be running." )
    l = stdout.readline()
  if not id:
    raise KarmTestError( "No karm instance found.  Try running dcop at command-line to verify it works." )
  stdin.close()
  stdout.close()

  # strip trailing newline
  return id.strip()

def test( goal, actual ):
  '''Raise exception if goal != actual.'''
  if goal != actual:
    path, scriptname = os.path.split( sys.argv[0] )
    raise KarmTestError( "%s: expected '%s', got '%s'" % ( scriptname, goal, actual ) )

Add KarmTestError we can distinguish and print full tracebacks for unexpected errors. Delete exception trapping--let the test scripts do that.
Add KarmTestError we can distinguish and print full tracebacks for unexpected errors.  Delete exception trapping--let the test scripts do that.

svn path=/trunk/kdepim/; revision=367066

  import sys
  import os
+ 
+ class KarmTestError( Exception ): pass
  
  def dcopid():
    '''Get dcop id of karm.  Fail if more than one instance running.'''
    id = stdin = stdout = None
-   try:
-     ( stdin, stdout ) = os.popen2( "dcop" )
+   ( stdin, stdout ) = os.popen2( "dcop" )
+   l = stdout.readline()
+   while l:
+     if l.startswith( "karm" ):
+       if not id: id = l
+       else: raise KarmTestError( "Only one instance of karm may be running." )
      l = stdout.readline()
-     while l:
-       if l.startswith( "karm" ):
-         if not id: id = l
-         else: raise "Only one instance of karm may be running."
-       l = stdout.readline()
-     if not id:
+   if not id:
-       raise "No karm instance found.  Try running dcop at command-line to verify it works."
+     raise KarmTestError( "No karm instance found.  Try running dcop at command-line to verify it works." )
-   except:
-     if stdin: stdin.close()
-     if stdout: stdout.close()
-     print sys.exc_info()[0]
-     sys.exit(1)
    stdin.close()
    stdout.close()
  
    # strip trailing newline
    return id.strip()
  
  def test( goal, actual ):
    '''Raise exception if goal != actual.'''
    if goal != actual:
      path, scriptname = os.path.split( sys.argv[0] )
-     raise "%s: expected '%s', got '%s'" % ( scriptname, goal, actual )
+     raise KarmTestError( "%s: expected '%s', got '%s'" % ( scriptname, goal, actual ) )
  
Add KarmTestError we can distinguish and print full tracebacks for unexpected errors. Delete exception trapping--let the test scripts do that.
## Code Before:
import sys
import os

def dcopid():
  '''Get dcop id of karm.  Fail if more than one instance running.'''
  id = stdin = stdout = None
  try:
    ( stdin, stdout ) = os.popen2( "dcop" )
    l = stdout.readline()
    while l:
      if l.startswith( "karm" ):
        if not id: id = l
        else: raise "Only one instance of karm may be running."
      l = stdout.readline()
    if not id:
      raise "No karm instance found.  Try running dcop at command-line to verify it works."
  except:
    if stdin: stdin.close()
    if stdout: stdout.close()
    print sys.exc_info()[0]
    sys.exit(1)
  stdin.close()
  stdout.close()

  # strip trailing newline
  return id.strip()

def test( goal, actual ):
  '''Raise exception if goal != actual.'''
  if goal != actual:
    path, scriptname = os.path.split( sys.argv[0] )
    raise "%s: expected '%s', got '%s'" % ( scriptname, goal, actual )

## Instruction:
Add KarmTestError we can distinguish and print full tracebacks for unexpected errors. Delete exception trapping--let the test scripts do that.
## Code After:
import sys
import os

class KarmTestError( Exception ): pass

def dcopid():
  '''Get dcop id of karm.  Fail if more than one instance running.'''
  id = stdin = stdout = None
  ( stdin, stdout ) = os.popen2( "dcop" )
  l = stdout.readline()
  while l:
    if l.startswith( "karm" ):
      if not id: id = l
      else: raise KarmTestError( "Only one instance of karm may be running." )
    l = stdout.readline()
  if not id:
    raise KarmTestError( "No karm instance found.  Try running dcop at command-line to verify it works." )
  stdin.close()
  stdout.close()

  # strip trailing newline
  return id.strip()

def test( goal, actual ):
  '''Raise exception if goal != actual.'''
  if goal != actual:
    path, scriptname = os.path.split( sys.argv[0] )
    raise KarmTestError( "%s: expected '%s', got '%s'" % ( scriptname, goal, actual ) )
