11"""Unit tests for case-insensitive username lookup in org-data.json."""
22
33import json
4+ import os
5+ import tempfile
46import unittest
57from pathlib import Path
68from unittest .mock import MagicMock , patch
@@ -104,6 +106,17 @@ def test_values(self):
104106 values = list (self .case_insensitive_dict .values ())
105107 self .assertEqual (len (values ), 4 )
106108
109+ def test_duplicate_case_insensitive_keys (self ):
110+ """Test that ValueError is raised for duplicate case-insensitive keys."""
111+ duplicate_data = {
112+ "alice" : {"manager" : "bob" },
113+ "Alice" : {"manager" : "charlie" }, # Duplicate!
114+ }
115+ with self .assertRaises (ValueError ) as context :
116+ CaseInsensitiveDict (duplicate_data )
117+ self .assertIn ("Duplicate case-insensitive keys found" , str (context .exception ))
118+ self .assertIn ("alice" , str (context .exception ).lower ())
119+
107120
108121class TestCaseInsensitiveLookupIntegration (unittest .TestCase ):
109122 """Integration tests for case-insensitive username lookup in measure_innersource."""
@@ -113,7 +126,11 @@ class TestCaseInsensitiveLookupIntegration(unittest.TestCase):
113126 @patch ("measure_innersource.get_env_vars" )
114127 @patch ("measure_innersource.write_to_markdown" )
115128 def test_username_lookup_case_insensitive (
116- self , mock_write , mock_get_env_vars , mock_auth , mock_evaluate # pylint: disable=unused-argument
129+ self ,
130+ mock_write ,
131+ mock_get_env_vars ,
132+ mock_auth ,
133+ mock_evaluate , # pylint: disable=unused-argument
117134 ):
118135 """Test that username lookups in org-data.json are case-insensitive."""
119136 # Create a temporary org-data.json file with lowercase username
@@ -160,16 +177,12 @@ def test_username_lookup_case_insensitive(
160177 mock_repo .issues .return_value = iter ([])
161178
162179 # Create temp directory for org-data.json
163- import tempfile
164-
165180 with tempfile .TemporaryDirectory () as tmpdir :
166181 org_data_path = Path (tmpdir ) / "org-data.json"
167182 with open (org_data_path , "w" , encoding = "utf-8" ) as f :
168183 json .dump (org_data , f )
169184
170185 # Change to temp directory and run test
171- import os
172-
173186 original_dir = os .getcwd ()
174187 try :
175188 os .chdir (tmpdir )
0 commit comments