"""338-1 우리 로직 지문(`M02_Hopyo_Ours`) — 판 열쇠 · 캐시 쓰기 · 읽기 · 준비 전 None · 합판 품 · 기계경비 로직 · 섞기 전 변형 · 엔진 셈 캐시 · master_data 원본 그대로. 캐시 폴더는 임시.""" import pytest from M02_MasterTemplete import M02_Hopyo_Fit as fit from M02_MasterTemplete import M02_Hopyo_Match as hm from M02_MasterTemplete import M02_Hopyo_Ours as ours from resources.tester.test_m02_hopyo_excel import master_hash approx = pytest.approx @pytest.fixture def cache(tmp_path, monkeypatch): """임시 캐시 폴더 + 로직 셋만 셈(1,438 대신) — 끝나면 메모리 표를 비움.""" monkeypatch.setenv("AISLO_HOPYO_CACHE", str(tmp_path)) few = [x for x in hm.targets()["로직"] if x["로직"] in ("GC000211", "GC000198", "GC000268")] monkeypatch.setattr(hm, "targets", lambda: {**hm._targets(id(ours.whole())), "로직": few}) monkeypatch.setitem(ours._STATE, "표판", None) monkeypatch.setitem(ours._STATE, "표", None) yield tmp_path ours._STATE.update(표판=None, 표=None) def test_판_열쇠_같음(): a, b = ours.version(), ours.version() assert a == b and len(a) == 16 and ours.path_of(a).name == f"우리지문_{a}.json" def test_캐시_쓰기_읽기_준비_전_none(cache): before = master_hash() assert ours.table() is None and not ours.ready() built = ours.build() assert [o["로직"] for o in built] == ["GC000198", "GC000211", "GC000268"] assert ours.path_of().parent == cache and ours.path_of().is_file() assert ours.ready() and ours.table() == built ours._STATE.update(표판=None, 표=None) assert [o["로직"] for o in ours.table()] == ["GC000198", "GC000211", "GC000268"] assert master_hash() == before def test_데움_뒤_스레드(cache): thread = ours.warm(build_missing=True) thread.join(timeout=120) assert ours.ready() and len(ours.table()) == 3 def test_합판_보통_형틀목공(): fp = ours.fingerprint("GC000211", "㎡") plain = next(v for v in fp["변형"] if v["in"].get("유형") == "보통") assert plain["L"]["형틀목공"] == approx(0.112, abs=1e-3) assert plain["L"]["보통인부"] == approx(0.045, abs=1e-3) assert fp["직종"] == ["보통인부", "형틀목공"] and not fp["기계경비"] assert fp["고름조건"]["횟수"] # 고르기 글 「4회사용시」 낱말 def test_기계경비_로직은_고른_기계_1시간(): v = ours.run("GC000268", {}) assert v["L"] == {} and len(v["X"]) == 1 and v["X"][0][2] == 1.0 assert ours.fingerprint("GC000268", "hr")["기계경비"] def test_섞기_전_변형(): table = ours.table() or ours.build() mixed = next( o for o in table if any(0 < ((v.get("mix") or {}).get("인력비율") or 0) < 100 for v in o["변형"]) ) prep = fit._prep(mixed, {}) assert any(v["in"] and v["in"].get("_섞기전") for v in prep["vs"]) def test_엔진_셈_캐시(): a = ours.run("GC000198", {"소량감률": 50}) assert ours.run("GC000198", {"소량감률": 50}) is a # 같은 입력은 다시 안 셈 assert ours.run("없는로직", {}) is None