Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: 增加单元、整合测试 #181

Open
4 of 8 tasks
Billyzou0741326 opened this issue Oct 14, 2022 · 2 comments
Open
4 of 8 tasks

[Feat]: 增加单元、整合测试 #181

Billyzou0741326 opened this issue Oct 14, 2022 · 2 comments
Labels
enhancement ✨ New feature or request tests🧾 python tests

Comments

@Billyzou0741326
Copy link
Contributor

请确保您已阅读以上注意事项,并勾选下方的确认框。

  • 我确定这是一个从未被提出和实现过的功能。
  • 我已经在 Issue Tracker 以及 Pull Request 中找过我要提出的功能,没有找到相同功能的ISSUE和PR。
  • 我已知晓并同意,此处仅用于建议新功能。若这个 Issue 是关于其他非主题的问题,则我的 Issue 可能会被无条件自动关闭或/并锁定。
  • 我已知晓并同意,如果我不按照模板提供的指示进行填写,则我的 Issue 可能会被无条件删除。

需要添加的功能内容

对已有的service层添加单元/整合测试,以避免后续修改/重构破坏现有功能。

  • Docker mysql (CI/CD)
  • Docker redis (CI/CD)
  • Mock genshin.py - genshin API
  • Mock webserver - other API's

最终目的是在不发送http/db/cache请求的情况下对service进行测试,且确保tests不会因为网络/上游问题导致失败。

@Billyzou0741326 Billyzou0741326 added enhancement ✨ New feature or request tests🧾 python tests labels Oct 14, 2022
@luoshuijs
Copy link
Contributor

@Billyzou0741326 估计不用写了,解耦困难,我一导入 bot 就是瞬间爆炸,加上你也没空,可以关闭这个issue了

#346 已经关闭

@luoshuijs
Copy link
Contributor

如果要单元测试,不能存在 bot = Bot() 这样奇怪的操作,更不能把实例化后的东西相互导入,这种耦合无异于内容耦合.
毕竟我刚刚试试了,如果我要测试 参数分发器 是否正常工作,但是我单元测试时因为下面代码必然导致报错。
https://github.com/luoshuijs/TGPaimonBot/blob/2c068a4ed32282c6ad2c39df9739cfcff3366054/core/builtins/dispatcher.py#L61-L68
所以,为了解决内容耦合,我就尝试不把实例化 bot 暴露在公共中,如果要传递给 plugin , 我们只需在安装插件时传递本身,
https://github.com/luoshuijs/TGPaimonBot/blob/421a20d3c660929f1f3b8bad6aaaaafb16897ba9/core/application.py#L112
需要声明 _Plugin 都需要这个玩意
https://github.com/luoshuijs/TGPaimonBot/blob/421a20d3c660929f1f3b8bad6aaaaafb16897ba9/core/plugin/_plugin.py#L71
而且在 init 后尝试注入
https://github.com/luoshuijs/TGPaimonBot/blob/421a20d3c660929f1f3b8bad6aaaaafb16897ba9/core/manager.py#L205
这样,还能解决不使用 context 或导入 bot 就能获取 job_queue 的问题
https://github.com/luoshuijs/TGPaimonBot/blob/421a20d3c660929f1f3b8bad6aaaaafb16897ba9/core/baseplugin.py#L48-L60

@luoshuijs luoshuijs moved this to 🆕 New in PaiGram V4 Feb 15, 2023
@luoshuijs luoshuijs moved this from 🆕 New to issues in PaiGram V4 Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request tests🧾 python tests
Projects
No open projects
Status: issues
Development

No branches or pull requests

2 participants