import os, time
from HTMLTestRunner import HTMLTestRunner
from test_case import TestDemo
import unittest


from types import FunctionType




# TestDemo3 = unittest.TestCase
# TestDemo3.test_007 = test_007
# TestDemo3.test_007.__module__= TestDemo3


obj = type("TestCases",(unittest.TestCase,),dict())
obj.__doc__ = 'Doc'
obj.test_demo0123456789ABCDEF_000000 = FunctionType(compile('def foo(self): import time; time.sleep(0)', "", "exec").co_consts[0], globals(), "foo")
obj.test_demo1 = FunctionType(compile('def foo(self): return "bar"', "", "exec").co_consts[0], globals(), "foo")
obj.test_demo2 = FunctionType(compile('def foo(self): assert 1 == 2', "", "exec").co_consts[0], globals(), "foo")
obj.test_demo3 = FunctionType(compile('def foo(): return "bar"', "", "exec").co_consts[0], globals(), "foo")
obj.test_demo1.__qualname__ = "test_demo1"
obj.test_demo1.__doc__ = "这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；"
obj.test_demo2.__qualname__ = "test_demo2"
obj.test_demo2.__doc__ = "这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；这是一条测试用例；"
obj.test_demo3.__qualname__ = "test_demo3"
obj.test_demo3.__doc__ = "这是一条测试用例；这是一条测试用例；这是一条测试用例；"
# print(obj)

# foo_code = compile('def foo(): return "bar"', "", "exec")
# print(foo_code)
# foo_func = FunctionType(foo_code.co_consts[0], globals(), "foo")
# foo_func.__qualname__ = "test_demo"
# print(foo_func)




base_path = os.path.dirname(__file__)
report_path = base_path
report_filename = os.path.join(report_path, 'report.html')

case_suite = unittest.TestSuite()
case_suite.addTest(TestDemo('test_one'))
case_suite.addTest(TestDemo('test_two'))
case_suite.addTest(TestDemo('test_tre'))
case_suite.addTest(obj('test_demo1'))
# case_suite.addTest(TestDemo('test_0123456789ABCDEF_123456_000000'))

# case_suite.addTest(obj('test_demo1'))
# case_suite.addTest(obj('test_demo1'))
# case_suite.addTest(obj('test_demo1'))
# case_suite.addTest(obj('test_demo1'))
# case_suite.addTest(obj('test_demo1'))
# case_suite.addTest(obj('test_demo1'))
# case_suite.addTest(obj('test_demo1'))
# case_suite.addTest(obj('test_demo1'))
# case_suite.addTest(obj('test_demo1'))
# case_suite.addTest(obj('test_demo2'))
# case_suite.addTest(obj('test_demo3'))


def start():
    with open(report_filename, 'wb') as f:
        runner = HTMLTestRunner(stream=f,
                                title='自动化测试报告',
                                verbosity=2,
                                description='描述',
                                tester='DESKTOP')
        runner.run(case_suite)


if __name__ == '__main__':
    start()
