mirror of
https://github.com/hanzoai/insights.git
synced 2026-11-02 09:24:48 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
157 lines
4.8 KiB
Python
157 lines
4.8 KiB
Python
# Test cases for test-no-datetime-now rule
|
|
# This file is used by `semgrep --test` to verify the rule works correctly.
|
|
#
|
|
# Note: This rule only applies to test files, but semgrep's test framework runs
|
|
# tests against this .py file directly, so we test the patterns here.
|
|
# ruff: noqa: F841 — assignments exist solely to give semgrep something to match
|
|
|
|
import datetime as dt
|
|
from datetime import date, datetime
|
|
|
|
from freezegun import freeze_time
|
|
|
|
from django.utils import (
|
|
timezone,
|
|
timezone as django_timezone,
|
|
)
|
|
|
|
# ============================================================
|
|
# Should flag: time-dependent calls in tests without freeze_time
|
|
# ============================================================
|
|
|
|
|
|
class TestWithoutFreeze:
|
|
def test_bare_datetime_now(self):
|
|
# ruleid: test-datetime-now-without-freeze
|
|
now = datetime.now()
|
|
|
|
def test_bare_datetime_utcnow(self):
|
|
# ruleid: test-datetime-now-without-freeze
|
|
now = datetime.utcnow()
|
|
|
|
def test_bare_datetime_today(self):
|
|
# ruleid: test-datetime-now-without-freeze
|
|
now = datetime.today()
|
|
|
|
def test_bare_timezone_now(self):
|
|
# ruleid: test-datetime-now-without-freeze
|
|
now = timezone.now()
|
|
|
|
def test_bare_django_timezone_now(self):
|
|
# ruleid: test-datetime-now-without-freeze
|
|
now = django_timezone.now()
|
|
|
|
def test_bare_date_today(self):
|
|
# ruleid: test-datetime-now-without-freeze
|
|
today = date.today()
|
|
|
|
def test_bare_dt_datetime_now(self):
|
|
# ruleid: test-datetime-now-without-freeze
|
|
now = dt.datetime.now()
|
|
|
|
def test_bare_dt_datetime_utcnow(self):
|
|
# ruleid: test-datetime-now-without-freeze
|
|
now = dt.datetime.utcnow()
|
|
|
|
def test_bare_dt_datetime_today(self):
|
|
# ruleid: test-datetime-now-without-freeze
|
|
now = dt.datetime.today()
|
|
|
|
def test_bare_dt_date_today(self):
|
|
# ruleid: test-datetime-now-without-freeze
|
|
today = dt.date.today()
|
|
|
|
|
|
# ============================================================
|
|
# Should NOT flag: protected by @freeze_time on method
|
|
# ============================================================
|
|
|
|
|
|
class TestWithFreezeOnMethod:
|
|
@freeze_time("2024-01-01")
|
|
def test_frozen_datetime_now(self):
|
|
# ok: test-datetime-now-without-freeze
|
|
now = datetime.now()
|
|
|
|
@freeze_time("2024-01-01")
|
|
def test_frozen_timezone_now(self):
|
|
# ok: test-datetime-now-without-freeze
|
|
now = timezone.now()
|
|
|
|
@freeze_time("2024-01-01")
|
|
def test_frozen_dt_datetime_now(self):
|
|
# ok: test-datetime-now-without-freeze
|
|
now = dt.datetime.now()
|
|
|
|
|
|
# ============================================================
|
|
# Should NOT flag: protected by @freeze_time on class
|
|
# ============================================================
|
|
|
|
|
|
@freeze_time("2024-01-01")
|
|
class TestWithFreezeOnClass:
|
|
def test_class_frozen_datetime_now(self):
|
|
# ok: test-datetime-now-without-freeze
|
|
now = datetime.now()
|
|
|
|
def test_class_frozen_timezone_now(self):
|
|
# ok: test-datetime-now-without-freeze
|
|
now = timezone.now()
|
|
|
|
|
|
@freeze_time("2024-01-01")
|
|
class TestWithFreezeOnClassWithBases:
|
|
def test_class_frozen_with_bases(self):
|
|
# ok: test-datetime-now-without-freeze
|
|
now = datetime.now()
|
|
|
|
|
|
# ============================================================
|
|
# Should NOT flag: protected by @freeze_time on stacked decorators
|
|
# ============================================================
|
|
|
|
|
|
class TestWithStackedDecorators:
|
|
@freeze_time("2024-01-01")
|
|
def test_stacked_frozen_datetime_now(self):
|
|
# ok: test-datetime-now-without-freeze
|
|
now = datetime.now()
|
|
|
|
|
|
# ============================================================
|
|
# Should NOT flag: protected by with freeze_time() context manager
|
|
# ============================================================
|
|
|
|
|
|
class TestWithFreezeContextManager:
|
|
def test_context_manager_datetime_now(self):
|
|
with freeze_time("2024-01-01"):
|
|
# ok: test-datetime-now-without-freeze
|
|
now = datetime.now()
|
|
|
|
def test_context_manager_timezone_now(self):
|
|
with freeze_time("2024-01-01"):
|
|
# ok: test-datetime-now-without-freeze
|
|
now = timezone.now()
|
|
|
|
def test_context_manager_with_binding(self):
|
|
with freeze_time("2024-01-01") as frozen_time:
|
|
# ok: test-datetime-now-without-freeze
|
|
now = datetime.now()
|
|
|
|
|
|
# ============================================================
|
|
# Should NOT flag: not a test method
|
|
# ============================================================
|
|
|
|
|
|
class TestHelpers:
|
|
def helper_get_time(self):
|
|
# ok: test-datetime-now-without-freeze
|
|
return datetime.now()
|
|
|
|
def setUp(self):
|
|
# ok: test-datetime-now-without-freeze
|
|
self.now = datetime.now()
|