Beispiel #1
0
def get_django_test(view, target):
    test_fn = get_current_test_function(view)

    if not test_fn:
        return

    # Test functions must start with `test_`.
    if test_fn.startswith('test_') is False:
        return

    filename = view.file_name()
    test_cls = class_finder.find_class(filename, test_fn)
    app_name = find_django_app_name(filename)
    test_name = None

    if not app_name or not test_cls:
        return None

    if target == 'method':
        test_name = '%s.%s.%s' % (app_name, test_cls, test_fn)
    elif target == 'class':
        test_name = '%s.%s' % (app_name, test_cls)
    elif target == 'suite':
        test_name = app_name

    return test_name
Beispiel #2
0
def get_nose_test(view, target):
    test_fn = get_current_test_function(view)

    # Test functions must start with `test_`.
    if test_fn and test_fn.startswith('test_') is False:
        return

    filename = view.file_name()
    test_cls = class_finder.find_class(filename, test_fn)
    project_root = find_project_root(filename)
    filename = filename[len(project_root):]
    filename = filename.lstrip(os.path.sep)
    import_string = make_import_string(filename)
    test_name = None

    if target == 'method':
        test_name = '%s:%s.%s' % (import_string, test_cls, test_fn)
    elif target == 'class':
        test_name = '%s:%s' % (import_string, test_cls)
    elif target == 'suite':
        test_name = import_string

    return test_name