<commit_before>import redisorm.core
import os
import pytest
import redis

@pytest.fixture
def test_redis():
    port = os.environ.get("TEST_REDIS_PORT")
    r = redis.StrictRedis(port=port, decode_responses=True)
    r.ping()
    r.flushdb()
    return r

def test_persistent_prefix():
    redisorm.core.Persistent("paco")

def test_persistent_set_redis(test_redis):
    redisorm.core.Persistent("paco", r=test_redis)

class SamplePersistentObject(redisorm.core.PersistentData):
    def __init__(self, id=None, arg01="", arg02=""):
        self.id = id
        self.arg01 = arg01
        self.arg02 = arg02

def test_persistent_basic_save_and_load(test_redis):
    p = redisorm.core.Persistent("paco", r=test_redis)
    obj = SamplePersistentObject(arg01="hoge", arg02="fuga")
    p.save(obj)
    loaded = p.load(SamplePersistentObject, 0)
    assert loaded.arg01 == obj.arg01
    assert loaded.arg02 == obj.arg02

def test_persistent_save_and_load_with_int(test_redis):
    p = redisorm.core.Persistent("paco", r=test_redis)
    obj = SamplePersistentObject(arg01=3, arg02="fuga")
    p.save(obj)
    loaded = p.load(SamplePersistentObject, 0)
    assert loaded.arg01 == str(obj.arg01)
    assert loaded.arg02 == obj.arg02
<commit_msg>add update_id test<commit_after>import redisorm.core
import os
import pytest
import redis

@pytest.fixture
def test_redis():
    port = os.environ.get("TEST_REDIS_PORT")
    r = redis.StrictRedis(port=port, decode_responses=True)
    r.ping()
    r.flushdb()
    return r

def test_persistent_prefix():
    redisorm.core.Persistent("paco")

def test_persistent_set_redis(test_redis):
    redisorm.core.Persistent("paco", r=test_redis)

class SamplePersistentObject(redisorm.core.PersistentData):
    def __init__(self, id=None, arg01="", arg02=""):
        self.id = id
        self.arg01 = arg01
        self.arg02 = arg02

def test_persistent_basic_save_and_load(test_redis):
    p = redisorm.core.Persistent("paco", r=test_redis)
    obj = SamplePersistentObject(arg01="hoge", arg02="fuga")
    p.save(obj)
    loaded = p.load(SamplePersistentObject, 0)
    assert loaded.arg01 == obj.arg01
    assert loaded.arg02 == obj.arg02

def test_persistent_auto_increment_id(test_redis):
    p = redisorm.core.Persistent("paco", r=test_redis)
    obj1 = SamplePersistentObject(arg01="hoge", arg02="fuga")
    obj2 = SamplePersistentObject(arg01="hoge", arg02="fuga")
    obj3 = SamplePersistentObject(arg01="hoge", arg02="fuga")
    p.save(obj1)
    assert obj1.id == "0"
    p.save(obj2)
    assert obj2.id == "1"
    p.save(obj3)
    assert obj3.id == "2"

def test_persistent_save_and_load_with_int(test_redis):
    p = redisorm.core.Persistent("paco", r=test_redis)
    obj = SamplePersistentObject(arg01=3, arg02="fuga")
    p.save(obj)
    loaded = p.load(SamplePersistentObject, 0)
    assert loaded.arg01 == str(obj.arg01)
    assert loaded.arg02 == obj.arg02

{'fraction_non_alphanumeric': 0.12556053811659193, 'fraction_numerical': 0.03518454639530873, 'mean_word_length': 4.2631578947368425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6770959', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1083, 'n_words': 180}