33import numpy as np
44from io import StringIO
55from csv_importer .parsers import polars_df_to_bob , update_bob_from_polars_df
6- import unittest
76import warnings
87import string
9-
8+ import bpy
9+ from unittest .mock import patch
1010
1111@pytest .fixture
1212def test_df ():
@@ -62,6 +62,7 @@ def test_polars_df_to_bob_with_datatypes():
6262 # bob.named_attribute("StringVal")
6363
6464
65+
6566def test_string_limit_functionality ():
6667 """Test string limit functionality without using mocks."""
6768 # Create test data with specific string values and a null
@@ -87,19 +88,22 @@ def test_string_limit_functionality():
8788 assert np .array_equal (strings_attr , expected_encoding )
8889
8990 # Test with very low string limit (should skip string column)
91+ # Use a mocked warning instead of popup_menu which causes segfault
9092 with warnings .catch_warnings (record = True ) as w :
9193 warnings .simplefilter ("always" )
9294
93- # Create a new bob with a low string limit
94- limited_bob = polars_df_to_bob (df , name = "LimitedStringTest" , string_limit = 2 )
95+ # Use patch to avoid the read-only attribute error
96+ with patch .object (bpy .context .window_manager .__class__ , 'popup_menu' , create = True , new = lambda * args , ** kwargs : None ):
97+ # Create a new bob with a low string limit
98+ limited_bob = polars_df_to_bob (df , name = "LimitedStringTest" , string_limit = 2 )
99+
100+ # Check that a warning was raised
101+ assert any ("exceeds the limit" in str (warning .message ) for warning in w )
95102
96- # Check that a warning was raised
97- assert any ("exceeds the limit" in str (warning .message ) for warning in w )
98-
99- # Verify the numeric column was processed
100- numbers_attr = limited_bob .named_attribute ("numbers" )
101- assert np .array_equal (numbers_attr , np .arange (len (test_strings )))
102-
103- # Verify the string column was skipped (should raise an AttributeError)
104- with pytest .raises (AttributeError ):
105- limited_bob .named_attribute ("strings" )
103+ # Verify the numeric column was processed
104+ numbers_attr = limited_bob .named_attribute ("numbers" )
105+ assert np .array_equal (numbers_attr , np .arange (len (test_strings )))
106+
107+ # Verify the string column was skipped (should raise an AttributeError)
108+ with pytest .raises (AttributeError ):
109+ limited_bob .named_attribute ("strings" )
0 commit comments