alasio 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (539) hide show
  1. alasio/adb/protocol/cnxn.py +36 -0
  2. alasio/adb/protocol/const.py +120 -0
  3. alasio/adb/protocol/props.py +102 -0
  4. alasio/adb/protocol/tcp.py +56 -0
  5. alasio/adb/protocol/tcp_protocol.py +454 -0
  6. alasio/adb/utils/remove_warning.py +139 -0
  7. alasio/assets/manager.py +49 -0
  8. alasio/assets/model/folder.py +429 -0
  9. alasio/assets/model/generator.py +352 -0
  10. alasio/assets/model/name.py +121 -0
  11. alasio/assets/model/parser.py +360 -0
  12. alasio/assets/model/resource.py +143 -0
  13. alasio/assets/template/__init__.py +4 -0
  14. alasio/assets/template/asset.py +133 -0
  15. alasio/assets/template/template.py +488 -0
  16. alasio/assets_dev/extract.py +334 -0
  17. alasio/assets_dev/extract_alas.py +113 -0
  18. alasio/assets_dev/extract_src.py +58 -0
  19. alasio/assets_dev/parse.py +389 -0
  20. alasio/backend/app/app.py +309 -0
  21. alasio/backend/app/asgi.py +201 -0
  22. alasio/backend/app/frontend.py +711 -0
  23. alasio/backend/app/lifespan.py +255 -0
  24. alasio/backend/app/prefs.py +103 -0
  25. alasio/backend/app/restart/__init__.py +32 -0
  26. alasio/backend/app/restart/daily.py +429 -0
  27. alasio/backend/app/restart/restart_base.py +555 -0
  28. alasio/backend/app/restart/restart_flow.py +357 -0
  29. alasio/backend/app/restart/restart_manager.py +387 -0
  30. alasio/backend/app/restart/restart_step.py +968 -0
  31. alasio/backend/app/restart/resume_file.py +504 -0
  32. alasio/backend/app/restart/update_check.py +988 -0
  33. alasio/backend/auth/auth.py +239 -0
  34. alasio/backend/auth/deps.py +51 -0
  35. alasio/backend/auth/fail2ban.py +263 -0
  36. alasio/backend/auth/password.py +52 -0
  37. alasio/backend/backend.py +49 -0
  38. alasio/backend/dev/assets.py +92 -0
  39. alasio/backend/entry.py +115 -0
  40. alasio/backend/locale/accept_language.py +145 -0
  41. alasio/backend/middleware/gate.py +536 -0
  42. alasio/backend/mpipe/mpipe_backend.py +115 -0
  43. alasio/backend/mpipe/token_backend.py +138 -0
  44. alasio/backend/mpipe/token_supervisor.py +138 -0
  45. alasio/backend/reactive/background.py +137 -0
  46. alasio/backend/reactive/base_rpc.py +142 -0
  47. alasio/backend/reactive/base_topic.py +57 -0
  48. alasio/backend/reactive/event.py +79 -0
  49. alasio/backend/reactive/not_found.py +16 -0
  50. alasio/backend/reactive/rx_sync.py +288 -0
  51. alasio/backend/reactive/rx_trio.py +323 -0
  52. alasio/backend/reactive/safeid.py +50 -0
  53. alasio/backend/reactive/source.py +996 -0
  54. alasio/backend/supervisor.py +857 -0
  55. alasio/backend/topic/_config_event.py +30 -0
  56. alasio/backend/topic/_gui_config.py +178 -0
  57. alasio/backend/topic/_worker.py +112 -0
  58. alasio/backend/topic/config.py +254 -0
  59. alasio/backend/topic/dashboard.py +38 -0
  60. alasio/backend/topic/dev_assets.py +270 -0
  61. alasio/backend/topic/log.py +239 -0
  62. alasio/backend/topic/mod.py +94 -0
  63. alasio/backend/topic/preview.py +297 -0
  64. alasio/backend/topic/que.py +703 -0
  65. alasio/backend/topic/restart.py +86 -0
  66. alasio/backend/topic/scan.py +194 -0
  67. alasio/backend/topic/state.py +172 -0
  68. alasio/backend/topic/update.py +201 -0
  69. alasio/backend/topic/worker.py +115 -0
  70. alasio/backend/worker/bridge.py +507 -0
  71. alasio/backend/worker/event.py +49 -0
  72. alasio/backend/worker/manager.py +1433 -0
  73. alasio/backend/ws/context.py +13 -0
  74. alasio/backend/ws/renew.py +161 -0
  75. alasio/backend/ws/topic.py +113 -0
  76. alasio/backend/ws/ws_server.py +658 -0
  77. alasio/backend/ws/ws_topic.py +457 -0
  78. alasio/backport/__init__.py +139 -0
  79. alasio/backport/batch.py +72 -0
  80. alasio/backport/cjk.py +71 -0
  81. alasio/backport/listify.py +70 -0
  82. alasio/backport/literal.py +195 -0
  83. alasio/backport/once.py +82 -0
  84. alasio/backport/patch.py +272 -0
  85. alasio/backport/rich/__init__.py +115 -0
  86. alasio/backport/rich/rich_14_1.py +207 -0
  87. alasio/backport/rich/rich_14_3.py +210 -0
  88. alasio/backport/strenum.py +61 -0
  89. alasio/backport/suppress.py +85 -0
  90. alasio/backport/threading_ext.py +16 -0
  91. alasio/base/base.py +123 -0
  92. alasio/base/cache.py +227 -0
  93. alasio/base/exception.py +58 -0
  94. alasio/base/filter.py +69 -0
  95. alasio/base/image/color.py +505 -0
  96. alasio/base/image/draw.py +274 -0
  97. alasio/base/image/imfile.py +505 -0
  98. alasio/base/image/imgif.py +91 -0
  99. alasio/base/image/impillow.py +88 -0
  100. alasio/base/image/impreview.py +47 -0
  101. alasio/base/op/__init__.py +9 -0
  102. alasio/base/op/area.py +915 -0
  103. alasio/base/op/color.py +29 -0
  104. alasio/base/op/rng.py +69 -0
  105. alasio/base/op/slist.py +199 -0
  106. alasio/base/pretty.py +76 -0
  107. alasio/base/scheduler/configwatcher.py +78 -0
  108. alasio/base/scheduler/scheduler.py +395 -0
  109. alasio/base/scheduler/scheduler_task.py +71 -0
  110. alasio/base/scheduler/task_entry.py +46 -0
  111. alasio/base/scheduler/task_record.py +127 -0
  112. alasio/base/servertime.py +494 -0
  113. alasio/base/state.py +679 -0
  114. alasio/base/timer.py +221 -0
  115. alasio/codegen/asar/__init__.py +63 -0
  116. alasio/codegen/asar/__main__.py +301 -0
  117. alasio/codegen/asar/archive.py +1055 -0
  118. alasio/codegen/asar/crawl.py +140 -0
  119. alasio/codegen/asar/errors.py +40 -0
  120. alasio/codegen/asar/format.py +139 -0
  121. alasio/codegen/asar/model.py +708 -0
  122. alasio/codegen/asar/pack.py +504 -0
  123. alasio/codegen/asar/source.py +187 -0
  124. alasio/codegen/markdown/table.py +469 -0
  125. alasio/codegen/python/__init__.py +4 -0
  126. alasio/codegen/python/gen.py +448 -0
  127. alasio/codegen/python/gen_base.py +307 -0
  128. alasio/codegen/python/libscan.py +265 -0
  129. alasio/codegen/python/obj_base.py +353 -0
  130. alasio/codegen/python/obj_class.py +197 -0
  131. alasio/codegen/python/obj_closure.py +391 -0
  132. alasio/codegen/python/obj_if.py +79 -0
  133. alasio/codegen/python/obj_import.py +178 -0
  134. alasio/codegen/python/obj_simple.py +159 -0
  135. alasio/codegen/ruff/__main__.py +75 -0
  136. alasio/codegen/ruff/ruff_format.py +239 -0
  137. alasio/config/_index/config_generated.py +42 -0
  138. alasio/config/_index/nav.order.yaml +1 -0
  139. alasio/config/_index/queue.index.json +16 -0
  140. alasio/config/_index/task.index.json +32 -0
  141. alasio/config/_index/task_entry.py +11 -0
  142. alasio/config/alasio/alasio.args.yaml +70 -0
  143. alasio/config/alasio/alasio_i18n.json +212 -0
  144. alasio/config/alasio/alasio_model.py +75 -0
  145. alasio/config/alasio/device.args.yaml +79 -0
  146. alasio/config/alasio/device.tasks.yaml +27 -0
  147. alasio/config/alasio/device_i18n.json +630 -0
  148. alasio/config/alasio/device_model.py +52 -0
  149. alasio/config/alasio/group_base.py +115 -0
  150. alasio/config/alasio/group_export.py +37 -0
  151. alasio/config/alasio/group_proxy.py +135 -0
  152. alasio/config/alasio/mixin.args.yaml +7 -0
  153. alasio/config/alasio/mixin_model.py +37 -0
  154. alasio/config/alasio/store.args.yaml +23 -0
  155. alasio/config/alasio/store_i18n.json +68 -0
  156. alasio/config/alasio/store_model.py +385 -0
  157. alasio/config/base/__init__.py +6 -0
  158. alasio/config/base/config_access.py +751 -0
  159. alasio/config/base/config_task.py +238 -0
  160. alasio/config/const.py +40 -0
  161. alasio/config/entry/const.py +171 -0
  162. alasio/config/entry/loader.py +369 -0
  163. alasio/config/entry/mod.py +6 -0
  164. alasio/config/entry/mod_base.py +140 -0
  165. alasio/config/entry/mod_config.py +788 -0
  166. alasio/config/entry/mod_scheduler.py +182 -0
  167. alasio/config/entry/model.py +131 -0
  168. alasio/config/entry/utils.py +17 -0
  169. alasio/config/table/base.py +21 -0
  170. alasio/config/table/config.py +96 -0
  171. alasio/config/table/key.py +164 -0
  172. alasio/config/table/scan.py +518 -0
  173. alasio/config_dev/format/__init__.py +0 -0
  174. alasio/config_dev/format/extract_method.py +87 -0
  175. alasio/config_dev/format/format_i18n.py +84 -0
  176. alasio/config_dev/format/format_yaml.py +128 -0
  177. alasio/config_dev/format/validate_color.py +31 -0
  178. alasio/config_dev/gen/gen_config.py +438 -0
  179. alasio/config_dev/gen/gen_config_generated.py +188 -0
  180. alasio/config_dev/gen/gen_config_index.py +243 -0
  181. alasio/config_dev/gen/gen_cross.py +562 -0
  182. alasio/config_dev/gen/gen_nav_index.py +179 -0
  183. alasio/config_dev/gen/gen_queue_index.py +41 -0
  184. alasio/config_dev/gen/gen_task_entry.py +157 -0
  185. alasio/config_dev/gen_alasio.py +50 -0
  186. alasio/config_dev/gen_index.py +131 -0
  187. alasio/config_dev/parse/base.py +261 -0
  188. alasio/config_dev/parse/build_mro.py +112 -0
  189. alasio/config_dev/parse/cache_alasio.py +16 -0
  190. alasio/config_dev/parse/load_alas_i18n.py +149 -0
  191. alasio/config_dev/parse/parse_arg_utils.py +106 -0
  192. alasio/config_dev/parse/parse_args.py +543 -0
  193. alasio/config_dev/parse/parse_groups.py +306 -0
  194. alasio/config_dev/parse/parse_range.py +205 -0
  195. alasio/config_dev/parse/parse_store.py +38 -0
  196. alasio/config_dev/parse/parse_task_entry.py +216 -0
  197. alasio/config_dev/parse/parse_tasks.py +276 -0
  198. alasio/db/conn.py +569 -0
  199. alasio/db/table.py +726 -0
  200. alasio/db/validate.py +171 -0
  201. alasio/deploy/config/model.py +287 -0
  202. alasio/deploy/history/decode_history.py +45 -0
  203. alasio/deploy/httpclient/client_async.py +312 -0
  204. alasio/deploy/httpclient/client_base.py +227 -0
  205. alasio/deploy/httpclient/client_sync.py +315 -0
  206. alasio/deploy/httpclient/probe_async.py +583 -0
  207. alasio/deploy/httpclient/probe_base.py +233 -0
  208. alasio/deploy/httpclient/probe_db.py +248 -0
  209. alasio/deploy/httpclient/probe_mirrors.py +274 -0
  210. alasio/deploy/httpclient/probe_sync.py +491 -0
  211. alasio/deploy/pack/decode_base.py +746 -0
  212. alasio/deploy/pack/decode_manifest.py +170 -0
  213. alasio/deploy/pack/job.py +611 -0
  214. alasio/deploy/pack/job_base.py +790 -0
  215. alasio/deploy/pack/job_rebuild.py +301 -0
  216. alasio/deploy/pack/job_reset.py +612 -0
  217. alasio/deploy/pack/job_unpack.py +241 -0
  218. alasio/deploy/pack/job_update.py +920 -0
  219. alasio/deploy/pack/local_probe.py +407 -0
  220. alasio/deploy/pack/pack_model.py +101 -0
  221. alasio/deploy/pack/packdep.py +201 -0
  222. alasio/deploy/pack/server_file.py +532 -0
  223. alasio/deploy/pack/tmp_manager.py +278 -0
  224. alasio/deploy/simple_pip/cleanup_folder.py +196 -0
  225. alasio/deploy/simple_pip/cleanup_pyc.py +251 -0
  226. alasio/deploy/simple_pip/install_base.py +318 -0
  227. alasio/deploy/simple_pip/parse_req.py +201 -0
  228. alasio/deploy/simple_pip/pip_install.py +747 -0
  229. alasio/deploy/simple_pip/pip_list.py +489 -0
  230. alasio/deploy/simple_pip/pip_pack.py +245 -0
  231. alasio/deploy/simple_pip/pyc.py +65 -0
  232. alasio/deploy/simple_pip/python_probe.py +330 -0
  233. alasio/deploy/simple_pip/whl_record.py +181 -0
  234. alasio/deploy/unpack.py +44 -0
  235. alasio/deploy_data/frontend/_app/immutable/assets/0.CxE3J1xw.css +1 -0
  236. alasio/deploy_data/frontend/_app/immutable/assets/1.B2QB1I1Z.css +1 -0
  237. alasio/deploy_data/frontend/_app/immutable/assets/15.PAcXLLKe.css +1 -0
  238. alasio/deploy_data/frontend/_app/immutable/assets/2.C8uW_YaM.css +1 -0
  239. alasio/deploy_data/frontend/_app/immutable/assets/LayoutHorizontalLike.0S0RqpCp.css +1 -0
  240. alasio/deploy_data/frontend/_app/immutable/assets/dnd.B-s_2auo.css +1 -0
  241. alasio/deploy_data/frontend/_app/immutable/assets/scroll-area.QE5ZuEV4.css +1 -0
  242. alasio/deploy_data/frontend/_app/immutable/assets/select.CV-KWLNP.css +1 -0
  243. alasio/deploy_data/frontend/_app/immutable/chunks/1WzRS_JT.js +5 -0
  244. alasio/deploy_data/frontend/_app/immutable/chunks/9cv0DBTP.js +1 -0
  245. alasio/deploy_data/frontend/_app/immutable/chunks/AlKcTD4b.js +1 -0
  246. alasio/deploy_data/frontend/_app/immutable/chunks/B05dMUVp.js +5 -0
  247. alasio/deploy_data/frontend/_app/immutable/chunks/B68qRUFY.js +1 -0
  248. alasio/deploy_data/frontend/_app/immutable/chunks/B6i8GFbo.js +1 -0
  249. alasio/deploy_data/frontend/_app/immutable/chunks/B7WtWDRR.js +1 -0
  250. alasio/deploy_data/frontend/_app/immutable/chunks/B8emgpOo.js +1 -0
  251. alasio/deploy_data/frontend/_app/immutable/chunks/BNkdd6XE.js +1 -0
  252. alasio/deploy_data/frontend/_app/immutable/chunks/BRtJfLrw.js +7 -0
  253. alasio/deploy_data/frontend/_app/immutable/chunks/BU9J6Vit.js +1 -0
  254. alasio/deploy_data/frontend/_app/immutable/chunks/BUKh3UmD.js +1 -0
  255. alasio/deploy_data/frontend/_app/immutable/chunks/BVd9JioC.js +1 -0
  256. alasio/deploy_data/frontend/_app/immutable/chunks/B_9CNbzS.js +3 -0
  257. alasio/deploy_data/frontend/_app/immutable/chunks/BjWTJ24g.js +3 -0
  258. alasio/deploy_data/frontend/_app/immutable/chunks/Bjy-W4x2.js +81 -0
  259. alasio/deploy_data/frontend/_app/immutable/chunks/BkH--E8c.js +1 -0
  260. alasio/deploy_data/frontend/_app/immutable/chunks/BmP5RnH1.js +1 -0
  261. alasio/deploy_data/frontend/_app/immutable/chunks/BnDc-5Su.js +1 -0
  262. alasio/deploy_data/frontend/_app/immutable/chunks/BrEYuMQs.js +1 -0
  263. alasio/deploy_data/frontend/_app/immutable/chunks/BrL8oXzA.js +1 -0
  264. alasio/deploy_data/frontend/_app/immutable/chunks/BxEtcARg.js +1 -0
  265. alasio/deploy_data/frontend/_app/immutable/chunks/C2WCLEZs.js +1 -0
  266. alasio/deploy_data/frontend/_app/immutable/chunks/C2dATR1Z.js +1 -0
  267. alasio/deploy_data/frontend/_app/immutable/chunks/C34YkqUj.js +1 -0
  268. alasio/deploy_data/frontend/_app/immutable/chunks/C4S8KBiV.js +1 -0
  269. alasio/deploy_data/frontend/_app/immutable/chunks/C6FvdxJI.js +1 -0
  270. alasio/deploy_data/frontend/_app/immutable/chunks/CC-kxPAl.js +1 -0
  271. alasio/deploy_data/frontend/_app/immutable/chunks/CSZi_BGQ.js +1 -0
  272. alasio/deploy_data/frontend/_app/immutable/chunks/CWLmEEVg.js +1 -0
  273. alasio/deploy_data/frontend/_app/immutable/chunks/CjBzUcoA.js +1 -0
  274. alasio/deploy_data/frontend/_app/immutable/chunks/CnMhvucq.js +1 -0
  275. alasio/deploy_data/frontend/_app/immutable/chunks/CnPBA-RE.js +1 -0
  276. alasio/deploy_data/frontend/_app/immutable/chunks/ComNeZZR.js +1 -0
  277. alasio/deploy_data/frontend/_app/immutable/chunks/CqNXHTMx.js +1 -0
  278. alasio/deploy_data/frontend/_app/immutable/chunks/Cta5dmDD.js +1 -0
  279. alasio/deploy_data/frontend/_app/immutable/chunks/Ctm798eZ.js +1 -0
  280. alasio/deploy_data/frontend/_app/immutable/chunks/CxfvbDWC.js +1 -0
  281. alasio/deploy_data/frontend/_app/immutable/chunks/D-SH_VhL.js +1 -0
  282. alasio/deploy_data/frontend/_app/immutable/chunks/DBTS_VrB.js +1 -0
  283. alasio/deploy_data/frontend/_app/immutable/chunks/DFHGvHlK.js +1 -0
  284. alasio/deploy_data/frontend/_app/immutable/chunks/DHZVHX0j.js +1 -0
  285. alasio/deploy_data/frontend/_app/immutable/chunks/DJ_BSubc.js +1 -0
  286. alasio/deploy_data/frontend/_app/immutable/chunks/DK3Fl9T5.js +1 -0
  287. alasio/deploy_data/frontend/_app/immutable/chunks/DRPcN1BG.js +1 -0
  288. alasio/deploy_data/frontend/_app/immutable/chunks/DSUGl7i8.js +1 -0
  289. alasio/deploy_data/frontend/_app/immutable/chunks/DWPcTWKb.js +1 -0
  290. alasio/deploy_data/frontend/_app/immutable/chunks/DZGy2QkI.js +1 -0
  291. alasio/deploy_data/frontend/_app/immutable/chunks/DaM3J7v-.js +1 -0
  292. alasio/deploy_data/frontend/_app/immutable/chunks/DbLSk6sY.js +1 -0
  293. alasio/deploy_data/frontend/_app/immutable/chunks/DhQzDTbe.js +1 -0
  294. alasio/deploy_data/frontend/_app/immutable/chunks/DjgbG-a_.js +1 -0
  295. alasio/deploy_data/frontend/_app/immutable/chunks/DlDfmLXX.js +1 -0
  296. alasio/deploy_data/frontend/_app/immutable/chunks/DsqGcPLg.js +1 -0
  297. alasio/deploy_data/frontend/_app/immutable/chunks/DsvzmDIz.js +1 -0
  298. alasio/deploy_data/frontend/_app/immutable/chunks/Dt-HX3Vu.js +1 -0
  299. alasio/deploy_data/frontend/_app/immutable/chunks/DxhPVHKV.js +1 -0
  300. alasio/deploy_data/frontend/_app/immutable/chunks/E0iefs2E.js +1 -0
  301. alasio/deploy_data/frontend/_app/immutable/chunks/GPTTlGC3.js +1 -0
  302. alasio/deploy_data/frontend/_app/immutable/chunks/POxmYQdJ.js +1 -0
  303. alasio/deploy_data/frontend/_app/immutable/chunks/PRNB418f.js +1 -0
  304. alasio/deploy_data/frontend/_app/immutable/chunks/VRTqFh1I.js +1 -0
  305. alasio/deploy_data/frontend/_app/immutable/chunks/WNunVdlW.js +1 -0
  306. alasio/deploy_data/frontend/_app/immutable/chunks/YuJ3Rkmi.js +1 -0
  307. alasio/deploy_data/frontend/_app/immutable/chunks/_NbQBaer.js +1 -0
  308. alasio/deploy_data/frontend/_app/immutable/chunks/bZpo2XFb.js +1 -0
  309. alasio/deploy_data/frontend/_app/immutable/chunks/qxqJpF8J.js +1 -0
  310. alasio/deploy_data/frontend/_app/immutable/chunks/r5Ivw3m7.js +1 -0
  311. alasio/deploy_data/frontend/_app/immutable/chunks/w311F1AZ.js +1 -0
  312. alasio/deploy_data/frontend/_app/immutable/chunks/xihTtKlq.js +1 -0
  313. alasio/deploy_data/frontend/_app/immutable/entry/app.C-c0FsJc.js +2 -0
  314. alasio/deploy_data/frontend/_app/immutable/entry/start.hQAc6FoB.js +1 -0
  315. alasio/deploy_data/frontend/_app/immutable/nodes/0.BnjcDdBX.js +1 -0
  316. alasio/deploy_data/frontend/_app/immutable/nodes/1.B1yf2DAZ.js +1 -0
  317. alasio/deploy_data/frontend/_app/immutable/nodes/10.BlTb0DUa.js +1 -0
  318. alasio/deploy_data/frontend/_app/immutable/nodes/11.CKC3PnpE.js +1 -0
  319. alasio/deploy_data/frontend/_app/immutable/nodes/12.CVm0G1_9.js +1 -0
  320. alasio/deploy_data/frontend/_app/immutable/nodes/13.BE7EJde3.js +4 -0
  321. alasio/deploy_data/frontend/_app/immutable/nodes/14.D79B8dIJ.js +1 -0
  322. alasio/deploy_data/frontend/_app/immutable/nodes/15.RBxeF4Ig.js +1 -0
  323. alasio/deploy_data/frontend/_app/immutable/nodes/16.BY_MqC-W.js +1 -0
  324. alasio/deploy_data/frontend/_app/immutable/nodes/17.BuqsdZ4-.js +1 -0
  325. alasio/deploy_data/frontend/_app/immutable/nodes/18.mOJ2N80g.js +1 -0
  326. alasio/deploy_data/frontend/_app/immutable/nodes/2.DtVVejdw.js +1 -0
  327. alasio/deploy_data/frontend/_app/immutable/nodes/3.BvTiP1zR.js +1 -0
  328. alasio/deploy_data/frontend/_app/immutable/nodes/4.D3dtUjri.js +1 -0
  329. alasio/deploy_data/frontend/_app/immutable/nodes/5.BK0Li99R.js +1 -0
  330. alasio/deploy_data/frontend/_app/immutable/nodes/6.BrWoS5i3.js +1 -0
  331. alasio/deploy_data/frontend/_app/immutable/nodes/7.Dmnm-P_G.js +1 -0
  332. alasio/deploy_data/frontend/_app/immutable/nodes/8.EPgaXfeA.js +1 -0
  333. alasio/deploy_data/frontend/_app/immutable/nodes/9.C90BOvcG.js +9 -0
  334. alasio/deploy_data/frontend/_app/version.json +1 -0
  335. alasio/deploy_data/frontend/favicon.png +0 -0
  336. alasio/deploy_data/frontend/index.html +87 -0
  337. alasio/deploy_data/frontend/sample-preview.jpg +0 -0
  338. alasio/deploy_data/frontend-manifest.pack +0 -0
  339. alasio/deploy_data/webapp/app.asar +0 -0
  340. alasio/deploy_dev/get_version.py +78 -0
  341. alasio/deploy_dev/history/cli.py +57 -0
  342. alasio/deploy_dev/history/encode_history.py +92 -0
  343. alasio/deploy_dev/history/pack_history.py +41 -0
  344. alasio/deploy_dev/pack/_pack_cache.py +429 -0
  345. alasio/deploy_dev/pack/encode_base.py +482 -0
  346. alasio/deploy_dev/pack/encode_manifest.py +110 -0
  347. alasio/deploy_dev/pack/encode_packdep.py +42 -0
  348. alasio/deploy_dev/pack/pack_full.py +776 -0
  349. alasio/deploy_dev/pack/pack_update.py +246 -0
  350. alasio/deploy_dev/pack/pack_wheel.py +592 -0
  351. alasio/deploy_dev/pack/pack_wheel_update.py +529 -0
  352. alasio/deploy_dev/pack/repo_diff.py +665 -0
  353. alasio/deploy_dev/pack_server/dep_gen.py +697 -0
  354. alasio/deploy_dev/pack_server/fetch_wheel.py +581 -0
  355. alasio/deploy_dev/pack_server/gate.py +133 -0
  356. alasio/deploy_dev/pack_server/lookback.py +393 -0
  357. alasio/deploy_dev/pack_server/lookback_wheel.py +334 -0
  358. alasio/deploy_dev/pack_server/main.py +210 -0
  359. alasio/deploy_dev/pack_server/model.py +229 -0
  360. alasio/deploy_dev/pack_server/pack_check.py +297 -0
  361. alasio/deploy_dev/pack_server/pack_gen.py +359 -0
  362. alasio/deploy_dev/pack_server/pack_repo.py +372 -0
  363. alasio/deploy_dev/pack_server/parse_dep.py +284 -0
  364. alasio/deploy_dev/pack_server/parse_entry.py +582 -0
  365. alasio/deploy_dev/pack_server/serve.py +165 -0
  366. alasio/deploy_dev/release/cleanup.py +315 -0
  367. alasio/deploy_dev/wheel/__main__.py +4 -0
  368. alasio/deploy_dev/wheel/alasio_wheel.py +122 -0
  369. alasio/deploy_dev/wheel/archive.py +274 -0
  370. alasio/deploy_dev/wheel/build_wheel.py +423 -0
  371. alasio/deploy_dev/wheel/cli.py +144 -0
  372. alasio/deploy_dev/wheel/parse_metadata.py +232 -0
  373. alasio/deploy_dev/wheel/repo_path.py +211 -0
  374. alasio/deploy_dev/wheel/verify.py +733 -0
  375. alasio/device/base.py +281 -0
  376. alasio/device/config.py +199 -0
  377. alasio/device/search/base.py +317 -0
  378. alasio/device/search/search.py +11 -0
  379. alasio/device/search/windows.py +310 -0
  380. alasio/device/search/windows_reg.py +256 -0
  381. alasio/device/serialstr.py +76 -0
  382. alasio/ext/__init__.py +0 -0
  383. alasio/ext/algorithm/bit2coding/bit2coding_decode.py +219 -0
  384. alasio/ext/algorithm/bit2coding/bit2coding_encode_c.py +43 -0
  385. alasio/ext/algorithm/bit2coding/bit2coding_encode_python.py +543 -0
  386. alasio/ext/algorithm/bit2coding/vlenint_decode.py +38 -0
  387. alasio/ext/algorithm/bit2coding/vlenint_encode_c.py +39 -0
  388. alasio/ext/algorithm/bit2coding/vlenint_encode_python.py +68 -0
  389. alasio/ext/algorithm/checksum.py +18 -0
  390. alasio/ext/algorithm/const.py +5 -0
  391. alasio/ext/algorithm/diffcooding.py +63 -0
  392. alasio/ext/algorithm/lcp.py +121 -0
  393. alasio/ext/algorithm/lz77.py +136 -0
  394. alasio/ext/algorithm/pathcomb/pathcomb_decode.py +93 -0
  395. alasio/ext/algorithm/pathcomb/pathcomb_encode_c.py +112 -0
  396. alasio/ext/algorithm/pathcomb/pathcomb_encode_python.py +289 -0
  397. alasio/ext/algorithm/pathlcs.py +157 -0
  398. alasio/ext/algorithm/pathlcs_v3.py +50 -0
  399. alasio/ext/algorithm/unpack.py +70 -0
  400. alasio/ext/algorithm/vint.py +185 -0
  401. alasio/ext/algorithm/zigzag.py +62 -0
  402. alasio/ext/cache/__init__.py +14 -0
  403. alasio/ext/cache/cache.py +670 -0
  404. alasio/ext/cache/cache_async.py +413 -0
  405. alasio/ext/cache/msgspec_meta.py +47 -0
  406. alasio/ext/cache/resource.py +192 -0
  407. alasio/ext/compress/algo_lzma.py +83 -0
  408. alasio/ext/compress/algo_zstd.py +160 -0
  409. alasio/ext/concurrent/cmd.py +183 -0
  410. alasio/ext/concurrent/prioritycapacity.py +116 -0
  411. alasio/ext/concurrent/prioritycapacity_trio.py +106 -0
  412. alasio/ext/concurrent/prioritythreadpool.py +230 -0
  413. alasio/ext/concurrent/processpool.py +370 -0
  414. alasio/ext/concurrent/processworker.py +35 -0
  415. alasio/ext/concurrent/threadpool.py +566 -0
  416. alasio/ext/concurrent/threadpool_wrapper.py +136 -0
  417. alasio/ext/deep.py +1063 -0
  418. alasio/ext/download.py +51 -0
  419. alasio/ext/env.py +42 -0
  420. alasio/ext/file/__init__.py +0 -0
  421. alasio/ext/file/filelock.py +363 -0
  422. alasio/ext/file/hash.py +126 -0
  423. alasio/ext/file/jsonfile.py +266 -0
  424. alasio/ext/file/loaddll.py +56 -0
  425. alasio/ext/file/loadpy.py +82 -0
  426. alasio/ext/file/msgspecfile.py +91 -0
  427. alasio/ext/file/tomlfile.py +44 -0
  428. alasio/ext/file/watchdog.py +265 -0
  429. alasio/ext/file/yamlconfig.py +442 -0
  430. alasio/ext/file/yamlfile.py +132 -0
  431. alasio/ext/inflect.py +80 -0
  432. alasio/ext/path/__init__.py +1 -0
  433. alasio/ext/path/atomic.py +1113 -0
  434. alasio/ext/path/calc.py +390 -0
  435. alasio/ext/path/iter.py +273 -0
  436. alasio/ext/path/makedir.py +112 -0
  437. alasio/ext/path/pathstr.py +775 -0
  438. alasio/ext/path/validate.py +265 -0
  439. alasio/ext/perf.py +448 -0
  440. alasio/ext/proc/__init__.py +6 -0
  441. alasio/ext/proc/cmd.py +123 -0
  442. alasio/ext/proc/iter.py +59 -0
  443. alasio/ext/proc/nice.py +120 -0
  444. alasio/ext/proc/sig.py +71 -0
  445. alasio/ext/singleton.py +320 -0
  446. alasio/ext/starapi/__init__.py +0 -0
  447. alasio/ext/starapi/asgi.py +278 -0
  448. alasio/ext/starapi/param.py +424 -0
  449. alasio/ext/starapi/router.py +144 -0
  450. alasio/ext/timez.py +155 -0
  451. alasio/git/__init__.py +0 -0
  452. alasio/git/attr/attr.py +137 -0
  453. alasio/git/attr/attrfile.py +242 -0
  454. alasio/git/attr/attrline.py +166 -0
  455. alasio/git/attr/pathregex.py +236 -0
  456. alasio/git/eol/__init__.py +1 -0
  457. alasio/git/eol/const.py +43 -0
  458. alasio/git/eol/constgen.py +110 -0
  459. alasio/git/eol/eol.py +151 -0
  460. alasio/git/eol/gitattributes/C++.gitattributes +37 -0
  461. alasio/git/eol/gitattributes/CSharp.gitattributes +8 -0
  462. alasio/git/eol/gitattributes/Global/DevContainer.gitattributes +3 -0
  463. alasio/git/eol/gitattributes/Global/VisualStudio.gitattributes +53 -0
  464. alasio/git/eol/gitattributes/Global/VisualStudioCode.gitattributes +2 -0
  465. alasio/git/eol/gitattributes/Go.gitattributes +2 -0
  466. alasio/git/eol/gitattributes/Java.gitattributes +43 -0
  467. alasio/git/eol/gitattributes/Lua.gitattributes +10 -0
  468. alasio/git/eol/gitattributes/Markdown.gitattributes +2 -0
  469. alasio/git/eol/gitattributes/MicrosoftShell.gitattributes +12 -0
  470. alasio/git/eol/gitattributes/PHP.gitattributes +15 -0
  471. alasio/git/eol/gitattributes/PowerShell.gitattributes +12 -0
  472. alasio/git/eol/gitattributes/Python.gitattributes +29 -0
  473. alasio/git/eol/gitattributes/Rails.gitattributes +7 -0
  474. alasio/git/eol/gitattributes/Rust.gitattributes +6 -0
  475. alasio/git/eol/gitattributes/Swift.gitattributes +3 -0
  476. alasio/git/eol/gitattributes/Vim.gitattributes +8 -0
  477. alasio/git/eol/gitattributes/Web.gitattributes +233 -0
  478. alasio/git/fetch/__init__.py +0 -0
  479. alasio/git/fetch/argument.py +145 -0
  480. alasio/git/fetch/pkt.py +242 -0
  481. alasio/git/fetch/transport.py +71 -0
  482. alasio/git/fetch/transport_git.py +216 -0
  483. alasio/git/fetch/transport_http.py +172 -0
  484. alasio/git/fetch/url.py +181 -0
  485. alasio/git/file/exception.py +66 -0
  486. alasio/git/file/gitobject.py +394 -0
  487. alasio/git/file/idx.py +188 -0
  488. alasio/git/file/loose.py +136 -0
  489. alasio/git/file/pack.py +324 -0
  490. alasio/git/mock/mock_base.py +15 -0
  491. alasio/git/mock/mock_object.py +527 -0
  492. alasio/git/mock/mock_repo.py +5 -0
  493. alasio/git/obj/obj.py +517 -0
  494. alasio/git/obj/objcommit.py +202 -0
  495. alasio/git/obj/objdelta.py +429 -0
  496. alasio/git/obj/objtag.py +134 -0
  497. alasio/git/obj/objtree.py +67 -0
  498. alasio/git/repo.py +8 -0
  499. alasio/git/stage/base.py +7 -0
  500. alasio/git/stage/genidx.py +307 -0
  501. alasio/git/stage/gitadd.py +201 -0
  502. alasio/git/stage/gitcommit.py +166 -0
  503. alasio/git/stage/gitconfig.py +228 -0
  504. alasio/git/stage/gitref.py +271 -0
  505. alasio/git/stage/gitreset.py +383 -0
  506. alasio/git/stage/gittag.py +53 -0
  507. alasio/git/stage/hashobj.py +68 -0
  508. alasio/git/stage/index.py +490 -0
  509. alasio/logger/__init__.py +1 -0
  510. alasio/logger/error.py +134 -0
  511. alasio/logger/logger.py +653 -0
  512. alasio/logger/utils.py +216 -0
  513. alasio/logger/writer.py +349 -0
  514. alasio/mcp/std_server.py +106 -0
  515. alasio/mcp/tool/base.py +86 -0
  516. alasio/mcp/tool/exec_python.py +84 -0
  517. alasio/mcp/tool/exec_shell.py +152 -0
  518. alasio/ocr/postprocess/replace.py +68 -0
  519. alasio/speedup/__init__.py +213 -0
  520. alasio/spider/deduplicate.py +61 -0
  521. alasio/spider/spawner.py +61 -0
  522. alasio/testing/drop.py +69 -0
  523. alasio/testing/filesystem/__init__.py +152 -0
  524. alasio/testing/filesystem/base.py +282 -0
  525. alasio/testing/filesystem/entry.py +127 -0
  526. alasio/testing/filesystem/fake_fs.py +1526 -0
  527. alasio/testing/filesystem/file_object.py +529 -0
  528. alasio/testing/managed_process.py +302 -0
  529. alasio/testing/patch_time.py +175 -0
  530. alasio/testing/preview/__init__.py +18 -0
  531. alasio/testing/preview/parse_unittest.py +377 -0
  532. alasio/testing/screenshot.py +420 -0
  533. alasio/testing/screenshot_device.py +99 -0
  534. alasio/testing/static_file.py +178 -0
  535. alasio/testing/timeout.py +53 -0
  536. alasio-2.0.0.dist-info/METADATA +57 -0
  537. alasio-2.0.0.dist-info/RECORD +539 -0
  538. alasio-2.0.0.dist-info/WHEEL +5 -0
  539. alasio-2.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,420 @@
1
+ """
2
+ Screenshot golden tests of game script modules.
3
+
4
+ A game script module reads the game from `device.image`, so the unit test of a
5
+ module starts by binding a screenshot to the device the module runs on.
6
+ Screenshots are collected by hand under `<project root>/collection`, a test binds
7
+ one with the `image` decorator and asks for the modules it needs by annotating
8
+ its parameters, the parameter names are free:
9
+
10
+ from alasio.testing.screenshot import image
11
+
12
+ class TestFleetBarNotExpanded:
13
+ @image("map/fleet_bar/not_expanded.webp")
14
+ def test_not_expanded(self, main: FleetPreparation, combat: CombatModule):
15
+ print(main.detect_fleet_bar())
16
+
17
+ The flow of a golden test:
18
+
19
+ 1. The draft test prints what the modules return, without a single assert.
20
+ 2. Run it, the printed output is the golden result.
21
+ 3. Copy the printed output into the test as asserts, on the Python side, so the
22
+ test may also assert attributes, warnings and logs.
23
+ 4. A human reads the screenshot and the asserts together and corrects them, and
24
+ the asserts stay in the test file as the readable record of that review.
25
+
26
+ A module parameter is built the way the scheduler builds it - the module class
27
+ declares its own config class, and it is constructed with the config of the mod
28
+ and the device of the scheduler - except that the device is the offline device of
29
+ the test, which holds exactly the screenshot of the test, see
30
+ screenshot_device.py:
31
+
32
+ - `device.image` is the screenshot, and the values cached on a screenshot
33
+ (@cached_on_screenshot) are computed on it, like on a real screenshot
34
+ - `device.screenshot()` raises instead of capturing: a module that needs a
35
+ second screenshot is a test missing a screenshot, not a module that re-reads a
36
+ stale image
37
+ - `device.click()` / `device.drag()` are recorded and do nothing, so a test may
38
+ follow a module into an action and assert on it afterwards
39
+
40
+ All the modules of a test run on the one device of the test, so the test reads it
41
+ from any of them (`main.device`) and builds more modules with
42
+ `build_main(cls, device)`.
43
+
44
+ A test module only imports the `image` decorator; the modules a test asks for are
45
+ looked up by the annotations of its parameters, nothing is registered as a
46
+ fixture. The plugin is enabled in the pytest configuration of the project:
47
+
48
+ [tool.pytest.ini_options]
49
+ addopts = ["-p", "alasio.testing.screenshot"]
50
+
51
+ It is loaded by module path instead of being an installed entry point, so a
52
+ plain checkout runs the tests without installing the package first.
53
+
54
+ The project root of a test is the nearest ancestor of the test file holding
55
+ `module/config/const.py`, which covers both layouts of a mod: a mod inside the
56
+ Alasio repository (`<repo>/ExampleMod`) and a mod that is the repository itself
57
+ (`<repo>` as a whole).
58
+ """
59
+ import inspect
60
+ from typing import get_type_hints
61
+
62
+ import pytest
63
+ from msgspecerror import get_class_annotation
64
+
65
+ from alasio.config.base import AlasioConfigBase
66
+ from alasio.ext.path import PathStr
67
+ from alasio.testing.screenshot_device import ScreenshotDevice, ScreenshotTestError
68
+
69
+ # Attribute of the test function holding the screenshot of the `image` decorator
70
+ ATTR_SCREENSHOT = '__screenshot__'
71
+ # Folder of the collected screenshots, relative to the project root
72
+ COLLECTION = 'collection'
73
+ # Entry file of a mod, the folder holding it is the project root of the mod
74
+ MOD_CONST = 'module/config/const.py'
75
+ # Config name of the tests: a template config, which is read only and never
76
+ # touches the database, every group falls back to its default values
77
+ CONFIG_NAME = 'template'
78
+
79
+
80
+ class ScreenshotNotFound(ScreenshotTestError):
81
+ """
82
+ Raised if the screenshot bound by `image` does not exist
83
+ """
84
+ pass
85
+
86
+
87
+ class ModuleRequest:
88
+ """
89
+ The placeholder of an annotated module parameter, see module_parameters().
90
+
91
+ pytest parametrizes the parameter with a request instead of a fixture, the
92
+ module is built when the test runs, see pytest_pyfunc_call().
93
+ """
94
+
95
+ def __init__(self, cls):
96
+ """
97
+ Args:
98
+ cls (type): The module class of the annotation
99
+ """
100
+ self.cls = cls
101
+
102
+ def __repr__(self):
103
+ return f'{self.__class__.__name__}({self.cls.__name__})'
104
+
105
+
106
+ def image(path):
107
+ """
108
+ Bind a screenshot of the collection folder to a test
109
+
110
+ Args:
111
+ path (str): Path of the screenshot relative to `<project root>/collection`,
112
+ e.g. "map/fleet_bar/not_expanded.png"
113
+
114
+ Returns:
115
+ callable: The decorator
116
+ """
117
+ def decorator(func):
118
+ setattr(func, ATTR_SCREENSHOT, path)
119
+ return func
120
+
121
+ return decorator
122
+
123
+
124
+ class ProjectRootManager:
125
+ """
126
+ The project roots of the mods of the running session.
127
+
128
+ A project root is a folder holding `module/config/const.py`, the entry file of
129
+ a mod. A real mod has many test files and they all live under the one root of
130
+ the mod, so a root is discovered once and reused: resolving a test file under
131
+ a known root walks no folder, it is a sub-path check.
132
+
133
+ Attributes:
134
+ roots (list[PathStr]): The project roots discovered so far
135
+ """
136
+
137
+ def __init__(self):
138
+ self.roots = []
139
+
140
+ def get_project_root(self, test_file):
141
+ """
142
+ Get the project root of a test file, which is the nearest ancestor of the
143
+ test file holding `module/config/const.py`
144
+
145
+ Args:
146
+ test_file (str): Path of the test file, absolute like the path pytest
147
+ reports, the result of a relative path depends on the working folder
148
+
149
+ Returns:
150
+ PathStr:
151
+
152
+ Raises:
153
+ ScreenshotTestError: If no project root is found
154
+ """
155
+ path = PathStr.new(test_file).abspath()
156
+
157
+ # The test file belongs to a mod discovered by an earlier test file
158
+ root = self.get_known_root(path)
159
+ if root is not None:
160
+ return root
161
+
162
+ # First test file of this mod: walk up once and remember the root
163
+ root = self.find_root(path, test_file)
164
+ self.roots.append(root)
165
+ return root
166
+
167
+ def get_known_root(self, path):
168
+ """
169
+ Get the known project root holding a path, the deepest one if several do
170
+
171
+ Args:
172
+ path (str): Normalized absolute path
173
+
174
+ Returns:
175
+ PathStr | None: The root, None if no known root holds the path
176
+ """
177
+ path = PathStr.new(path)
178
+ matched = None
179
+ for root in self.roots:
180
+ if path.subpath_to(root) is None:
181
+ continue
182
+ if matched is None or len(root) > len(matched):
183
+ matched = root
184
+ return matched
185
+
186
+ @staticmethod
187
+ def find_root(path, test_file=None):
188
+ """
189
+ Walk up from a path to the nearest folder holding `module/config/const.py`
190
+
191
+ Args:
192
+ path (str): Normalized absolute path
193
+ test_file (str): Path to report in the error, `path` if not given
194
+
195
+ Returns:
196
+ PathStr:
197
+
198
+ Raises:
199
+ ScreenshotTestError: If no project root is found
200
+ """
201
+ folder = PathStr.new(path)
202
+ while folder:
203
+ if folder.joinpath(MOD_CONST).isfile():
204
+ return folder
205
+ parent = folder.uppath(1)
206
+ if parent == folder:
207
+ break
208
+ folder = parent
209
+
210
+ raise ScreenshotTestError(
211
+ f'No project root above the test file "{test_file or path}", a project root is '
212
+ f'a folder holding "{MOD_CONST}"'
213
+ )
214
+
215
+
216
+ # The project roots of the mods of the running session
217
+ PROJECT_ROOT_MANAGER = ProjectRootManager()
218
+
219
+
220
+ def test_name(item):
221
+ """
222
+ The name of a test, from a pytest item or a fixture request
223
+
224
+ Args:
225
+ item (Function | FixtureRequest):
226
+
227
+ Returns:
228
+ str:
229
+ """
230
+ node = getattr(item, 'node', item)
231
+ return node.name
232
+
233
+
234
+ def screenshot_of(item):
235
+ """
236
+ Resolve the screenshot bound by the `image` decorator
237
+
238
+ The file is not checked here: a check is one IO call that the read
239
+ duplicates, so the missing file is reported by load_screenshot() from the
240
+ read itself instead.
241
+
242
+ Args:
243
+ item (Function | FixtureRequest): The test item or request, both carry
244
+ the test function and the path of the test file
245
+
246
+ Returns:
247
+ PathStr: Path of the screenshot
248
+
249
+ Raises:
250
+ ScreenshotNotFound: If the test has no `image` decorator
251
+ """
252
+ path = getattr(item.function, ATTR_SCREENSHOT, None)
253
+ if path is None:
254
+ raise ScreenshotNotFound(
255
+ f'"{test_name(item)}" has no screenshot, decorate the test with '
256
+ f'@image("<screenshot>") to bind one of the collection folder'
257
+ )
258
+
259
+ root = PROJECT_ROOT_MANAGER.get_project_root(str(item.fspath))
260
+ return root.joinpath(COLLECTION).joinpath(path)
261
+
262
+
263
+ def load_screenshot(item):
264
+ """
265
+ The screenshot bound by the `image` decorator, loaded from the collection
266
+ folder
267
+
268
+ Args:
269
+ item (Function | FixtureRequest): The test item or request
270
+
271
+ Returns:
272
+ tuple[PathStr, np.ndarray]: Path of the screenshot, and the image
273
+
274
+ Raises:
275
+ ScreenshotNotFound: If the test has no `image` decorator, or if the
276
+ screenshot does not exist
277
+ """
278
+ file = screenshot_of(item)
279
+ # local import to avoid importing numpy/opencv when the pytest plugin loads
280
+ from alasio.base.image.imfile import image_load
281
+
282
+ try:
283
+ return file, image_load(file)
284
+ except FileNotFoundError:
285
+ raise ScreenshotNotFound(
286
+ f'Screenshot of "{test_name(item)}" does not exist: {file}'
287
+ ) from None
288
+
289
+
290
+ def config_of(cls):
291
+ """
292
+ Build the config of a module class, the way the scheduler does: the module
293
+ class declares its own config class, and the config is loaded with the mod
294
+ entry of that class
295
+
296
+ The config of a test is a template config, which is read only: no database
297
+ and no user config file is involved, every group of the config falls back to
298
+ its default values.
299
+
300
+ Args:
301
+ cls (type): The module class under test
302
+
303
+ Returns:
304
+ AlasioConfigBase:
305
+
306
+ Raises:
307
+ ScreenshotTestError: If the class does not declare a config class of its own
308
+ """
309
+ try:
310
+ config_cls = get_class_annotation(cls, 'config')
311
+ except AttributeError:
312
+ raise ScreenshotTestError(
313
+ f'"{cls.__name__}" has no "config" annotation, annotate it like the '
314
+ f'mod does: "config: Config"'
315
+ ) from None
316
+
317
+ if config_cls is AlasioConfigBase:
318
+ raise ScreenshotTestError(
319
+ f'"{cls.__name__}" declares no config class of its own, annotate it '
320
+ f'like the mod does: "config: Config"'
321
+ )
322
+
323
+ return config_cls(CONFIG_NAME)
324
+
325
+
326
+ def build_main(cls, device, **kwargs):
327
+ """
328
+ Build a module class the way the scheduler builds it, except that its device
329
+ is the offline device of a test
330
+
331
+ Args:
332
+ cls (type): The module class under test
333
+ device (DeviceBase): The device of the test, holding the screenshot
334
+ **kwargs: Extra arguments of the constructor of the class
335
+
336
+ Returns:
337
+ object: The module under test
338
+ """
339
+ config = config_of(cls)
340
+ return cls(config, device=device, **kwargs)
341
+
342
+
343
+ def module_parameters(function):
344
+ """
345
+ The parameters of a test that ask for a module, by the annotation of the
346
+ parameter: `def test(self, main: FleetPreparation)`, the name of the
347
+ parameter is free.
348
+
349
+ Args:
350
+ function (callable): The test function
351
+
352
+ Returns:
353
+ dict[str, type]: {parameter name: module class}
354
+ """
355
+ try:
356
+ # Resolve the annotations written as a string, e.g. "FleetPreparation"
357
+ annotations = get_type_hints(function)
358
+ except NameError:
359
+ # An annotation does not resolve, report it as it is written
360
+ annotations = getattr(function, '__annotations__', {})
361
+
362
+ out = {}
363
+ for name, annotation in annotations.items():
364
+ if name == 'self':
365
+ continue
366
+ if not isinstance(annotation, type):
367
+ continue
368
+ # A module class declares the config class of its mod, see build_main()
369
+ try:
370
+ get_class_annotation(annotation, 'config')
371
+ except (AttributeError, TypeError):
372
+ continue
373
+ out[name] = annotation
374
+ return out
375
+
376
+
377
+ def pytest_generate_tests(metafunc):
378
+ """
379
+ Parametrize the module parameters of a screenshot test with a placeholder, so
380
+ pytest does not look for a fixture named after the parameter: the module is
381
+ built from its annotation when the test runs, see pytest_pyfunc_call()
382
+ """
383
+ if getattr(metafunc.function, ATTR_SCREENSHOT, None) is None:
384
+ return
385
+
386
+ for name, cls in module_parameters(metafunc.function).items():
387
+ metafunc.parametrize(name, [ModuleRequest(cls)], ids=[cls.__name__])
388
+
389
+
390
+ @pytest.hookimpl(tryfirst=True)
391
+ def pytest_pyfunc_call(pyfuncitem):
392
+ """
393
+ Build the modules of a screenshot test on the screenshot of the test, and
394
+ call the test with them
395
+ """
396
+ requests = {
397
+ name: pyfuncitem.funcargs[name]
398
+ for name in module_parameters(pyfuncitem.function)
399
+ if isinstance(pyfuncitem.funcargs.get(name), ModuleRequest)
400
+ }
401
+ if not requests:
402
+ return None
403
+ if inspect.iscoroutinefunction(pyfuncitem.function):
404
+ raise ScreenshotTestError(f'"{pyfuncitem.name}" is async, a screenshot test is sync')
405
+
406
+ # All the modules of the test run on the one screenshot of the test
407
+ device = None
408
+ modules = {}
409
+ for name, request in requests.items():
410
+ if device is None:
411
+ file, image = load_screenshot(pyfuncitem)
412
+ device = ScreenshotDevice(image=image, file=file)
413
+ modules[name] = build_main(request.cls, device)
414
+
415
+ # Call the test with its fixtures and its modules
416
+ names = set(inspect.signature(pyfuncitem.function).parameters) - {'self'}
417
+ kwargs = {name: value for name, value in pyfuncitem.funcargs.items() if name in names}
418
+ kwargs.update(modules)
419
+ pyfuncitem.obj(**kwargs)
420
+ return True
@@ -0,0 +1,99 @@
1
+ """
2
+ The offline device of a screenshot test.
3
+
4
+ A game script module reads the game from `device.image`, so the test of a module
5
+ runs it on a device holding the screenshot of the test instead of a connected
6
+ device: the device never connects anywhere, it never takes a screenshot, and it
7
+ never clicks anything, it records the actions of the module under test so that
8
+ the test can assert on them.
9
+
10
+ The device is independent of pytest, a test only needs a screenshot to build it:
11
+
12
+ device = ScreenshotDevice(image, file='map/fleet_bar/not_expanded.webp')
13
+ main = FleetPreparation(config, device=device)
14
+
15
+ The pytest plugin of the screenshot tests, which binds the screenshot of a test
16
+ with the `image` decorator and builds the modules a test asks for, is
17
+ alasio.testing.screenshot.
18
+ """
19
+ from alasio.device.base import DeviceBase
20
+ from alasio.device.config import DeviceConfig
21
+
22
+
23
+ class ScreenshotTestError(Exception):
24
+ """
25
+ Raised if a screenshot test is not set up as it should be
26
+ """
27
+ pass
28
+
29
+
30
+ class ScreenshotNotProvided(ScreenshotTestError):
31
+ """
32
+ Raised if the module under test takes a screenshot the test did not provide
33
+ """
34
+ pass
35
+
36
+
37
+ class ScreenshotDevice(DeviceBase):
38
+ """
39
+ A device holding the screenshot of a test, that never connects anywhere.
40
+
41
+ Attributes:
42
+ file (str): Path of the screenshot of the test
43
+ clicks (list): Buttons clicked by the module under test
44
+ drags (list): (p1, p2) of the drags of the module under test
45
+ sleeps (list): Seconds the module under test waited for
46
+ """
47
+
48
+ def __init__(self, image, file=None):
49
+ """
50
+ Args:
51
+ image (np.ndarray): The screenshot of the test
52
+ file (str): Path of the screenshot, for error messages
53
+ """
54
+ super().__init__(DeviceConfig())
55
+ self.file = file
56
+ self.clicks = []
57
+ self.drags = []
58
+ self.sleeps = []
59
+ # Set the image like the dev tools do, so the values cached on a
60
+ # screenshot are computed on the screenshot of the test
61
+ self.set_image(image)
62
+
63
+ def screenshot(self):
64
+ """
65
+ Raises:
66
+ ScreenshotNotProvided: Always, a test provides exactly one screenshot
67
+ """
68
+ raise ScreenshotNotProvided(
69
+ f'"{self.file}" is the only screenshot of this test, but the module under test '
70
+ f'asked for another screenshot. Add a screenshot of that page to the test, or '
71
+ f'reuse the screenshot of the first one (skip_first_screenshot).'
72
+ )
73
+
74
+ def click(self, button, *args, **kwargs):
75
+ """
76
+ Record a click, do nothing: a screenshot test does not click
77
+ """
78
+ self.clicks.append(button)
79
+
80
+ def stuck_record_add(self, button):
81
+ """
82
+ Do nothing: stuck detection belongs to a connected device, a screenshot
83
+ is never stuck
84
+ """
85
+ pass
86
+
87
+ def drag(self, p1, p2, *args, **kwargs):
88
+ """
89
+ Record a drag, do nothing
90
+ """
91
+ self.drags.append((p1, p2))
92
+
93
+ swipe = drag
94
+
95
+ def sleep(self, second):
96
+ """
97
+ Record a wait, do nothing
98
+ """
99
+ self.sleeps.append(second)
@@ -0,0 +1,178 @@
1
+ """
2
+ An in-memory static file server for the tests: MockStaticFile.
3
+
4
+ The files are registered in memory and served by the ASGI app of the instance,
5
+ with the semantics a client of a static file server depends on: the whole file
6
+ (200), the bytes of a single Range request (206, with the content-range
7
+ header), a range outside the file (416), a path nothing was registered for
8
+ (404), the headers of a HEAD answer without a body, content-length and
9
+ accept-ranges on every answer. No filesystem is involved: a test that already
10
+ runs under the in-memory filesystem of the project
11
+ (alasio.testing.filesystem) does not have to materialize the files of the
12
+ server anywhere, the two layers stay apart.
13
+
14
+ The app is an ASGI callable (the instance itself), used with httpx2 or with
15
+ starlette's TestClient, on its own or mounted (Mount) under a path prefix:
16
+
17
+ server = MockStaticFile()
18
+ server.register_file('1.0/full.pack', b'...')
19
+ client = httpx2.AsyncClient(transport=httpx2.ASGITransport(app=server))
20
+
21
+ The mock is deliberately small: the multiple ranges (multipart/byteranges),
22
+ the conditional requests (If-Range / If-None-Match) and the content types of a
23
+ full static file server are not implemented, the clients of the project send a
24
+ single unconditional range of the bytes unit only.
25
+ """
26
+ import re
27
+
28
+ from starlette.responses import PlainTextResponse, Response
29
+ from starlette.routing import get_route_path
30
+
31
+
32
+ class MockRangeNotSatisfiable(Exception):
33
+ """
34
+ Raised when a Range request asks for bytes outside the file: the 416 of a
35
+ static file server.
36
+ """
37
+
38
+ def __init__(self, size):
39
+ """
40
+ Args:
41
+ size (int): Size of the file the range was asked for
42
+ """
43
+ super().__init__(f'Range not satisfiable: {size} bytes')
44
+ self.size = size
45
+
46
+
47
+ class MockStaticFile:
48
+ """
49
+ An in-memory static file server: register_file() the files, the app of the
50
+ instance serves them.
51
+
52
+ Attributes:
53
+ files (dict[str, bytes]): {'/path': content} of the registered files,
54
+ the paths are '/'-separated and absolute
55
+ """
56
+
57
+ # bytes of one body message of an answer
58
+ CHUNK_SIZE = 65536
59
+
60
+ # the single range forms the clients of the project send: 'bytes=a-b',
61
+ # 'bytes=a-' and 'bytes=-n'
62
+ REGEX_RANGE = re.compile(r'bytes=(\d*)-(\d*)')
63
+
64
+ def __init__(self, files=None):
65
+ """
66
+ Args:
67
+ files (dict[str, bytes], optional): Files to register, see
68
+ register_file(). Defaults to None, no file
69
+ """
70
+ # {'/path': content}
71
+ self.files = {}
72
+ if files:
73
+ self.register_files(files)
74
+
75
+ def register_file(self, path, content):
76
+ """
77
+ Register a file, the app serves it at its path.
78
+
79
+ Args:
80
+ path (str): Path of the file below the root, '/'-separated, e.g.
81
+ 'latest.pack' or '1.0/full.pack'. The trailing '/' of the path
82
+ of a directory-like file (the index page of a simple mirror)
83
+ is kept, the client asks the url with it
84
+ content (bytes): Content of the file
85
+ """
86
+ name = path.strip('/')
87
+ if path.endswith('/') and name:
88
+ name += '/'
89
+ self.files[f'/{name}'] = content
90
+
91
+ def register_files(self, files):
92
+ """
93
+ Register several files, a path registered before is replaced.
94
+
95
+ Args:
96
+ files (dict[str, bytes]): {path: content}, see register_file()
97
+ """
98
+ for path, content in files.items():
99
+ self.register_file(path, content)
100
+
101
+ @classmethod
102
+ def parse_range(cls, http_range, size):
103
+ """
104
+ The range of a Range header.
105
+
106
+ Args:
107
+ http_range (str): Value of the Range header, e.g. 'bytes=2-5'
108
+ size (int): Size of the file the range is asked for
109
+
110
+ Returns:
111
+ tuple[int, int]: (start, end), the inclusive range to serve
112
+
113
+ Raises:
114
+ ValueError: If the header is not a single range of the bytes unit
115
+ (the form the mock does not implement)
116
+ MockRangeNotSatisfiable: If the range is outside the file
117
+ """
118
+ match = cls.REGEX_RANGE.fullmatch(http_range.strip())
119
+ if match is None:
120
+ raise ValueError(f'Not a single range of bytes: {http_range!r}')
121
+ first, last = match.groups()
122
+ if not first and not last:
123
+ raise ValueError(f'Not a range of bytes: {http_range!r}')
124
+ if not first:
125
+ # the last n bytes
126
+ start, end = max(size - int(last), 0), size - 1
127
+ else:
128
+ start = int(first)
129
+ end = size - 1 if not last else min(int(last), size - 1)
130
+ if start >= size or start > end:
131
+ raise MockRangeNotSatisfiable(size)
132
+ return start, end
133
+
134
+ async def __call__(self, scope, receive, send):
135
+ """
136
+ Serve one request: the whole file, the range of it, or a 404.
137
+
138
+ Args:
139
+ scope (dict): ASGI scope of the request
140
+ receive (Callable): ASGI receive
141
+ send (Callable): ASGI send
142
+ """
143
+ if scope['type'] != 'http':
144
+ # a static file server serves no websocket and has no lifespan
145
+ return
146
+ # the app is mountable: the file is looked up below the mount point
147
+ # (the root path of the scope), like the static files of starlette
148
+ path = get_route_path(scope)
149
+ content = self.files.get(path)
150
+ if content is None:
151
+ await PlainTextResponse('Not Found', status_code=404)(scope, receive, send)
152
+ return
153
+ size = len(content)
154
+ http_range = dict(scope['headers']).get(b'range', b'').decode('latin-1')
155
+ if not http_range:
156
+ body, status = content, 200
157
+ headers = {'accept-ranges': 'bytes', 'content-length': str(size)}
158
+ else:
159
+ try:
160
+ start, end = self.parse_range(http_range, size)
161
+ except MockRangeNotSatisfiable as e:
162
+ await Response(
163
+ b'', status_code=416,
164
+ headers={'content-range': f'bytes */{e.size}'})(scope, receive, send)
165
+ return
166
+ body = content[start:end + 1]
167
+ status = 206
168
+ headers = {
169
+ 'accept-ranges': 'bytes',
170
+ 'content-range': f'bytes {start}-{end}/{size}',
171
+ 'content-length': str(len(body)),
172
+ }
173
+ if scope['method'] == 'HEAD':
174
+ # the answer of a HEAD carries the headers only, the content-length
175
+ # is the one of the body that would be served
176
+ await Response(b'', status_code=status, headers=headers)(scope, receive, send)
177
+ return
178
+ await Response(body, status_code=status, headers=headers)(scope, receive, send)