@@ -555,3 +555,89 @@ def test_normalize_with_mapping_parameter(self):
555555 "a" ,
556556 "b" ,
557557 ), f"Expected normalized.value to be ('a', 'b'), but got { normalized .value !r} "
558+
559+
560+ class TestContextFieldIsResource :
561+ """Test ContextField is_resource method."""
562+
563+ @pytest .mark .parametrize (
564+ "value,expected" ,
565+ [
566+ # String values that should return True (resource categories)
567+ ("resource" , True ),
568+ ("resources" , True ),
569+ ("natural resource" , True ),
570+ ("natural resources" , True ),
571+ ("land use" , True ),
572+ ("economic" , True ),
573+ ("social" , True ),
574+ ("raw materials" , True ),
575+ ("raw" , True ),
576+ # Case insensitivity
577+ ("RESOURCE" , True ),
578+ ("Natural Resource" , True ),
579+ # Substring matches
580+ ("water resource extraction" , True ),
581+ ("natural resource extraction" , True ),
582+ ("economic activity" , True ),
583+ ("social aspect" , True ),
584+ # Slash-separated strings with resource
585+ ("resource/air" , True ),
586+ # String values that should return False
587+ ("emission" , False ),
588+ ("air" , False ),
589+ ("water" , False ),
590+ ("" , False ),
591+ ("emission/air" , False ),
592+ ],
593+ )
594+ def test_is_resource_with_string (self , value , expected ):
595+ """Test is_resource with string values."""
596+ c = ContextField (value )
597+ assert (
598+ c .is_resource () is expected
599+ ), f"Expected is_resource() to be { expected } for { value !r} , but got { c .is_resource ()} "
600+
601+ @pytest .mark .parametrize (
602+ "value,expected" ,
603+ [
604+ # List values that should return True
605+ (["resource" ], True ),
606+ (["resources" ], True ),
607+ (["raw" ], True ),
608+ (["land use" ], True ),
609+ (["economic" ], True ),
610+ (["social" ], True ),
611+ (["raw materials" ], True ),
612+ (["RESOURCE" ], True ), # Case insensitive
613+ (["emission" , "resource" , "air" ], True ), # Multiple elements, one resource
614+ # List values that should return False
615+ (["emission" , "air" , "water" ], False ),
616+ ([], False ),
617+ ],
618+ )
619+ def test_is_resource_with_list (self , value , expected ):
620+ """Test is_resource with list values."""
621+ c = ContextField (value )
622+ assert (
623+ c .is_resource () is expected
624+ ), f"Expected is_resource() to be { expected } for { value !r} , but got { c .is_resource ()} "
625+
626+ @pytest .mark .parametrize (
627+ "value,expected" ,
628+ [
629+ # Tuple values that should return True
630+ (("resource" ,), True ),
631+ (("raw" ,), True ),
632+ (("emission" , "resource" , "air" ), True ), # Multiple elements, one resource
633+ # Tuple values that should return False
634+ (("emission" , "air" ), False ),
635+ ((), False ),
636+ ],
637+ )
638+ def test_is_resource_with_tuple (self , value , expected ):
639+ """Test is_resource with tuple values."""
640+ c = ContextField (value )
641+ assert (
642+ c .is_resource () is expected
643+ ), f"Expected is_resource() to be { expected } for { value !r} , but got { c .is_resource ()} "
0 commit comments