mardi 19 novembre 2019

Should you test primitive functions in Python?

I am currently rewriting a large data framework for my company. My company has a basically nonexistent testing policy and I want to change that, but I am very new to testing software. Thus I wanted to ask the following question -

If I have the following function:

def read_attributes(annotation_file=IMPORTED_PATH):
    attributes = {}
    with open(annotation_file) as ga:
        for idx, line in enumerate(ga):
            fields = [field.strip() for field in line.split('\t')]
            if idx == 0:
                continue
            else:
                attributes[fields[0]] = fields[6] #0 - sample, 6 - tissue

    return attributes

I don't see the point in actually unit-testing it, if I have a previous test that checks if file at IMPORTED_PATH actually exists.

I have tried to test whether certain keys are present in the resulting attributes dictionary, but I see that as volatile because file at IMPORTED_PATH can change it's values. I could also write an if statement checking whether fields variable has the necessary amount of entries, but that is more of an internal check than a test.

Should I test this and how would I go about it?

Aucun commentaire:

Enregistrer un commentaire