test_victory_data.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. from typing import List, Set, Type
  2. import pytest
  3. from pynecone.components.component import Component, CustomComponent, ImportDict
  4. from pynecone.components.layout.box import Box
  5. from pynecone.event import EVENT_TRIGGERS, EventHandler
  6. from pynecone.state import State
  7. from pynecone.style import Style
  8. from pynecone.var import Var
  9. from pynecone import data
  10. x_num = [1, 2, 3, 4, 5]
  11. x_str = ["Cats", "Dogs", "Birds", "Fish", "Reptiles"]
  12. y = [1, 2, 3, 4, 10]
  13. y1 = [5, 12, 4, 6, 1]
  14. y2 = [
  15. [1, 5, 7, 4, 10, 14],
  16. [1, 2, 3, 4, 10],
  17. [1, 2, 3, 4, 5],
  18. [1, 7, 3, 14, 10],
  19. [1, 2, 6, 4, 10],
  20. ]
  21. amount = [1, 5, 3, 14, 1]
  22. def test_line():
  23. output = data(graph="line", x=x_num, y=y)
  24. expected = [
  25. {"x": 1, "y": 1},
  26. {"x": 2, "y": 2},
  27. {"x": 3, "y": 3},
  28. {"x": 4, "y": 4},
  29. {"x": 5, "y": 10},
  30. ]
  31. assert output == expected
  32. def test_scatter():
  33. output = data(graph="scatter", x=x_num, y=y)
  34. expected = [
  35. {"x": 1, "y": 1},
  36. {"x": 2, "y": 2},
  37. {"x": 3, "y": 3},
  38. {"x": 4, "y": 4},
  39. {"x": 5, "y": 10},
  40. ]
  41. assert output == expected
  42. def test_area():
  43. output = data(graph="area", x=x_num, y=y)
  44. expected = [
  45. {"x": 1, "y": 1},
  46. {"x": 2, "y": 2},
  47. {"x": 3, "y": 3},
  48. {"x": 4, "y": 4},
  49. {"x": 5, "y": 10},
  50. ]
  51. assert output == expected
  52. def test_bar():
  53. output = data(graph="bar", x=x_str, y=y)
  54. expected = [
  55. {"x": "Cats", "y": 1},
  56. {"x": "Dogs", "y": 2},
  57. {"x": "Birds", "y": 3},
  58. {"x": "Fish", "y": 4},
  59. {"x": "Reptiles", "y": 10},
  60. ]
  61. assert output == expected
  62. def test_box_plot():
  63. output = data(graph="box_plot", x=x_num, y=y2)
  64. expected = [
  65. {"x": 1, "y": [1, 5, 7, 4, 10, 14]},
  66. {"x": 2, "y": [1, 2, 3, 4, 10]},
  67. {"x": 3, "y": [1, 2, 3, 4, 5]},
  68. {"x": 4, "y": [1, 7, 3, 14, 10]},
  69. {"x": 5, "y": [1, 2, 6, 4, 10]},
  70. ]
  71. output_specified = data(
  72. graph="box_plot", x=x_num, min_=y1, max_=y1, median=y1, q1=y1, q3=y1
  73. )
  74. expected_specified = [
  75. {"x": 1, "min": 5, "max": 5, "median": 5, "q1": 5, "q3": 5},
  76. {"x": 2, "min": 12, "max": 12, "median": 12, "q1": 12, "q3": 12},
  77. {"x": 3, "min": 4, "max": 4, "median": 4, "q1": 4, "q3": 4},
  78. {"x": 4, "min": 6, "max": 6, "median": 6, "q1": 6, "q3": 6},
  79. {"x": 5, "min": 1, "max": 1, "median": 1, "q1": 1, "q3": 1},
  80. ]
  81. assert output == expected
  82. assert output_specified == expected_specified
  83. def test_histogram():
  84. output = data(graph="histogram", x=x_num)
  85. output2 = data(graph="histogram", x=y1)
  86. expected = [{"x": 1}, {"x": 2}, {"x": 3}, {"x": 4}, {"x": 5}]
  87. expected2 = [{"x": 5}, {"x": 12}, {"x": 4}, {"x": 6}, {"x": 1}]
  88. assert output == expected
  89. assert output2 == expected2
  90. def test_pie():
  91. output = data(graph="pie", x=x_str, y=amount)
  92. expected = [
  93. {"x": "Cats", "y": 1},
  94. {"x": "Dogs", "y": 5},
  95. {"x": "Birds", "y": 3},
  96. {"x": "Fish", "y": 14},
  97. {"x": "Reptiles", "y": 1},
  98. ]
  99. output_labels = data(graph="pie", x=x_str, y=amount, label=x_str)
  100. expected_labels = [
  101. {"x": "Cats", "y": 1, "label": "Cats"},
  102. {"x": "Dogs", "y": 5, "label": "Dogs"},
  103. {"x": "Birds", "y": 3, "label": "Birds"},
  104. {"x": "Fish", "y": 14, "label": "Fish"},
  105. {"x": "Reptiles", "y": 1, "label": "Reptiles"},
  106. ]
  107. assert output == expected
  108. assert output_labels == expected_labels
  109. def test_voronoi():
  110. output = data(graph="voronoi", x=x_num, y=y)
  111. expected = [
  112. {"x": 1, "y": 1},
  113. {"x": 2, "y": 2},
  114. {"x": 3, "y": 3},
  115. {"x": 4, "y": 4},
  116. {"x": 5, "y": 10},
  117. ]
  118. assert output == expected
  119. def test_candlestick():
  120. output = data(graph="candlestick", x=x_num, open=y1, high=y1, low=y1, close=y1)
  121. expected = [
  122. {"x": 1, "open": 5, "high": 5, "low": 5, "close": 5},
  123. {"x": 2, "open": 12, "high": 12, "low": 12, "close": 12},
  124. {"x": 3, "open": 4, "high": 4, "low": 4, "close": 4},
  125. {"x": 4, "open": 6, "high": 6, "low": 6, "close": 6},
  126. {"x": 5, "open": 1, "high": 1, "low": 1, "close": 1},
  127. ]
  128. assert output == expected
  129. def test_errorbar():
  130. output = data(graph="error_bar", x=x_num, y=y1, error_y=y1, error_x=y1)
  131. expected = [
  132. {"x": 1, "y": 5, "error_y": 5, "error_x": 5},
  133. {"x": 2, "y": 12, "error_y": 12, "error_x": 12},
  134. {"x": 3, "y": 4, "error_y": 4, "error_x": 4},
  135. {"x": 4, "y": 6, "error_y": 6, "error_x": 6},
  136. {"x": 5, "y": 1, "error_y": 1, "error_x": 1},
  137. ]
  138. assert output == expected