Testing a CLI made with docopt, with unittest

109 Views Asked by At

There is a part of the code in the file fastq_trimmer.py:

if __name__ == '__main__':
    usage = '''
    Fastq Trimmer CLI.

    Usage:
        fastq_trimmer.py trim <filePath> <trimFactor>

    '''

    args = docopt(usage)

    if args['trim']:
        commenceOperation(args)
    else:
        print(usage)

Im trying to write a unittest :

import fastq_trimmer
from docopt import docopt

doc = fastq_trimmer.commenceOperation(args)

class TestTrimmer(unittest.TestCase):

    def test_exceptions(self):
        args = docopt(doc, ["/home/eliran/Desktop/example.fastq", "5"])
        self.assertEqual(args["<filePath>"], "/home/eliran/Desktop/example.fastq")
        self.assertEqual(args["<trimFactor>"], "5")

basically im trying to control the args variable from the unittest file so I can 'inject' the CLI with the args i specify in the unittest file.

0

There are 0 best solutions below