import sys, ast, os sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) with open("main.py", encoding="utf-8") as f: src = f.read() # isolate parse_account_line (no external deps) tree = ast.parse(src) func_def = None for node in ast.walk(tree): if isinstance(node, ast.FunctionDef) and node.name == "parse_account_line": func_def = node break # exec only the function (with from __future__ import annotations for <3.10 compat) func_src = "from __future__ import annotations\n" + ast.unparse(func_def) exec(compile(func_src, "", "exec")) def test_login_pass(): r = parse_account_line("user:pass") assert r["login"] == "user" assert r["password"] == "pass" assert r["cookie"] == "" def test_login_pass_cookie(): raw = "user:pass:_|WARNING:some-cookie:with:colons" r = parse_account_line(raw) assert r["login"] == "user" assert r["password"] == "pass" assert r["cookie"] == "_|WARNING:some-cookie:with:colons" def test_login_cookie(): raw = "user:_|WARNING:some-cookie:with:colons" r = parse_account_line(raw) assert r["login"] == "user" assert r["password"] == "" assert r["cookie"] == "_|WARNING:some-cookie:with:colons" def test_cookie_only(): raw = "_|WARNING:" + "x" * 100 r = parse_account_line(raw) assert r["login"] == "" assert r["password"] == "" assert r["cookie"] == raw def test_short_line_no_colon(): assert parse_account_line("short") is None def test_raw_preserved(): raw = "user:pass:cookie" r = parse_account_line(raw) assert r["_raw"] == raw if __name__ == "__main__": test_login_pass() test_login_pass_cookie() test_login_cookie() test_cookie_only() test_short_line_no_colon() test_raw_preserved() print("All tests passed")