|
6 | 6 | import pandas as pd |
7 | 7 | from PIL import Image |
8 | 8 |
|
| 9 | +import pytest |
| 10 | + |
9 | 11 | from pandasai.core.response import ( |
10 | 12 | ChartResponse, |
11 | 13 | DataFrameResponse, |
@@ -57,12 +59,23 @@ def test_parse_valid_plot(self): |
57 | 59 | self.assertEqual(response.type, "chart") |
58 | 60 |
|
59 | 61 | def test_parse_valid_interactive_plot(self): |
60 | | - result = {"type": "iplot", "value": "path/to/plot.json"} |
61 | | - response = self.response_parser.parse(result) |
62 | | - self.assertIsInstance(response, InteractiveChartResponse) |
63 | | - self.assertEqual(response.value, "path/to/plot.json") |
64 | | - self.assertEqual(response.last_code_executed, None) |
65 | | - self.assertEqual(response.type, "ichart") |
| 62 | + path = "path/to/interactive_plot.json" |
| 63 | + # mock os.path.exists to return True for the plot path |
| 64 | + with patch("os.path.exists", return_value=True) as mock_exists: |
| 65 | + result = {"type": "iplot", "value": path} |
| 66 | + response = self.response_parser.parse(result) |
| 67 | + self.assertIsInstance(response, InteractiveChartResponse) |
| 68 | + self.assertEqual(response.value, path) |
| 69 | + self.assertEqual(response.last_code_executed, None) |
| 70 | + self.assertEqual(response.type, "ichart") |
| 71 | + |
| 72 | + mock_exists.assert_called_once_with(path) |
| 73 | + |
| 74 | + def test_parse_invalid_interactive_plot_because_of_not_existing_file(self): |
| 75 | + path = "path/to/interactive_plot.json" |
| 76 | + with pytest.raises(ValueError): |
| 77 | + result = {"type": "iplot", "value": path} |
| 78 | + self.response_parser.parse(result) |
66 | 79 |
|
67 | 80 | def test_plot_img_show_triggered(self): |
68 | 81 | result = { |
|
0 commit comments