test_var_operations.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. """Integration tests for var operations."""
  2. from typing import Generator
  3. import pytest
  4. from selenium.webdriver.common.by import By
  5. from reflex.testing import AppHarness
  6. # pyright: reportOptionalMemberAccess=false, reportGeneralTypeIssues=false, reportUnknownMemberType=false
  7. def VarOperations():
  8. """App with var operations."""
  9. import reflex as rx
  10. class VarOperationState(rx.State):
  11. int_var1: int = 10
  12. int_var2: int = 5
  13. int_var3: int = 7
  14. float_var1: float = 10.5
  15. float_var2: float = 5.5
  16. list1: list = [1, 2]
  17. list2: list = [3, 4]
  18. list3: list = ["first", "second", "third"]
  19. str_var1: str = "first"
  20. str_var2: str = "second"
  21. str_var3: str = "ThIrD"
  22. str_var4: str = "a long string"
  23. dict1: dict = {1: 2}
  24. dict2: dict = {3: 4}
  25. html_str: str = "<div>hello</div>"
  26. app = rx.App(state=rx.State)
  27. @app.add_page
  28. def index():
  29. return rx.vstack(
  30. rx.el.input(
  31. id="token",
  32. value=VarOperationState.router.session.client_token,
  33. is_read_only=True,
  34. ),
  35. # INT INT
  36. rx.text(
  37. VarOperationState.int_var1 + VarOperationState.int_var2,
  38. id="int_add_int",
  39. ),
  40. rx.text(
  41. VarOperationState.int_var1 * VarOperationState.int_var2,
  42. id="int_mult_int",
  43. ),
  44. rx.text(
  45. VarOperationState.int_var1 - VarOperationState.int_var2,
  46. id="int_sub_int",
  47. ),
  48. rx.text(
  49. VarOperationState.int_var1**VarOperationState.int_var2,
  50. id="int_exp_int",
  51. ),
  52. rx.text(
  53. VarOperationState.int_var1 / VarOperationState.int_var2,
  54. id="int_div_int",
  55. ),
  56. rx.text(
  57. VarOperationState.int_var1 // VarOperationState.int_var3,
  58. id="int_floor_int",
  59. ),
  60. rx.text(
  61. VarOperationState.int_var1 % VarOperationState.int_var2,
  62. id="int_mod_int",
  63. ),
  64. rx.text(
  65. VarOperationState.int_var1 | VarOperationState.int_var2,
  66. id="int_or_int",
  67. ),
  68. rx.text(
  69. (VarOperationState.int_var1 > VarOperationState.int_var2).to_string(),
  70. id="int_gt_int",
  71. ),
  72. rx.text(
  73. (VarOperationState.int_var1 < VarOperationState.int_var2).to_string(),
  74. id="int_lt_int",
  75. ),
  76. rx.text(
  77. (VarOperationState.int_var1 >= VarOperationState.int_var2).to_string(),
  78. id="int_gte_int",
  79. ),
  80. rx.text(
  81. (VarOperationState.int_var1 <= VarOperationState.int_var2).to_string(),
  82. id="int_lte_int",
  83. ),
  84. rx.text(
  85. VarOperationState.int_var1 & VarOperationState.int_var2,
  86. id="int_and_int",
  87. ),
  88. rx.text(
  89. (VarOperationState.int_var1 | VarOperationState.int_var2).to_string(),
  90. id="int_or_int",
  91. ),
  92. rx.text(
  93. (VarOperationState.int_var1 == VarOperationState.int_var2).to_string(),
  94. id="int_eq_int",
  95. ),
  96. rx.text(
  97. (VarOperationState.int_var1 != VarOperationState.int_var2).to_string(),
  98. id="int_neq_int",
  99. ),
  100. # INT FLOAT OR FLOAT INT
  101. rx.text(
  102. VarOperationState.float_var1 + VarOperationState.int_var2,
  103. id="float_add_int",
  104. ),
  105. rx.text(
  106. VarOperationState.float_var1 * VarOperationState.int_var2,
  107. id="float_mult_int",
  108. ),
  109. rx.text(
  110. VarOperationState.float_var1 - VarOperationState.int_var2,
  111. id="float_sub_int",
  112. ),
  113. rx.text(
  114. VarOperationState.float_var1**VarOperationState.int_var2,
  115. id="float_exp_int",
  116. ),
  117. rx.text(
  118. VarOperationState.float_var1 / VarOperationState.int_var2,
  119. id="float_div_int",
  120. ),
  121. rx.text(
  122. VarOperationState.float_var1 // VarOperationState.int_var3,
  123. id="float_floor_int",
  124. ),
  125. rx.text(
  126. VarOperationState.float_var1 % VarOperationState.int_var2,
  127. id="float_mod_int",
  128. ),
  129. rx.text(
  130. (VarOperationState.float_var1 > VarOperationState.int_var2).to_string(),
  131. id="float_gt_int",
  132. ),
  133. rx.text(
  134. (VarOperationState.float_var1 < VarOperationState.int_var2).to_string(),
  135. id="float_lt_int",
  136. ),
  137. rx.text(
  138. (
  139. VarOperationState.float_var1 >= VarOperationState.int_var2
  140. ).to_string(),
  141. id="float_gte_int",
  142. ),
  143. rx.text(
  144. (
  145. VarOperationState.float_var1 <= VarOperationState.int_var2
  146. ).to_string(),
  147. id="float_lte_int",
  148. ),
  149. rx.text(
  150. (
  151. VarOperationState.float_var1 == VarOperationState.int_var2
  152. ).to_string(),
  153. id="float_eq_int",
  154. ),
  155. rx.text(
  156. (
  157. VarOperationState.float_var1 != VarOperationState.int_var2
  158. ).to_string(),
  159. id="float_neq_int",
  160. ),
  161. rx.text(
  162. (VarOperationState.float_var1 & VarOperationState.int_var2).to_string(),
  163. id="float_and_int",
  164. ),
  165. rx.text(
  166. (VarOperationState.float_var1 | VarOperationState.int_var2).to_string(),
  167. id="float_or_int",
  168. ),
  169. # INT, DICT
  170. rx.text(
  171. (VarOperationState.int_var1 | VarOperationState.dict1).to_string(),
  172. id="int_or_dict",
  173. ),
  174. rx.text(
  175. (VarOperationState.int_var1 & VarOperationState.dict1).to_string(),
  176. id="int_and_dict",
  177. ),
  178. rx.text(
  179. (VarOperationState.int_var1 == VarOperationState.dict1).to_string(),
  180. id="int_eq_dict",
  181. ),
  182. rx.text(
  183. (VarOperationState.int_var1 != VarOperationState.dict1).to_string(),
  184. id="int_neq_dict",
  185. ),
  186. # FLOAT FLOAT
  187. rx.text(
  188. VarOperationState.float_var1 + VarOperationState.float_var2,
  189. id="float_add_float",
  190. ),
  191. rx.text(
  192. VarOperationState.float_var1 * VarOperationState.float_var2,
  193. id="float_mult_float",
  194. ),
  195. rx.text(
  196. VarOperationState.float_var1 - VarOperationState.float_var2,
  197. id="float_sub_float",
  198. ),
  199. rx.text(
  200. VarOperationState.float_var1**VarOperationState.float_var2,
  201. id="float_exp_float",
  202. ),
  203. rx.text(
  204. VarOperationState.float_var1 / VarOperationState.float_var2,
  205. id="float_div_float",
  206. ),
  207. rx.text(
  208. VarOperationState.float_var1 // VarOperationState.float_var2,
  209. id="float_floor_float",
  210. ),
  211. rx.text(
  212. VarOperationState.float_var1 % VarOperationState.float_var2,
  213. id="float_mod_float",
  214. ),
  215. rx.text(
  216. (
  217. VarOperationState.float_var1 > VarOperationState.float_var2
  218. ).to_string(),
  219. id="float_gt_float",
  220. ),
  221. rx.text(
  222. (
  223. VarOperationState.float_var1 < VarOperationState.float_var2
  224. ).to_string(),
  225. id="float_lt_float",
  226. ),
  227. rx.text(
  228. (
  229. VarOperationState.float_var1 >= VarOperationState.float_var2
  230. ).to_string(),
  231. id="float_gte_float",
  232. ),
  233. rx.text(
  234. (
  235. VarOperationState.float_var1 <= VarOperationState.float_var2
  236. ).to_string(),
  237. id="float_lte_float",
  238. ),
  239. rx.text(
  240. (
  241. VarOperationState.float_var1 == VarOperationState.float_var2
  242. ).to_string(),
  243. id="float_eq_float",
  244. ),
  245. rx.text(
  246. (
  247. VarOperationState.float_var1 != VarOperationState.float_var2
  248. ).to_string(),
  249. id="float_neq_float",
  250. ),
  251. rx.text(
  252. (
  253. VarOperationState.float_var1 & VarOperationState.float_var2
  254. ).to_string(),
  255. id="float_and_float",
  256. ),
  257. rx.text(
  258. (
  259. VarOperationState.float_var1 | VarOperationState.float_var2
  260. ).to_string(),
  261. id="float_or_float",
  262. ),
  263. # FLOAT STR
  264. rx.text(
  265. VarOperationState.float_var1 | VarOperationState.str_var1,
  266. id="float_or_str",
  267. ),
  268. rx.text(
  269. VarOperationState.float_var1 & VarOperationState.str_var1,
  270. id="float_and_str",
  271. ),
  272. rx.text(
  273. (
  274. VarOperationState.float_var1 == VarOperationState.str_var1
  275. ).to_string(),
  276. id="float_eq_str",
  277. ),
  278. rx.text(
  279. (
  280. VarOperationState.float_var1 != VarOperationState.str_var1
  281. ).to_string(),
  282. id="float_neq_str",
  283. ),
  284. # FLOAT LIST
  285. rx.text(
  286. (VarOperationState.float_var1 | VarOperationState.list1).to_string(),
  287. id="float_or_list",
  288. ),
  289. rx.text(
  290. (VarOperationState.float_var1 & VarOperationState.list1).to_string(),
  291. id="float_and_list",
  292. ),
  293. rx.text(
  294. (VarOperationState.float_var1 == VarOperationState.list1).to_string(),
  295. id="float_eq_list",
  296. ),
  297. rx.text(
  298. (VarOperationState.float_var1 != VarOperationState.list1).to_string(),
  299. id="float_neq_list",
  300. ),
  301. # FLOAT DICT
  302. rx.text(
  303. (VarOperationState.float_var1 | VarOperationState.dict1).to_string(),
  304. id="float_or_dict",
  305. ),
  306. rx.text(
  307. (VarOperationState.float_var1 & VarOperationState.dict1).to_string(),
  308. id="float_and_dict",
  309. ),
  310. rx.text(
  311. (VarOperationState.float_var1 == VarOperationState.dict1).to_string(),
  312. id="float_eq_dict",
  313. ),
  314. rx.text(
  315. (VarOperationState.float_var1 != VarOperationState.dict1).to_string(),
  316. id="float_neq_dict",
  317. ),
  318. # STR STR
  319. rx.text(
  320. VarOperationState.str_var1 + VarOperationState.str_var2,
  321. id="str_add_str",
  322. ),
  323. rx.text(
  324. (VarOperationState.str_var1 > VarOperationState.str_var2).to_string(),
  325. id="str_gt_str",
  326. ),
  327. rx.text(
  328. (VarOperationState.str_var1 < VarOperationState.str_var2).to_string(),
  329. id="str_lt_str",
  330. ),
  331. rx.text(
  332. (VarOperationState.str_var1 >= VarOperationState.str_var2).to_string(),
  333. id="str_gte_str",
  334. ),
  335. rx.text(
  336. (VarOperationState.str_var1 <= VarOperationState.str_var2).to_string(),
  337. id="str_lte_str",
  338. ),
  339. rx.text(
  340. (
  341. VarOperationState.float_var1 == VarOperationState.float_var2
  342. ).to_string(),
  343. id="str_eq_str",
  344. ),
  345. rx.text(
  346. (
  347. VarOperationState.float_var1 != VarOperationState.float_var2
  348. ).to_string(),
  349. id="str_neq_str",
  350. ),
  351. rx.text(
  352. VarOperationState.str_var1.contains("fir").to_string(),
  353. id="str_contains",
  354. ),
  355. rx.text(
  356. VarOperationState.str_var1 | VarOperationState.str_var1, id="str_or_str"
  357. ),
  358. rx.text(
  359. VarOperationState.str_var1 & VarOperationState.str_var2,
  360. id="str_and_str",
  361. ),
  362. # STR, INT
  363. rx.text(
  364. VarOperationState.str_var1 * VarOperationState.int_var2,
  365. id="str_mult_int",
  366. ),
  367. rx.text(
  368. VarOperationState.str_var1 & VarOperationState.int_var2,
  369. id="str_and_int",
  370. ),
  371. rx.text(
  372. VarOperationState.str_var1 | VarOperationState.int_var2, id="str_or_int"
  373. ),
  374. rx.text(
  375. (VarOperationState.str_var1 == VarOperationState.int_var1).to_string(),
  376. id="str_eq_int",
  377. ),
  378. rx.text(
  379. (VarOperationState.str_var1 != VarOperationState.int_var1).to_string(),
  380. id="str_neq_int",
  381. ),
  382. # STR, LIST
  383. rx.text(
  384. VarOperationState.str_var1 | VarOperationState.list1, id="str_or_list"
  385. ),
  386. rx.text(
  387. (VarOperationState.str_var1 & VarOperationState.list1).to_string(),
  388. id="str_and_list",
  389. ),
  390. rx.text(
  391. (VarOperationState.str_var1 == VarOperationState.list1).to_string(),
  392. id="str_eq_list",
  393. ),
  394. rx.text(
  395. (VarOperationState.str_var1 != VarOperationState.list1).to_string(),
  396. id="str_neq_list",
  397. ),
  398. # STR, DICT
  399. rx.text(
  400. VarOperationState.str_var1 | VarOperationState.dict1, id="str_or_dict"
  401. ),
  402. rx.text(
  403. (VarOperationState.str_var1 & VarOperationState.dict1).to_string(),
  404. id="str_and_dict",
  405. ),
  406. rx.text(
  407. (VarOperationState.str_var1 == VarOperationState.dict1).to_string(),
  408. id="str_eq_dict",
  409. ),
  410. rx.text(
  411. (VarOperationState.str_var1 != VarOperationState.dict1).to_string(),
  412. id="str_neq_dict",
  413. ),
  414. # LIST, LIST
  415. rx.text(
  416. (VarOperationState.list1 + VarOperationState.list2).to_string(),
  417. id="list_add_list",
  418. ),
  419. rx.text(
  420. (VarOperationState.list1 & VarOperationState.list2).to_string(),
  421. id="list_and_list",
  422. ),
  423. rx.text(
  424. (VarOperationState.list1 | VarOperationState.list2).to_string(),
  425. id="list_or_list",
  426. ),
  427. rx.text(
  428. (VarOperationState.list1 > VarOperationState.list2).to_string(),
  429. id="list_gt_list",
  430. ),
  431. rx.text(
  432. (VarOperationState.list1 < VarOperationState.list2).to_string(),
  433. id="list_lt_list",
  434. ),
  435. rx.text(
  436. (VarOperationState.list1 >= VarOperationState.list2).to_string(),
  437. id="list_gte_list",
  438. ),
  439. rx.text(
  440. (VarOperationState.list1 <= VarOperationState.list2).to_string(),
  441. id="list_lte_list",
  442. ),
  443. rx.text(
  444. (VarOperationState.list1 == VarOperationState.list2).to_string(),
  445. id="list_eq_list",
  446. ),
  447. rx.text(
  448. (VarOperationState.list1 != VarOperationState.list2).to_string(),
  449. id="list_neq_list",
  450. ),
  451. rx.text(
  452. VarOperationState.list1.contains(1).to_string(), id="list_contains"
  453. ),
  454. rx.text(VarOperationState.list1.reverse().to_string(), id="list_reverse"),
  455. # LIST, INT
  456. rx.text(
  457. (VarOperationState.list1 * VarOperationState.int_var2).to_string(),
  458. id="list_mult_int",
  459. ),
  460. rx.text(
  461. (VarOperationState.list1 | VarOperationState.int_var1).to_string(),
  462. id="list_or_int",
  463. ),
  464. rx.text(
  465. (VarOperationState.list1 & VarOperationState.int_var1).to_string(),
  466. id="list_and_int",
  467. ),
  468. rx.text(
  469. (VarOperationState.list1 == VarOperationState.int_var1).to_string(),
  470. id="list_eq_int",
  471. ),
  472. rx.text(
  473. (VarOperationState.list1 != VarOperationState.int_var1).to_string(),
  474. id="list_neq_int",
  475. ),
  476. # LIST, DICT
  477. rx.text(
  478. (VarOperationState.list1 | VarOperationState.dict1).to_string(),
  479. id="list_or_dict",
  480. ),
  481. rx.text(
  482. (VarOperationState.list1 & VarOperationState.dict1).to_string(),
  483. id="list_and_dict",
  484. ),
  485. rx.text(
  486. (VarOperationState.list1 == VarOperationState.dict1).to_string(),
  487. id="list_eq_dict",
  488. ),
  489. rx.text(
  490. (VarOperationState.list1 != VarOperationState.dict1).to_string(),
  491. id="list_neq_dict",
  492. ),
  493. # DICT, DICT
  494. rx.text(
  495. (VarOperationState.dict1 | VarOperationState.dict2).to_string(),
  496. id="dict_or_dict",
  497. ),
  498. rx.text(
  499. (VarOperationState.dict1 & VarOperationState.dict2).to_string(),
  500. id="dict_and_dict",
  501. ),
  502. rx.text(
  503. (VarOperationState.dict1 == VarOperationState.dict2).to_string(),
  504. id="dict_eq_dict",
  505. ),
  506. rx.text(
  507. (VarOperationState.dict1 != VarOperationState.dict2).to_string(),
  508. id="dict_neq_dict",
  509. ),
  510. rx.text(
  511. VarOperationState.dict1.contains(1).to_string(), id="dict_contains"
  512. ),
  513. rx.text(VarOperationState.str_var3.lower(), id="str_lower"),
  514. rx.text(VarOperationState.str_var3.upper(), id="str_upper"),
  515. rx.text(VarOperationState.str_var4.split(" ").to_string(), id="str_split"),
  516. rx.text(VarOperationState.list3.join(""), id="list_join"),
  517. rx.text(VarOperationState.list3.join(","), id="list_join_comma"),
  518. # Index from an op var
  519. rx.text(
  520. VarOperationState.list3[VarOperationState.int_var1 % 3],
  521. id="list_index_mod",
  522. ),
  523. rx.html(
  524. VarOperationState.html_str,
  525. id="html_str",
  526. ),
  527. rx.highlight(
  528. "second",
  529. query=[VarOperationState.str_var2],
  530. ),
  531. rx.text(rx.Var.range(2, 5).join(","), id="list_join_range1"),
  532. rx.text(rx.Var.range(2, 10, 2).join(","), id="list_join_range2"),
  533. rx.text(rx.Var.range(5, 0, -1).join(","), id="list_join_range3"),
  534. rx.text(rx.Var.range(0, 3).join(","), id="list_join_range4"),
  535. rx.box(
  536. rx.foreach(
  537. rx.Var.range(0, 2), lambda x: rx.text(VarOperationState.list1[x])
  538. ),
  539. id="foreach_list_arg",
  540. ),
  541. rx.box(
  542. rx.foreach(
  543. rx.Var.range(0, 2),
  544. lambda x, ix: rx.text(VarOperationState.list1[ix]),
  545. ),
  546. id="foreach_list_ix",
  547. ),
  548. rx.box(
  549. rx.foreach(
  550. rx.Var.create_safe(list(range(0, 3))).to(list[int]),
  551. lambda x: rx.foreach(
  552. rx.Var.range(x),
  553. lambda y: rx.text(VarOperationState.list1[y]),
  554. ),
  555. ),
  556. id="foreach_list_nested",
  557. ),
  558. )
  559. @pytest.fixture(scope="session")
  560. def var_operations(tmp_path_factory) -> Generator[AppHarness, None, None]:
  561. """Start VarOperations app at tmp_path via AppHarness.
  562. Args:
  563. tmp_path_factory: pytest tmp_path_factory fixture
  564. Yields:
  565. running AppHarness instance
  566. """
  567. with AppHarness.create(
  568. root=tmp_path_factory.mktemp("var_operations"),
  569. app_source=VarOperations, # type: ignore
  570. ) as harness:
  571. assert harness.app_instance is not None, "app is not running"
  572. yield harness
  573. @pytest.fixture
  574. def driver(var_operations: AppHarness):
  575. """Get an instance of the browser open to the var operations app.
  576. Args:
  577. var_operations: harness for VarOperations app
  578. Yields:
  579. WebDriver instance.
  580. """
  581. driver = var_operations.frontend()
  582. try:
  583. token_input = driver.find_element(By.ID, "token")
  584. assert token_input
  585. # wait for the backend connection to send the token
  586. token = var_operations.poll_for_value(token_input)
  587. assert token is not None
  588. yield driver
  589. finally:
  590. driver.quit()
  591. def test_var_operations(driver, var_operations: AppHarness):
  592. """Test that the var operations produce the right results.
  593. Args:
  594. driver: selenium WebDriver open to the app
  595. var_operations: AppHarness for the var operations app
  596. """
  597. tests = [
  598. # int, int
  599. ("int_add_int", "15"),
  600. ("int_mult_int", "50"),
  601. ("int_sub_int", "5"),
  602. ("int_exp_int", "100000"),
  603. ("int_div_int", "2"),
  604. ("int_floor_int", "1"),
  605. ("int_mod_int", "0"),
  606. ("int_gt_int", "true"),
  607. ("int_lt_int", "false"),
  608. ("int_gte_int", "true"),
  609. ("int_lte_int", "false"),
  610. ("int_and_int", "5"),
  611. ("int_or_int", "10"),
  612. ("int_eq_int", "false"),
  613. ("int_neq_int", "true"),
  614. # int, float
  615. ("float_add_int", "15.5"),
  616. ("float_mult_int", "52.5"),
  617. ("float_sub_int", "5.5"),
  618. ("float_exp_int", "127628.15625"),
  619. ("float_div_int", "2.1"),
  620. ("float_floor_int", "1"),
  621. ("float_mod_int", "0.5"),
  622. ("float_gt_int", "true"),
  623. ("float_lt_int", "false"),
  624. ("float_gte_int", "true"),
  625. ("float_lte_int", "false"),
  626. ("float_eq_int", "false"),
  627. ("float_neq_int", "true"),
  628. ("float_and_int", "5"),
  629. ("float_or_int", "10.5"),
  630. # int, dict
  631. ("int_or_dict", "10"),
  632. ("int_and_dict", '{"1":2}'),
  633. ("int_eq_dict", "false"),
  634. ("int_neq_dict", "true"),
  635. # float, float
  636. ("float_add_float", "16"),
  637. ("float_mult_float", "57.75"),
  638. ("float_sub_float", "5"),
  639. ("float_exp_float", "413562.49323606625"),
  640. ("float_div_float", "1.9090909090909092"),
  641. ("float_floor_float", "1"),
  642. ("float_mod_float", "5"),
  643. ("float_gt_float", "true"),
  644. ("float_lt_float", "false"),
  645. ("float_gte_float", "true"),
  646. ("float_lte_float", "false"),
  647. ("float_eq_float", "false"),
  648. ("float_neq_float", "true"),
  649. ("float_and_float", "5.5"),
  650. ("float_or_float", "10.5"),
  651. # float, str
  652. ("float_or_str", "10.5"),
  653. ("float_and_str", "first"),
  654. ("float_eq_str", "false"),
  655. ("float_neq_str", "true"),
  656. # float, list
  657. ("float_or_list", "10.5"),
  658. ("float_and_list", "[1,2]"),
  659. ("float_eq_list", "false"),
  660. ("float_neq_list", "true"),
  661. # float, dict
  662. ("float_or_dict", "10.5"),
  663. ("float_and_dict", '{"1":2}'),
  664. ("float_eq_dict", "false"),
  665. ("float_neq_dict", "true"),
  666. # str, str
  667. ("str_add_str", "firstsecond"),
  668. ("str_gt_str", "false"),
  669. ("str_lt_str", "true"),
  670. ("str_gte_str", "false"),
  671. ("str_lte_str", "true"),
  672. ("str_eq_str", "false"),
  673. ("str_neq_str", "true"),
  674. ("str_and_str", "second"),
  675. ("str_or_str", "first"),
  676. ("str_contains", "true"),
  677. ("str_lower", "third"),
  678. ("str_upper", "THIRD"),
  679. ("str_split", '["a","long","string"]'),
  680. # str, int
  681. ("str_mult_int", "firstfirstfirstfirstfirst"),
  682. ("str_and_int", "5"),
  683. ("str_or_int", "first"),
  684. ("str_eq_int", "false"),
  685. ("str_neq_int", "true"),
  686. # str, list
  687. ("str_and_list", "[1,2]"),
  688. ("str_or_list", "first"),
  689. ("str_eq_list", "false"),
  690. ("str_neq_list", "true"),
  691. # str, dict
  692. ("str_or_dict", "first"),
  693. ("str_and_dict", '{"1":2}'),
  694. ("str_eq_dict", "false"),
  695. ("str_neq_dict", "true"),
  696. # list, list
  697. ("list_add_list", "[1,2,3,4]"),
  698. ("list_gt_list", "false"),
  699. ("list_lt_list", "true"),
  700. ("list_gte_list", "false"),
  701. ("list_lte_list", "true"),
  702. ("list_eq_list", "false"),
  703. ("list_neq_list", "true"),
  704. ("list_and_list", "[3,4]"),
  705. ("list_or_list", "[1,2]"),
  706. ("list_contains", "true"),
  707. ("list_reverse", "[2,1]"),
  708. ("list_join", "firstsecondthird"),
  709. ("list_join_comma", "first,second,third"),
  710. ("list_join_range1", "2,3,4"),
  711. ("list_join_range2", "2,4,6,8"),
  712. ("list_join_range3", "5,4,3,2,1"),
  713. ("list_join_range4", "0,1,2"),
  714. # list, int
  715. ("list_mult_int", "[1,2,1,2,1,2,1,2,1,2]"),
  716. ("list_or_int", "[1,2]"),
  717. ("list_and_int", "10"),
  718. ("list_eq_int", "false"),
  719. ("list_neq_int", "true"),
  720. # list, dict
  721. ("list_and_dict", '{"1":2}'),
  722. ("list_or_dict", "[1,2]"),
  723. ("list_eq_dict", "false"),
  724. ("list_neq_dict", "true"),
  725. # dict, dict
  726. ("dict_or_dict", '{"1":2}'),
  727. ("dict_and_dict", '{"3":4}'),
  728. ("dict_eq_dict", "false"),
  729. ("dict_neq_dict", "true"),
  730. ("dict_contains", "true"),
  731. # index from an op var
  732. ("list_index_mod", "second"),
  733. # html component with var
  734. ("html_str", "hello"),
  735. # index into list with foreach
  736. ("foreach_list_arg", "1\n2"),
  737. ("foreach_list_ix", "1\n2"),
  738. ("foreach_list_nested", "1\n1\n2"),
  739. ]
  740. for tag, expected in tests:
  741. assert driver.find_element(By.ID, tag).text == expected
  742. # Highlight component with var query (does not plumb ID)
  743. assert driver.find_element(By.TAG_NAME, "mark").text == "second"