Пример #1
0
def test_get_score_single(tmpdir):
    register = ScoreRegister(EVENT, os.path.join(tmpdir, "db.csv"))
    register.register_score(metadata=METADATA,
                            score_key=SCORE_KEY,
                            score_increment=SCORE_INCREMENT)
    current_score = register.get_score(METADATA, SCORE_TABLE)
    assert current_score[SCORE_KEY] == SCORE_INCREMENT
Пример #2
0
def test_corrupt_file(tmpdir):
    filename = os.path.join(tmpdir, "db.csv")
    register = ScoreRegister(EVENT, filename)
    register.register_score(metadata=METADATA,
                            score_key=SCORE_KEY,
                            score_increment=SCORE_INCREMENT)
    with open(filename, "a") as f:
        f.write("\nfoo")
    with pytest.raises(ValueError):
        ScoreRegister(EVENT, filename)
Пример #3
0
def test_load_from_file_twice(tmpdir):
    register = ScoreRegister(EVENT, os.path.join(tmpdir, "db.csv"))
    register.register_score(metadata=METADATA,
                            score_key=SCORE_KEY,
                            score_increment=SCORE_INCREMENT)
    register2 = ScoreRegister(EVENT, os.path.join(tmpdir, "db.csv"))
    register2.register_score(metadata=METADATA,
                             score_key=SCORE_KEY,
                             score_increment=SCORE_INCREMENT)
    current_score = register2.get_score(METADATA, SCORE_TABLE)
    assert current_score[SCORE_KEY] == 2 * SCORE_INCREMENT
Пример #4
0
def test_different_metadata(tmpdir):
    register = ScoreRegister(EVENT, os.path.join(tmpdir, "db.csv"))
    register.register_score(metadata=METADATA,
                            score_key=SCORE_KEY,
                            score_increment=SCORE_INCREMENT)
    metadata2 = MetaData(METADATA.team, METADATA.challenge,
                         METADATA.attempt + 1)
    register.register_score(metadata=metadata2,
                            score_key=SCORE_KEY + 1,
                            score_increment=2 * SCORE_INCREMENT)
    current_score = register.get_score(METADATA, SCORE_TABLE)
    assert current_score[SCORE_KEY] == SCORE_INCREMENT
    current_score = register.get_score(metadata2, SCORE_TABLE)
    assert current_score[SCORE_KEY + 1] == 2 * SCORE_INCREMENT
Пример #5
0
 def _create_score_register(path: str, event: str) -> ScoreRegister:
     os.makedirs(path, exist_ok=True)
     filename = os.path.join(path, "score_db.csv")
     return ScoreRegister(event, filename)
Пример #6
0
def test_register_score(tmpdir):
    register = ScoreRegister(EVENT, os.path.join(tmpdir, "db.csv"))
    register.register_score(metadata=METADATA,
                            score_key=SCORE_KEY,
                            score_increment=SCORE_INCREMENT)