From 92b1584aaa0fd2a8df045f9b95b48b5325c4534f Mon Sep 17 00:00:00 2001 From: woni <320753691@qq.com> Date: Thu, 10 Apr 2025 11:24:02 +0800 Subject: [PATCH] first commit --- .vscode/settings.json | 7 ++ .../conftest.cpython-313-pytest-8.3.5.pyc | Bin 0 -> 832 bytes conftest.py | 14 ++++ examples/ziniao-login.py | 13 ++++ pytest.ini | 11 +++ src/__pycache__/ziniao.cpython-313.pyc | Bin 0 -> 4216 bytes src/ziniao.py | 72 +++++++++++++++--- .../test_ziniao.cpython-313-pytest-8.3.5.pyc | Bin 0 -> 4643 bytes tests/test-ziniao.py | 37 +++++++++ tests/test_ziniao.py | 1 - 10 files changed, 142 insertions(+), 13 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 __pycache__/conftest.cpython-313-pytest-8.3.5.pyc create mode 100644 conftest.py create mode 100644 examples/ziniao-login.py create mode 100644 pytest.ini create mode 100644 src/__pycache__/ziniao.cpython-313.pyc create mode 100644 tests/__pycache__/test_ziniao.cpython-313-pytest-8.3.5.pyc create mode 100644 tests/test-ziniao.py delete mode 100644 tests/test_ziniao.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a3a1838 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} diff --git a/__pycache__/conftest.cpython-313-pytest-8.3.5.pyc b/__pycache__/conftest.cpython-313-pytest-8.3.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a3c19218dfbc23ab0c70eb00653fc0fce36ea83c GIT binary patch literal 832 zcmZ8f&1(}u6rcUbZa!;cm7>HLq6^tWqbNliM64CDRnwBygLEZqHfQ2ZEOA-+aU`fWY!hlh*5-}=PO|>>T95RkYV2Flf$aA6*I|*hF z2%K;PUHKWJ>OH0sNC*o2p2$?IO@lUpEJp001^-c|@NS8JeahV?Sml0THF21YWAQLA zkL$zC5JFvZQsHo4xZyu5jx?VIx?JsE*Gd+#De|CB3aeVlh3nAuEeD#w)lG)PZvr*d1V+~-vOqnyV_`4K(I z;%jZ>QsfhszSip0N9aVo)rmG+gv+MmMgb{@-F)A^2SWEK5VSC-eIKwA1Wq_I5 zM2{)g9BIW_PDPvXRM-^1;suSi3$Nl+9P(#BxXGR*2*Ni2UV!HlUqEIr4#fCI{#pKw W{BH4+Q2r&V!s)&Q#B)&=&HD@K)Xw|> literal 0 HcmV?d00001 diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..0892767 --- /dev/null +++ b/conftest.py @@ -0,0 +1,14 @@ +import logging +import pytest + + +# 在测试开始前配置日志 +@pytest.fixture(autouse=True, scope="session") +def configure_logging(): + logging.basicConfig( + level=logging.INFO, + format="%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)", + datefmt="%Y-%m-%d %H:%M:%S", + ) + # 返回一个日志对象供测试函数使用 + return logging.getLogger() diff --git a/examples/ziniao-login.py b/examples/ziniao-login.py new file mode 100644 index 0000000..880cf3b --- /dev/null +++ b/examples/ziniao-login.py @@ -0,0 +1,13 @@ +import sys +import os + +sys.path.append( + os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src") +) + + +from ziniao import Ziniao + +if __name__ == "__main__": + ziniao = Ziniao() + ziniao.launch_ziniao() diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..44e1c32 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,11 @@ +[pytest] +# 显示日志输出 +log_cli = True +# 设置日志级别 +log_cli_level = INFO +# 日志格式 +log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s) +# 时间戳格式 +log_cli_date_format = %Y-%m-%d %H:%M:%S +# 捕获stdout/stderr输出 +addopts = -v --capture=tee-sys diff --git a/src/__pycache__/ziniao.cpython-313.pyc b/src/__pycache__/ziniao.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dee814423ff5c4192ed90b6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时间内出现") + + except ImportError: + print("警告: 未安装win32gui模块,无法检测紫鸟窗口出现") + except Exception as e: + print(f"检测窗口出错: {e}") + def get_ziniao_exe_path(self): - """ - Returns: - str: The DisplayIcon value if found, None otherwise - """ + """返回紫鸟的安装路径""" try: # Open the registry key reg_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\8c327052-d9e8-5248-931f-e5b8c47f82b5" key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg_path) - # Query the DisplayIcon value - display_icon, _ = winreg.QueryValueEx(key, "DisplayIcon") + # Query the UninstallString value + uninstall_string, _ = winreg.QueryValueEx(key, "UninstallString") winreg.CloseKey(key) - return display_icon - except FileNotFoundError: - return "Registry key not found" - except WindowsError as e: - return f"Error accessing registry: {e}" + uninstall_exe_path = uninstall_string.rsplit(" ", 1)[0].strip('"') + os.path.split(uninstall_exe_path)[0] # 获取路径部分 + exe_path = os.path.join(os.path.split(uninstall_exe_path)[0], "ziniao.exe") + + return exe_path + except Exception as e: + raise RuntimeError(f"获取紫鸟EXE路径失败: {e}") from e diff --git a/tests/__pycache__/test_ziniao.cpython-313-pytest-8.3.5.pyc b/tests/__pycache__/test_ziniao.cpython-313-pytest-8.3.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0e6b4f4a222e21030e9ffa521694ba2c800a6dae GIT binary patch literal 4643 zcmd5AYfl{4_0G=h?(Bo*VVl}6#v52StlQ${vBseV6(uAoj_hiuNLF{H(HMqhrDbMy zXSW3^OEj?rwuwMZh-f0^Nm`RgrOm5OT_>&j2Nq#WJ3&gTuxtFOG^A?Pe(AY0dv|9I z5=P30jFx-PJ&$`H_sp4d*{-N?BY1M5f5-pKA@mtp(8pc?w*Lsg91@VgoJE*1W?LVt z+5D)F!*;((abSl*abl-2^O%R(cGlJB#%@1~IU}`n7YBaNkfC`9-2p*CBXF|mFWXW~qdzekqm78%{~qlA)> z)G}XfKx5%=n;1EVq6Jx0)EhuSCUX{uxv7_OH-De|@Po~dpU=JY^2UvcjT>*7JLZ1< z^2SHk{_%(D+|1I(%{Mn+e>=DEB2e@1U)x-o%T3YjXE$zreE0e5m}p!? z+c2Up`d}F7jP+|W)?#g~p^k9uydpn_6F-(?`4=Yhue}j_R2`IKkstJk!T?UB(y?*F zk62pP(wZ@fCZ;(xrdOJvm{7E|qzuTIoHGx9ng@mn^o0X?Yp$J{IFAYPv!cHRE+ZB{ zcam82qllFX4CJAaR+uP>o$*8!i9a*hNc4M31;w{ z2y#eZqehkzbi`XATBcHVdC&dL-b56(!11{2Gq~eIMP{W1gBz)9-%vwVy18cul}&#-gy}zb%=TfnOIR4 zdB~FcAINl9zoVTI+!uP=ZQ;VZAb7s?_#dX4sW;Th2g=YMp{mu|$WD~!SY~tx&bSBx<#VA}Claix#^mHQi6e`W?FCzZZib84w zXQD(}j<|D38iwN=gssU-&Tp?p%I; zDL4B|vq#CzP66ibi?ME&~+`YE1;w64btBAXCU7Yk0+G4&Lxx~6_W-AldeGbelIm9Ud$wt zX$Y+DNU8%;Qq$dlC5@jbVg0bE4Xc^tporxZ7UN0vqLdUBX++jtq9zT=1g-mejPp#W zN-xGL)(?oFWkgCt-lUR}BBgAiJB!b&qdq^jcSztDA2z zhGkFP8dvzOaCK8%#gz%Ha&^;fMci`P%0%A*sZlEjU4baw4tAbzDe@EnKyP>|W;(8P zWVyzf?kn9eO?A&Vt#}#%y5nhF!c}(Co*Eru)#DN@L zfn0Wn7C`R2;gFlHal?5BfH_pZ#~sIy_P*oLS`D{N_94st!il6t=vFQFoJjF51Ih~z z^p3XsZ%N0Iz$#1+6KBnNh#5j%>~S>21i4H*2%2Ajq?Azxh6^8ovfBU5t^Cw%?&>SK z*`?go>t=<|kVpSaCG zyv|q7c&~c1hk~p8$^Wc-4sIjH9$M#pGoGuSZ0*VGE!P{f2bvGp_7}jk*{XR`0tLWgPEk 0 + # 验证路径是否存在(如果此测试在未安装紫鸟的环境中可能会失败) + assert os.path.exists(exe_path) + + +def test_launch_ziniao(ziniao_instance): + """测试launch_ziniao方法是否能成功启动紫鸟""" + try: + ziniao_instance.launch_ziniao() + logging.info("紫鸟启动成功") + except Exception as e: + pytest.fail(f"启动紫鸟失败: {e}") + + +if __name__ == "__main__": + # 保留原来的手动测试代码,但仅在直接运行此文件时执行 + ziniao_instance = Ziniao() + print(f"紫鸟EXE路径: {ziniao_instance.get_ziniao_exe_path()}") diff --git a/tests/test_ziniao.py b/tests/test_ziniao.py deleted file mode 100644 index 8b13789..0000000 --- a/tests/test_ziniao.py +++ /dev/null @@ -1 +0,0 @@ -