Total Complexity | 5 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import os |
||
2 | from fastest.bodies import f |
||
3 | |||
4 | |||
5 | def build(function_objects, src_file_path, base_path): |
||
6 | test_file_name = src_file_path.split('/')[-1].replace('.py', '__test.py') |
||
7 | deps_import = src_file_path.replace(base_path + '/', '').replace('/', '.').replace('.py', '') |
||
8 | root_module_name = deps_import.split('.')[-1] |
||
9 | test_file_path = os.path.join(base_path, 'test', test_file_name) |
||
10 | |||
11 | with open(test_file_path, 'w+') as fp: |
||
12 | fp.write('import unittest\n\n') |
||
13 | for function_object in function_objects: |
||
14 | fp.write('from {} import {}\n'.format(deps_import, function_object['name'])) |
||
15 | |||
16 | for function_object in function_objects: |
||
17 | fp.write( |
||
18 | """\n |
||
19 | class Test_{}_{}(unittest.TestCase): |
||
20 | |||
21 | """.format(root_module_name, function_object['name']) |
||
22 | ) |
||
23 | for test in function_object['tests']: |
||
24 | fp.write(f.create_naive_test_case(function_object, test)) |