title: How do I write a unit test code for this piece of code
body: <p>Below is my code which replaces some characters in string based on the key available in the dictionary:</p>
  
  <pre><code>import re
  
  D = {'h':'hhh', 'l':'nnn'}
  enpattern = re.compile(r'(.)\1?', re.IGNORECASE)
  
  def convert(str):
      result = [x.group() for x in enpattern.finditer(str)]
      data = ''.join(map(lambda x:D.get(x.lower(), x.lower()), result))
      print data
  </code></pre>
  
  <p>How do i write a unit test for this code such that the arguments to convert() is never a integer and it should accept only strings or special characters like <code>'$'</code>.</p>
  
  <p>How to write a unit test such that I can check for <code>char</code>, <code>int</code> or any other data types that can be passed as an argument generally.</p>