jeudi 25 février 2016

Unit-testing a function

I am new to unit-testing. However, I need to make a test for the function below. I've done some reading but can't really get much from reading. This is what I have been able to come with but I certainly know there is more to do. Could someone tell me what i would need to do next.

def apply_filter(x): 
    filterer = { 
        1: 'ether proto 0x88B8', 
        2: 'tcp port 102', 
        3: 'ether proto 0x88BA' 
    } 
    return filterer.get(x, '') 



import unittest 

from new_format import apply_filter 


class test_apply_filter(unittest.TestCase): 

    def setUp(self): 
        pass 
    def tearDown(self): 
        pass 

    def test_filter_by_name(self): 
        self.assertEqual(apply_filter(1),"ether proto 0x88B8") 
        self.assertEqual(apply_filter(2),"tcp port 102") 
        self.assertEqual(apply_filter(3),"ether proto 0x88BA") 

if __name__ == '__main__': 
    unittest.main()

Aucun commentaire:

Enregistrer un commentaire