Problem with code testing using unittest library

This is the place for queries that don't fit in any of the other categories.

Problem with code testing using unittest library

Postby nick123 » Sat Jul 20, 2013 5:38 pm

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:

Code: Select all
 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:
                try:
                    RegExp = re.compile(pattern.regex)
                if RegExp.match(message):
                    ret_status = 1
                    ret_pattern = pattern.ID
                    break

        return ret_status, ret_pattern



Code: Select all
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])
        else:
            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.
nick123
 
Posts: 1
Joined: Sat Jul 20, 2013 5:18 pm

Return to General Coding Help

Who is online

Users browsing this forum: Mekire and 2 guests