@@ -151,16 +151,23 @@ def test_m2o_map_success() -> None:
151151
152152def test_m2m_multi_column () -> None :
153153 """Tests the m2m mapper in multi-column mode."""
154+ # With the new m2m logic, this should split both "tags" and "other_tags"
155+ # "tags" ("T1, T2") should become "tag_prefix.T1", "tag_prefix.T2"
156+ # "other_tags" ("T3") should become "tag_prefix.T3"
157+ # Joined by comma: "tag_prefix.T1,tag_prefix.T2,tag_prefix.T3"
154158 mapper_func = mapper .m2m ("tag_prefix" , "tags" , "other_tags" )
155159 result = mapper_func (LINE_M2M , {})
156- assert result == "tag_prefix.T1, T2,tag_prefix.T3"
160+ assert result == "tag_prefix.T1,tag_prefix. T2,tag_prefix.T3"
157161
158162
159163def test_m2m_multi_column_with_missing_field () -> None :
160164 """Tests the m2m mapper in multi-column mode with a non-existent field."""
165+ # "tags" ("T1, T2") should become "tag_prefix.T1", "tag_prefix.T2"
166+ # "non_existent_field" will be empty/None
167+ # Joined by comma: "tag_prefix.T1,tag_prefix.T2"
161168 mapper_func = mapper .m2m ("tag_prefix" , "tags" , "non_existent_field" )
162169 result = mapper_func (LINE_M2M , {})
163- assert result == "tag_prefix.T1, T2"
170+ assert result == "tag_prefix.T1,tag_prefix. T2"
164171
165172
166173def test_m2m_multi_column_with_empty_value () -> None :
@@ -172,10 +179,28 @@ def test_m2m_multi_column_with_empty_value() -> None:
172179
173180def test_m2m_single_empty_field () -> None :
174181 """Tests the m2m mapper in single-column mode with an empty field."""
182+ # "empty_tags" is "", so it should return an empty string.
175183 mapper_func = mapper .m2m ("tag_prefix" , "empty_tags" , sep = "," )
176184 assert mapper_func (LINE_M2M , {}) == ""
177185
178186
187+ # Add a specific test for m2m single column with a comma-separated value
188+ def test_m2m_single_column_splits_value () -> None :
189+ """Tests that m2m in single-column mode correctly splits the field value."""
190+ line = {"products" : "PROD1, PROD2,PROD3" }
191+ mapper_func = mapper .m2m ("prod_prefix" , "products" , sep = "," )
192+ assert (
193+ mapper_func (line , {}) == "prod_prefix.PROD1,prod_prefix.PROD2,prod_prefix.PROD3"
194+ )
195+
196+
197+ def test_m2m_single_column_splits_value_with_custom_sep () -> None :
198+ """Tests that m2m in single-column mode correctly splits with custom separator."""
199+ line = {"items" : "ITEM-A; ITEM-B" }
200+ mapper_func = mapper .m2m ("item_prefix" , "items" , sep = ";" )
201+ assert mapper_func (line , {}) == "item_prefix.ITEM-A,item_prefix.ITEM-B"
202+
203+
179204def test_m2m_map_with_concat () -> None :
180205 """Tests m2m_map wrapping another mapper."""
181206 concat_mapper = mapper .concat ("," , "tags" , "other_tags" )
0 commit comments