示例#1
0
    def create(cls, path_name=None, name=None, project_id=None,
               log_modified_at=None):
        """Initialize an instance and save it to db."""
        result = cls(path_name, name, project_id, log_modified_at)

        db.session.add(result)
        db.session.commit()

        crawl_result(result, True)

        return result
示例#2
0
def test_crawl_result_invalid_default_name_file(func_dir):
    conf_path = os.path.join(func_dir, '.chainerui_conf')
    with open(conf_path, 'w') as f:
        f.write('{"default_result_name": "default_name"')  # broken JSON
    result = Result(func_dir)
    assert result.name is None

    result2 = crawl_result(result, force=True, commit=False)
    assert result2.name is None
示例#3
0
def test_crawl_result_reset(func_dir):
    # basic test is checked on 'test_api.py', so this test checks only
    # reset logic.
    result = Result(func_dir)
    result.updated_at = datetime.datetime.now()
    result.logs = [Log({'loss': 0.5}), Log({'loss': 0.2}), Log({'loss': 0.01})]
    result.commands = [Command('take_sanpshot'), Command('stop')]
    result.snapshots = [
        Snapshot('snapshot_iter_10', 10), Snapshot('snapshot_iter_11', 11)]

    actual = crawl_result(result, force=True, commit=False)
    assert len(actual.logs) == 2
    assert len(actual.commands) == 1
    assert len(actual.snapshots) == 1

    open(os.path.join(func_dir, 'snapshot_iter_200'), 'w').close()

    actual2 = crawl_result(actual, force=True, commit=False)
    assert len(actual2.logs) == 2
    assert len(actual2.commands) == 1
    assert len(actual2.snapshots) == 2
示例#4
0
def test_crawl_result_default_name(func_dir):
    conf_path = os.path.join(func_dir, '.chainerui_conf')
    chainerui_conf = {'dummy_key': 'default_name'}
    with open(conf_path, 'w') as f:
        json.dump(chainerui_conf, f)
    # basic test is checked on 'test_api.py', so this test checks only
    # reset logic.
    result = Result(func_dir)
    assert result.name is None

    result2 = crawl_result(result, force=True, commit=False)
    assert result2.name is None

    chainerui_conf['default_result_name'] = 'default_name'
    with open(conf_path, 'w') as f:
        json.dump(chainerui_conf, f)
    result3 = crawl_result(result2, force=True, commit=False)
    assert result3.name == 'default_name'

    chainerui_conf['default_result_name'] = 'updated_name'
    with open(conf_path, 'w') as f:
        json.dump(chainerui_conf, f)
    result4 = crawl_result(result3, force=True, commit=False)
    assert result4.name == 'default_name'  # not updated