lundi 1 février 2016

How to write tests for main() function that does not return anything

I'm trying to test the code in the main() but I'm a bit unsure how to go about it since I'm not passing any arguments or even returning anything. For the purposes of the example I've shortened the tree statements in the function..

Can anyone point me in the right direction on how to test the logic below? Also I did google to see if this question had already been asked but I couldn't find it, so if it was apologies did not mean to ask again.

script.py

from . import settings


def main():
    if settings.PATHS:  # list containing full paths to a directory of files
        paths = settings.PATHS
        for path in paths:
            data = read_file(path)
            modified_data = do_something_with_the_data_collected(data)
            write_to_new_file(modified_data)
    else:
        logger.warning("There are no files in {}".format(settings.FILES_DIRECTORY))

if __name__ == '__main__':
    main()

tests/file_tests.py

import unittest

from module.script import main


class FileManagerTests(unittest.TestCase):

    def test_main_func(self):
        main()  # ?? this is where I am stuck, should I just test 
                # that it logs correctly if certain data exists 
                # in settings file?

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

Aucun commentaire:

Enregistrer un commentaire