69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Die Zugzeile darf beim Preis nicht luegen (lesen/spot_from_log.py).
|
|
|
|
Der Antrag an den Kern weicht im All-in auf `userTurnOptions["4"]` aus - `callAmount` ist dort 0.0
|
|
(dokumentierter Fall: Hand 166448800045 in archiv/mitschrieb/main.6.log.gz). Die kurze Zeile fuer Log und
|
|
Ausgabe nahm aber weiter `callAmount` und schrieb "toCall 0.0" zu einem Zug, der 7.6 kostete.
|
|
31.10. sah damit ein **richtiger** Fold wie ein Gratis-Fold aus.
|
|
|
|
Invariante: was in der Zeile steht, ist genau das, was der Kern bekommt.
|
|
|
|
python3 tests/zugpreis_zeile_spec.py -v
|
|
"""
|
|
import gzip
|
|
import json
|
|
import os
|
|
import re
|
|
import sys
|
|
import unittest
|
|
|
|
HIER = os.path.dirname(os.path.abspath(__file__))
|
|
WURZEL = os.path.dirname(HIER)
|
|
for p in (WURZEL, os.path.join(WURZEL, "lesen")):
|
|
if p not in sys.path:
|
|
sys.path.insert(0, p)
|
|
|
|
import spot_from_log
|
|
|
|
QUELLE = os.path.join(WURZEL, "archiv", "mitschrieb", "main.6.log.gz")
|
|
FALL = "166448800045"
|
|
|
|
|
|
def text():
|
|
with gzip.open(QUELLE, "rt", encoding="utf-8", errors="replace") as h:
|
|
return h.read()
|
|
|
|
|
|
class ZeileLuegtNicht(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.t = text()
|
|
if FALL not in cls.t:
|
|
raise AssertionError(f"Bestandsfall {FALL} fehlt - Archiv geaendert?")
|
|
cls.zeilen = spot_from_log.spots(cls.t)
|
|
|
|
def test_der_bestandsfall_ist_da(self):
|
|
self.assertTrue(any(FALL in z for z, _, _, h, _ in self.zeilen for z in (z,)) or
|
|
any(h == FALL for _, _, _, h, _ in self.zeilen))
|
|
|
|
def test_die_zeile_nennt_denselben_preis_wie_der_antrag(self):
|
|
geprueft = 0
|
|
for zeile, kurz, _, _, _ in self.zeilen:
|
|
m = re.search(r"toCall ([\d.]+) Pot", kurz)
|
|
self.assertIsNotNone(m, kurz)
|
|
self.assertAlmostEqual(float(m.group(1)), float(json.loads(zeile)["toCall"]), places=9,
|
|
msg=kurz)
|
|
geprueft += 1
|
|
self.assertGreaterEqual(geprueft, 3)
|
|
|
|
def test_der_allingriff_des_bestandsfalls_ist_nicht_gratis(self):
|
|
"""Genau der Fall, der falsch aussah: callAmount 0.0, Preis trotzdem gross."""
|
|
treffer = [k for _, k, _, h, _ in self.zeilen if h == FALL]
|
|
self.assertTrue(treffer, "kein Zug des Bestandsfalls gefunden")
|
|
self.assertTrue(any(float(re.search(r"toCall ([\d.]+)", k).group(1)) > 0 for k in treffer),
|
|
treffer[:3])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|