Beispiel #1
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()
Beispiel #2
0
    def test_setup_import_error(self):
        try:
            import fdb  # NOQA
            pytest.skip(
                'expected that fdb is not installed on testing environment')
        except (ImportError, TypeError):
            pass

        from chainerui.database import db
        db_url = 'firebird+fdb://user:password@host:3050/path/to/db'
        assert not db.setup(url=db_url)

        assert not db._initialized
        with pytest.raises(ValueError) as e:
            db.url
        assert 'DB URL' in str(e.value)
        with pytest.raises(ValueError) as e:
            db.engine
        assert 'database engine' in str(e.value)
        with pytest.raises(ValueError) as e:
            db.session
        assert 'database session' in str(e.value)
        with pytest.raises(ValueError) as e:
            db.alembic_config
        assert 'migration configuration' in str(e.value)
Beispiel #3
0
    def test_setup_default_db(self):
        from chainerui.database import db
        db.init_db()
        assert db.setup(url=None)

        assert db._initialized
        assert db.url == 'sqlite:///' + os.path.join(self.dir, 'db',
                                                     'chainerui.db')
        assert db.engine is not None
        assert db.session is not None
        assert db.alembic_config is not None
Beispiel #4
0
    def test_setup_external_db_file(self):
        from chainerui.database import db
        db_dir = os.path.join(self.dir, 'exdb')
        os.makedirs(db_dir)
        db_url = 'sqlite:///' + os.path.join(db_dir, 'sqlite.db')
        assert db.setup(url=db_url)

        assert db._initialized
        assert db.url == db_url
        assert db.engine is not None
        assert db.session is not None
        assert db.alembic_config is not None
Beispiel #5
0
    def test_setup_not_init_error(self):
        from chainerui.database import db
        assert not db.setup(url=None)

        assert not db._initialized
        with pytest.raises(ValueError) as e:
            db.url
        assert 'DB URL' in str(e.value)
        with pytest.raises(ValueError) as e:
            db.engine
        assert 'database engine' in str(e.value)
        with pytest.raises(ValueError) as e:
            db.session
        assert 'database session' in str(e.value)
        with pytest.raises(ValueError) as e:
            db.alembic_config
        assert 'migration configuration' in str(e.value)
Beispiel #6
0
    def test_setup_connection_error(self):
        from chainerui.database import db
        db_dir = os.path.join(self.dir, 'not_exist')
        db_url = 'sqlite:///' + os.path.join(db_dir, 'sqlite.db')
        assert not db.setup(url=db_url)

        assert not db._initialized
        with pytest.raises(ValueError) as e:
            db.url
        assert 'DB URL' in str(e.value)
        with pytest.raises(ValueError) as e:
            db.engine
        assert 'database engine' in str(e.value)
        with pytest.raises(ValueError) as e:
            db.session
        assert 'database session' in str(e.value)
        with pytest.raises(ValueError) as e:
            db.alembic_config
        assert 'migration configuration' in str(e.value)
Beispiel #7
0
def main():
    """make animation GIF for README top

    Required:
      * chainerui==lateset
      * selenium==3.14.1
      * chromedriver-binary==2.42.0
      * Pillow==5.3.0

    Preparation:
      * set original database
      * run server on default, port number '5000' is fixed

    Usage:
      $ mkdir -p $HOME/.chainerui/db/
      $ export CHAINERUI_DB_URL=sqlite:///$HOME/.chainerui/db/gif_ani.db
      $ chainerui db upgrade
      $ chainerui server
      $ # other terminal
      $ python cap_training.py
    """

    base_logs = os.path.join('..', '..', 'examples', 'log-file', 'results')
    log_dirs = ['18003', '18948', '19204', '19205']
    chainerui_url = 'http://localhost:5000/projects/1'
    out = os.path.dirname(os.path.abspath(__file__))

    db_url = os.getenv('CHAINERUI_DB_URL', None)
    if db_url is None:
        raise ValueError('set \'CHAINERUI_DB_URL\', see comment')
    if not db.setup(url=db_url):
        raise ValueError('database initialize error')
    if not app._check_db_revision():
        raise ValueError('unsupported database schema error')

    def load_log(path):
        with open(path, 'rb') as f:
            log_json = json.load(f)
        return log_json
    logs = [load_log(os.path.join(base_logs, d, 'log')) for d in log_dirs]
    snapshots = []

    with tempdir(prefix='chainer_task_') as tempd:
        with chrome_driver() as driver:
            prj_path = os.path.join(tempd, 'result')

            for i in range(11):
                # reset result directory
                if os.path.exists(prj_path):
                    shutil.rmtree(prj_path, ignore_errors=False)
                    os.makedirs(prj_path)

                snap_logs = yield_logs(logs, i)
                prj = create_prj(prj_path, log_dirs, snap_logs)

                driver.get(chainerui_url)
                if i == 0:
                    # checkbox status is memorized, should use 'is_selected'
                    driver.find_element_by_xpath(
                        '/html/body/div/div/div/div/div[1]/div/div/div[1]/ul[1]/li/div[4]/input').click()  # NOQA
                shot_path = os.path.join(tempd, '{:d}.png'.format(i))
                driver.save_screenshot(shot_path)
                snapshots.append(shot_path)

                db.session.delete(prj)
                db.session.commit()

        draw_gif(snapshots, out)