Ejemplo n.º 1
0
def db_handler(args):
    """db_handler."""

    if args.type == 'create':
        if args.db is None:
            db.init_db()
        return

    if not db.setup(url=args.db, echo=args.db_echo):
        return

    if args.type == 'status':
        current_rev = db_revision.current_db_revision()
        print('The current DB schema version:', current_rev)

    if args.type == 'upgrade':
        db.upgrade()

    if args.type == 'revision':
        db_revision.new_revision()

    if args.type == 'drop':
        if args.db is not None:
            db.downgrade()
        db.remove_db()
Ejemplo n.º 2
0
def db_url(func_dir):
    db_path = os.path.join(func_dir, 'test_app.db')
    db_url = 'sqlite:///' + db_path
    yield (db_url)

    if db._session is not None:
        db.session.remove()
    db.remove_db()
Ejemplo n.º 3
0
def func_init_db(func_dir):
    url = 'sqlite:///' + os.path.join(func_dir, 'chainerui.db')
    db.setup(url=url, echo=False)

    yield

    if db._session is not None:
        db.session.remove()
    db.remove_db()
Ejemplo n.º 4
0
    def set_test_root(self):
        os.environ['CHAINERUI_ROOT'] = self.dir

        yield

        # db module is global, required initialize after testing
        from chainerui import db
        if db._session is not None:
            db.session.remove()
        db.remove_db()
Ejemplo n.º 5
0
def project(func_dir):
    db.setup(test_mode=True)
    db.upgrade()

    project_path = os.path.join(func_dir, 'test_project')
    _setup_test_project(project_path)
    project_name = 'my-project'
    Project.create(project_path, project_name)

    yield (project_path, project_name)

    db.session.remove()
    db.remove_db()
Ejemplo n.º 6
0
def result_path(func_dir):
    db.setup(test_mode=True)
    db.upgrade()

    info_path = os.path.join(func_dir, '.chainerui_images')

    with open(os.path.join(func_dir, 'img1_1.png'), 'w') as f:
        f.write('text')
    with open(os.path.join(func_dir, 'img1_2.png'), 'w') as f:
        f.write('text2')
    with open(os.path.join(func_dir, 'img2.png'), 'w') as f:
        f.write('text3')

    test_data = [{
        'iteration':
        1000,
        'epoch':
        1,
        'images':
        OrderedDict([
            ('0', 'img1_1.png'),
            ('1', 'img1_2.png'),
        ])
    }, {
        'iteration': 2000,
        'epoch': 2,
        'custom': 'test',
        'images': OrderedDict([
            ('seg', 'img2.png'),
        ])
    }]
    with open(info_path, 'w') as f:
        json.dump(test_data, f)

    yield (func_dir)

    db.session.remove()
    db.remove_db()
Ejemplo n.º 7
0
 def tearDownClass(cls):
     db.session.remove()
     db.remove_db()