1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Rep Power

    Problem with code testing using unittest library

    Hi all,
    For few days I'm trying to lern how to properly use unittest library in Python. I've got some basics but I've made myself a challenge - test two functions that I made before. These are the functions:

    def PatternMatch(self, message, number):
    ret_status = 2 # 'No match'
    ret_pattern = -1

    for pattern in self.PatternList:
    if pattern.active == 1 and pattern.LA == number:
    RegExp = re.compile(pattern.regex)
    if RegExp.match(message):
    ret_status = 1
    ret_pattern = pattern.ID

    return ret_status, ret_pattern

    def GetPattern(self, patternID):
    pattern = None
    db = Database()
    query = 'CALL PATTERN_GET'
    query += '(@sql_err_code, @my_status, @my_msg, %s)'
    ret = db.query(query, [patternID])
    if len(ret['data']) == 2:
    pattern = Pattern(ret['data'][1])
    pattern = Pattern()

    result = {'status': ret['data'][0]}
    return pattern, result

    How should i start? I have mocked the database connection using the mox library and it works but what about the functionality? I appreciate any help.
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    You might start by writing input with corresponding expected output.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo