test_victory_data.py 4.3 KB

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