Nettoyage des tests should_rebuild suite à la revue
- Import de should_rebuild au niveau module - Suppression d'un setenv DEVELOPMENT inutile (branche db-missing) - Utilisation de os.utime pour un ordre mtime déterministe refs #71 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+16
-16
@@ -1,7 +1,10 @@
|
|||||||
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from src.db import should_rebuild
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def parquet_and_db(tmp_path, monkeypatch):
|
def parquet_and_db(tmp_path, monkeypatch):
|
||||||
@@ -13,55 +16,52 @@ def parquet_and_db(tmp_path, monkeypatch):
|
|||||||
return parquet, db
|
return parquet, db
|
||||||
|
|
||||||
|
|
||||||
def test_should_rebuild_when_db_missing(parquet_and_db, monkeypatch):
|
def test_should_rebuild_when_db_missing(parquet_and_db):
|
||||||
from src.db import should_rebuild
|
|
||||||
|
|
||||||
parquet, db = parquet_and_db
|
parquet, db = parquet_and_db
|
||||||
monkeypatch.setenv("DEVELOPMENT", "true")
|
|
||||||
assert should_rebuild(db, parquet) is True
|
assert should_rebuild(db, parquet) is True
|
||||||
|
|
||||||
|
|
||||||
def test_should_rebuild_prod_when_parquet_newer(parquet_and_db, monkeypatch):
|
def test_should_rebuild_prod_when_parquet_newer(parquet_and_db, monkeypatch):
|
||||||
from src.db import should_rebuild
|
|
||||||
|
|
||||||
parquet, db = parquet_and_db
|
parquet, db = parquet_and_db
|
||||||
db.write_bytes(b"x")
|
db.write_bytes(b"x")
|
||||||
time.sleep(0.01)
|
|
||||||
parquet.touch()
|
parquet.touch()
|
||||||
|
now = time.time()
|
||||||
|
os.utime(db, (now, now))
|
||||||
|
os.utime(parquet, (now + 10, now + 10))
|
||||||
monkeypatch.setenv("DEVELOPMENT", "false")
|
monkeypatch.setenv("DEVELOPMENT", "false")
|
||||||
assert should_rebuild(db, parquet) is True
|
assert should_rebuild(db, parquet) is True
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_rebuild_prod_when_parquet_older(parquet_and_db, monkeypatch):
|
def test_should_not_rebuild_prod_when_parquet_older(parquet_and_db, monkeypatch):
|
||||||
from src.db import should_rebuild
|
|
||||||
|
|
||||||
parquet, db = parquet_and_db
|
parquet, db = parquet_and_db
|
||||||
parquet.touch()
|
parquet.touch()
|
||||||
time.sleep(0.01)
|
|
||||||
db.write_bytes(b"x")
|
db.write_bytes(b"x")
|
||||||
|
now = time.time()
|
||||||
|
os.utime(parquet, (now, now))
|
||||||
|
os.utime(db, (now + 10, now + 10))
|
||||||
monkeypatch.setenv("DEVELOPMENT", "false")
|
monkeypatch.setenv("DEVELOPMENT", "false")
|
||||||
assert should_rebuild(db, parquet) is False
|
assert should_rebuild(db, parquet) is False
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_rebuild_dev_even_when_parquet_newer(parquet_and_db, monkeypatch):
|
def test_should_not_rebuild_dev_even_when_parquet_newer(parquet_and_db, monkeypatch):
|
||||||
from src.db import should_rebuild
|
|
||||||
|
|
||||||
parquet, db = parquet_and_db
|
parquet, db = parquet_and_db
|
||||||
db.write_bytes(b"x")
|
db.write_bytes(b"x")
|
||||||
time.sleep(0.01)
|
|
||||||
parquet.touch()
|
parquet.touch()
|
||||||
|
now = time.time()
|
||||||
|
os.utime(db, (now, now))
|
||||||
|
os.utime(parquet, (now + 10, now + 10))
|
||||||
monkeypatch.setenv("DEVELOPMENT", "true")
|
monkeypatch.setenv("DEVELOPMENT", "true")
|
||||||
monkeypatch.delenv("REBUILD_DUCKDB", raising=False)
|
monkeypatch.delenv("REBUILD_DUCKDB", raising=False)
|
||||||
assert should_rebuild(db, parquet) is False
|
assert should_rebuild(db, parquet) is False
|
||||||
|
|
||||||
|
|
||||||
def test_should_rebuild_dev_when_rebuild_forced(parquet_and_db, monkeypatch):
|
def test_should_rebuild_dev_when_rebuild_forced(parquet_and_db, monkeypatch):
|
||||||
from src.db import should_rebuild
|
|
||||||
|
|
||||||
parquet, db = parquet_and_db
|
parquet, db = parquet_and_db
|
||||||
db.write_bytes(b"x")
|
db.write_bytes(b"x")
|
||||||
time.sleep(0.01)
|
|
||||||
parquet.touch()
|
parquet.touch()
|
||||||
|
now = time.time()
|
||||||
|
os.utime(db, (now, now))
|
||||||
|
os.utime(parquet, (now + 10, now + 10))
|
||||||
monkeypatch.setenv("DEVELOPMENT", "true")
|
monkeypatch.setenv("DEVELOPMENT", "true")
|
||||||
monkeypatch.setenv("REBUILD_DUCKDB", "true")
|
monkeypatch.setenv("REBUILD_DUCKDB", "true")
|
||||||
assert should_rebuild(db, parquet) is True
|
assert should_rebuild(db, parquet) is True
|
||||||
|
|||||||
Reference in New Issue
Block a user