This commit is contained in:
@@ -21,6 +21,16 @@ class FakeDatetime:
|
||||
return getattr(datetime, attr)
|
||||
|
||||
|
||||
# Wrapper to monkeypatch the whole datetime module with a fake .now()
|
||||
class FakeDateTimeModule:
|
||||
def __init__(self, fake_dt):
|
||||
self.fake_dt = fake_dt
|
||||
def now(self):
|
||||
return self.fake_dt.now()
|
||||
def __getattr__(self, attr):
|
||||
return getattr(datetime, attr)
|
||||
|
||||
|
||||
def test_run_at(monkeypatch):
|
||||
triggered = []
|
||||
|
||||
@@ -30,9 +40,7 @@ def test_run_at(monkeypatch):
|
||||
base = datetime(2025, 1, 1, 12, 0, 0)
|
||||
fake_dt = FakeDatetime(base)
|
||||
|
||||
# Patch dependencies in slic.utils.run_later
|
||||
monkeypatch.setattr("slic.utils.run_later.datetime", datetime)
|
||||
monkeypatch.setattr("slic.utils.run_later.datetime.now", fake_dt.now)
|
||||
monkeypatch.setattr("slic.utils.run_later.datetime", FakeDateTimeModule(fake_dt))
|
||||
monkeypatch.setattr("slic.utils.run_later.sleep", lambda x: None)
|
||||
monkeypatch.setattr("slic.utils.run_later.tqdm_mod", lambda *a, **k: DummyBar())
|
||||
|
||||
@@ -56,8 +64,7 @@ def test_run_in(monkeypatch):
|
||||
base = datetime(2025, 1, 1, 13, 0, 0)
|
||||
fake_dt = FakeDatetime(base)
|
||||
|
||||
monkeypatch.setattr("slic.utils.run_later.datetime", datetime)
|
||||
monkeypatch.setattr("slic.utils.run_later.datetime.now", fake_dt.now)
|
||||
monkeypatch.setattr("slic.utils.run_later.datetime", FakeDateTimeModule(fake_dt))
|
||||
monkeypatch.setattr("slic.utils.run_later.sleep", lambda x: None)
|
||||
monkeypatch.setattr("slic.utils.run_later.tqdm_mod", lambda *a, **k: DummyBar())
|
||||
|
||||
@@ -82,8 +89,7 @@ def test_run_later(monkeypatch):
|
||||
base = datetime(2025, 1, 1, 14, 0, 0)
|
||||
fake_dt = FakeDatetime(base)
|
||||
|
||||
monkeypatch.setattr("slic.utils.run_later.datetime", datetime)
|
||||
monkeypatch.setattr("slic.utils.run_later.datetime.now", fake_dt.now)
|
||||
monkeypatch.setattr("slic.utils.run_later.datetime", FakeDateTimeModule(fake_dt))
|
||||
monkeypatch.setattr("slic.utils.run_later.sleep", lambda x: None)
|
||||
monkeypatch.setattr("slic.utils.run_later.tqdm_mod", lambda *a, **k: DummyBar())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user