<reponame>MarkMoss/ft4222<filename>ft4222_test/test_all.py
# Copyright (c) 2019 <NAME>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""
Executes all tests for the ft4222 module
"""
import sys
import os
import nose


def main():
    """
    Executes all tests for the ft4222 module.
    """
    # Lists tests which can be run using the standard d2xx and libft4222
    # modules.
    tests_using_real_libs = ['test_libft4222_contents',
                             'test_libft4222_types']
    # Lists tests which must be run using the simulating d2xx and libft4222
    # modules
    tests_using_sim_libs = ['test_ft4222']
    # Add UNIT_TEST=1 to the environment.  This allows the test modules to
    # enable any test-specific code.
    test_environ = os.environ
    test_environ["UNIT_TEST"] = "1"
    # Run the tests which can be run using the stadnard d2xx and libft4222
    # modules.
    nose.main(defaultTest=tests_using_real_libs,
              env=test_environ,
              exit=False)
    # Remove modules containing ft4222 or ftd2xx so that the simulation
    # version can be imported.
    remove_modules = []
    for module_name in sys.modules:
        if module_name.find("ft4222") >= 0:
            remove_modules.append(module_name)
        elif module_name.find("ftd2xx") >= 0:
            remove_modules.append(module_name)
    for module_name in remove_modules:
        del sys.modules[module_name]
    # Add environment variables specifying which simulation modules should be
    # loaded.
    test_environ["PY_USE_FTD2XX_MOD"] = "ft4222.simulation.ftd2xx"
    test_environ["PY_USE_LIBFT4222_MOD"] = "ft4222.simulation.libft4222"
    # Run the tests which require the simulation modules.
    nose.main(defaultTest=tests_using_sim_libs,
              env=test_environ,
              exit=False)


if __name__ == '__main__':
    main()
