Skip to content

Commit ccb9e9a

Browse files
tests
1 parent a674c86 commit ccb9e9a

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

tests/unit_tests/helpers/test_responses.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import pandas as pd
77
from PIL import Image
88

9+
import pytest
10+
911
from pandasai.core.response import (
1012
ChartResponse,
1113
DataFrameResponse,
@@ -57,12 +59,23 @@ def test_parse_valid_plot(self):
5759
self.assertEqual(response.type, "chart")
5860

5961
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)
6679

6780
def test_plot_img_show_triggered(self):
6881
result = {

0 commit comments

Comments
 (0)