Esempio n. 1
0
def _flask_tester(func, pool_function=None):
    print '\n\n-------- Testing flask generator for', func.__name__, '\n'
    if os.path.isdir(test_dir):
        shutil.rmtree(test_dir)
    os.mkdir(test_dir)
    shutil.copy('compute.py', test_dir)
    os.chdir(test_dir)
    pool_function_name = '_' + pool_function.__name__ if pool_function is not None else ''
    template = '%s%s_view.html' % (func.__name__, pool_function_name)
    controller = '%s%s_controller.py' % (func.__name__, pool_function_name)
    model = '%s%s_model.py' % (func.__name__, pool_function_name)
    flask_generate(func,
                   default_field='FloatField',
                   filename_template=template,
                   filename_controller=controller,
                   filename_model=model,
                   pool_function=pool_function)
    # Move all generated files to test_dir
    os.rename(os.path.join('templates', template), template)
    os.chdir(os.pardir)
    filenames = template, controller, model
    for filename in filenames:
        assert_equal_files(os.path.join(reference_dir, filename),
                           os.path.join(test_dir, filename),
                           os.path.join(reference_dir, filename),
                           os.path.join(test_dir, filename),
                           msg='failure in test %s, file %s' %
                           (func.__name__, filename))
    shutil.rmtree(test_dir)
Esempio n. 2
0
def _flask_tester(func, pool_function=None):
    print '\n\n-------- Testing flask generator for', func.__name__, '\n'
    if os.path.isdir(test_dir):
        shutil.rmtree(test_dir)
    os.mkdir(test_dir)
    shutil.copy('compute.py', test_dir)
    os.chdir(test_dir)
    pool_function_name = '_' + pool_function.__name__ if pool_function is not None else ''
    template = '%s%s_view.html' % (func.__name__, pool_function_name)
    controller = '%s%s_controller.py' % (func.__name__, pool_function_name)
    model = '%s%s_model.py' % (func.__name__, pool_function_name)
    flask_generate(func,
                   default_field='FloatField',
                   filename_template=template,
                   filename_controller=controller,
                   filename_model=model,
                   pool_function=pool_function)
    # Move all generated files to test_dir
    os.rename(os.path.join('templates', template), template)
    os.chdir(os.pardir)
    filenames = template, controller, model
    for filename in filenames:
        assert_equal_files(
            os.path.join(reference_dir, filename),
            os.path.join(test_dir, filename),
            os.path.join(reference_dir, filename),
            os.path.join(test_dir, filename),
            msg='failure in test %s, file %s' % (func.__name__, filename))
    shutil.rmtree(test_dir)
Esempio n. 3
0
def _django_tester(func, pool_function=None):
    print '\n\n-------- Testing django generator for', func.__name__, '\n'
    if os.path.isdir(test_dir):
        shutil.rmtree(test_dir)
    os.mkdir(test_dir)
    shutil.copy('compute.py', test_dir)
    os.chdir(test_dir)
    pool_function_name = '_' + pool_function.__name__ if pool_function is not None else ''
    template = '%s%s_index.html' % (func.__name__, pool_function_name)
    views = '%s%s_views.py' % (func.__name__, pool_function_name)
    models = '%s%s_models.py' % (func.__name__, pool_function_name)
    django_generate(func,
                    default_field='FloatField',
                    filename_template=template,
                    filename_views=views,
                    filename_models=models,
                    pool_function=pool_function)
    # Move all generated files to test_dir
    appdir = os.path.join(func.__name__, 'app').replace('compute_', '')
    os.rename(os.path.join(appdir, 'templates', template), template)
    os.rename(os.path.join(appdir, models), models)
    os.rename(os.path.join(appdir, views), views)
    os.chdir(os.pardir)
    filenames = template, views, models
    for filename in filenames:
        generated = os.path.join(test_dir, filename)
        original = os.path.join(reference_dir, filename)
        print 'comparing', filename, '...'
        assert_equal_files(original,
                           generated,
                           original,
                           generated,
                           msg='failure in test %s, file %s' %
                           (func.__name__, filename))
        # Test login.html, old.html, reg.html if they exist...
    shutil.rmtree(test_dir)
Esempio n. 4
0
def _django_tester(func, pool_function=None):
    print '\n\n-------- Testing django generator for', func.__name__, '\n'
    if os.path.isdir(test_dir):
        shutil.rmtree(test_dir)
    os.mkdir(test_dir)
    shutil.copy('compute.py', test_dir)
    os.chdir(test_dir)
    pool_function_name = '_' + pool_function.__name__ if pool_function is not None else ''
    template = '%s%s_index.html' % (func.__name__, pool_function_name)
    views = '%s%s_views.py' % (func.__name__, pool_function_name)
    models = '%s%s_models.py' % (func.__name__, pool_function_name)
    django_generate(func,
                    default_field='FloatField',
                    filename_template=template,
                    filename_views=views,
                    filename_models=models,
                    pool_function=pool_function)
    # Move all generated files to test_dir
    appdir = os.path.join(func.__name__, 'app').replace('compute_', '')
    os.rename(os.path.join(appdir, 'templates', template), template)
    os.rename(os.path.join(appdir, models), models)
    os.rename(os.path.join(appdir, views), views)
    os.chdir(os.pardir)
    filenames = template, views, models
    for filename in filenames:
        generated = os.path.join(test_dir, filename)
        original = os.path.join(reference_dir, filename)
        print 'comparing', filename, '...'
        assert_equal_files(
            original,
            generated,
            original,
            generated,
            msg='failure in test %s, file %s' % (func.__name__, filename))
        # Test login.html, old.html, reg.html if they exist...
    shutil.rmtree(test_dir)
Esempio n. 5
0
def test_generator_django2():
    if os.path.isdir('myfunc'):
        shutil.rmtree('myfunc')
    if os.path.isfile('clean.sh'):
        failure = os.system('sh clean.sh')
        assert failure == False, 'could not run clean.sh'
    failure = os.system('python generate_django2.py')
    assert failure == False, 'could not run generate_django2.py'
    assert_equal_files(os.path.join('myfunc', 'app', 'models.py'),
                       'reference_django2_models.py')
    assert_equal_files(os.path.join('myfunc', 'app', 'views.py'),
                       'reference_django2_views.py')
    assert_equal_files(os.path.join('myfunc', 'app', 'templates', 'index.html'),
                       'reference_django2_index.html')
    if os.path.isdir('myfunc'):
        shutil.rmtree('myfunc')
    if os.path.isdir('static'):
        shutil.rmtree('static')
Esempio n. 6
0
def test_generator_flask1():
    if os.path.isfile('clean.sh'):
        failure = os.system('sh clean.sh')
        assert failure == False, 'could not run clean.sh'
    failure = os.system('python generate_flask1.py')
    assert failure == False, 'could not run generate_flask1.py'
    assert_equal_files('model.py', 'reference_flask1_model.py')
    assert_equal_files('controller.py', 'reference_flask1_controller.py')
    assert_equal_files(os.path.join('templates', 'view.html'),
                       'reference_flask1_view.html')
    if os.path.isfile('clean.sh'):
        os.system('sh clean.sh')  # clean up
    else:
        for name in ['static', 'templates', 'uploads', 'model.py',
                     'controller.py',] + glob.glob('*.pyc'):
            if os.path.isfile(name):
                os.remove(name)
            elif os.path.isdir(name):
                shutil.rmtree(name)