"""
Testovací skript - zjistí proč nejde 003.
Zapíše výsledek do test_spusteni.log
"""
import sys
import os
import traceback

LOG = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_spusteni.log")

lines = []
lines.append(f"Python: {sys.executable}")
lines.append(f"Verze: {sys.version}")
lines.append(f"Cwd: {os.getcwd()}")
lines.append(f"__file__: {os.path.abspath(__file__)}")
lines.append("")

try:
    import fdb
    lines.append("fdb: OK")
except Exception as e:
    lines.append(f"fdb CHYBA: {e}")
    lines.append(traceback.format_exc())

try:
    import tkinter as tk
    lines.append("tkinter: OK")
except Exception as e:
    lines.append(f"tkinter CHYBA: {e}")

try:
    conn = __import__("fdb").connect(
        dsn=r"localhost:c:\medicus 3\data\medicus.fdb",
        user="SYSDBA", password="masterkey", charset="win1250"
    )
    conn.close()
    lines.append("DB spojeni: OK")
except Exception as e:
    lines.append(f"DB CHYBA: {e}")

with open(LOG, "w", encoding="utf-8") as f:
    f.write("\n".join(lines))
