# Path: utils/v4l.py
# def v4l_get_name(device='video0'):
#     path_pattern = "/sys/class/video4linux/%s/name"
#     from utils.files import read_file
#     path = path_pattern %device
#     return read_file(path).strip() 
# 
# def v4l_get_devices():
#     return os.listdir('/sys/class/video4linux')
# 
# def v4l_set_current_device(device):
#     os.environ['V4L2_TEST_DEVICE'] = device
# 
# Path: utils/colors.py
# class Colors():
#     RED = '\033[91m'
#     GREEN = '\033[92m'
#     YELLOW = '\033[93m'
#     BLUE = '\033[94m'
#     PURPLE = '\033[95m'
#     TEAL = '\033[96m'
#     DEFAULT = '\033[0m'


import os
import sys
import imp
    import argparse
from utils.v4l import v4l_get_name, v4l_get_devices, v4l_set_current_device
from utils.colors import Colors
TESTS_DIR = 'tests'

def scan_test_folder(folder=TESTS_DIR):
    test_files = list()
    for root, dirs, files in os.walk(folder):
        for f in files:
            if f.endswith('.py'):
                test_files.append(os.path.join(root, f))
    return test_files

def run_tests(test_files):
    print('Will run the following tests \n\t%s' % "\n\t".join(test_files))
    results = list()

    for test_file in test_files:
        test_name = os.path.splitext(test_file)[0]
        test_module = imp.load_source(test_name, test_file)

        if hasattr(test_module, 'get_test_banner'):
            banner = test_module.get_test_banner()
        else:
            banner = "Test: %s" %(test_name)

        def run_test(test_module, test_banner):
            print("\n>>> Running %s" %test_banner)
            #results.append("\n%s" %test_banner)
            result, t_info = test_module.run()
            if result:
                info = "%s[Pass]%s" %(Colors.GREEN, Colors.DEFAULT)
            else:

# Path: utils/v4l.py
# def v4l_get_name(device='video0'):
#     path_pattern = "/sys/class/video4linux/%s/name"
#     from utils.files import read_file
#     path = path_pattern %device
#     return read_file(path).strip() 
# 
# def v4l_get_devices():
#     return os.listdir('/sys/class/video4linux')
# 
# def v4l_set_current_device(device):
#     os.environ['V4L2_TEST_DEVICE'] = device
# 
# Path: utils/colors.py
# class Colors():
#     RED = '\033[91m'
#     GREEN = '\033[92m'
#     YELLOW = '\033[93m'
#     BLUE = '\033[94m'
#     PURPLE = '\033[95m'
#     TEAL = '\033[96m'
#     DEFAULT = '\033[0m'


# Path: run_tests.py
import os
import sys
import imp
    import argparse
from utils.v4l import v4l_get_name, v4l_get_devices, v4l_set_current_device
from utils.colors import Colors

TESTS_DIR = 'tests'

def scan_test_folder(folder=TESTS_DIR):
    test_files = list()
    for root, dirs, files in os.walk(folder):
        for f in files:
            if f.endswith('.py'):
                test_files.append(os.path.join(root, f))
    return test_files

def run_tests(test_files):
    print('Will run the following tests \n\t%s' % "\n\t".join(test_files))
    results = list()

    for test_file in test_files:
        test_name = os.path.splitext(test_file)[0]
        test_module = imp.load_source(test_name, test_file)

        if hasattr(test_module, 'get_test_banner'):
            banner = test_module.get_test_banner()
        else:
            banner = "Test: %s" %(test_name)

        def run_test(test_module, test_banner):
            print("\n>>> Running %s" %test_banner)
            #results.append("\n%s" %test_banner)
            result, t_info = test_module.run()
            if result:
                info = "%s[Pass]%s" %(Colors.GREEN, Colors.DEFAULT)
            else:

                info = "%s[Fail]%s" %(Colors.RED, Colors.DEFAULT)