mardi 29 décembre 2020

unittest for method that it reads lines

I am learning unit test and I want to write a testing method for proposals_extract() how can I use unittest for a function which reads line by line of a huge file?

class Conference:

    def __init__(self):
        self.talks = self.proposals_extract()
        self.Track = 1
        
    def proposals_extract(self):
        talks = {}
        f = open('input.txt')
        try:
            while True:
                line = f.readline()
                duration = ''.join(filter(lambda i: i.isdigit(), line))
                if duration:
                    talks[line] = duration
                elif duration == []:
                    print('for proposal {} no duration has been detected'.format(line))
                    break
                if not line:
                    break         
        except FileNotFoundError as e:
                print(e)
        f.close()
        return talks

Aucun commentaire:

Enregistrer un commentaire