@@ -577,6 +577,88 @@ def test_similar_name(self, tmp_path):
577
577
with pytest .raises (ImportError , match = "foobar" ):
578
578
import_module ("foobar" )
579
579
580
+ def test_case_sensitivity (self , tmp_path ):
581
+ files = {
582
+ "foo" : {
583
+ "__init__.py" : "" ,
584
+ "lowercase.py" : "x = 1" ,
585
+ "bar" : {
586
+ "__init__.py" : "" ,
587
+ "lowercase.py" : "x = 2" ,
588
+ },
589
+ },
590
+ }
591
+ jaraco .path .build (files , prefix = tmp_path )
592
+ mapping = {
593
+ "foo" : str (tmp_path / "foo" ),
594
+ }
595
+ template = _finder_template (str (uuid4 ()), mapping , {})
596
+ with contexts .save_paths (), contexts .save_sys_modules ():
597
+ sys .modules .pop ("foo" , None )
598
+
599
+ self .install_finder (template )
600
+ with pytest .raises (ImportError , match = "\' FOO\' " ):
601
+ import_module ("FOO" )
602
+
603
+ with pytest .raises (ImportError , match = "\' foo\\ .LOWERCASE\' " ):
604
+ import_module ("foo.LOWERCASE" )
605
+
606
+ with pytest .raises (ImportError , match = "\' foo\\ .bar\\ .Lowercase\' " ):
607
+ import_module ("foo.bar.Lowercase" )
608
+
609
+ with pytest .raises (ImportError , match = "\' foo\\ .BAR\' " ):
610
+ import_module ("foo.BAR.lowercase" )
611
+
612
+ with pytest .raises (ImportError , match = "\' FOO\' " ):
613
+ import_module ("FOO.bar.lowercase" )
614
+
615
+ mod = import_module ("foo.lowercase" )
616
+ assert mod .x == 1
617
+
618
+ mod = import_module ("foo.bar.lowercase" )
619
+ assert mod .x == 2
620
+
621
+ def test_namespace_case_sensitivity (self , tmp_path ):
622
+ files = {
623
+ "pkg" : {
624
+ "__init__.py" : "a = 13" ,
625
+ "foo" : {
626
+ "__init__.py" : "b = 37" ,
627
+ "bar.py" : "c = 42" ,
628
+ },
629
+ },
630
+ }
631
+ jaraco .path .build (files , prefix = tmp_path )
632
+
633
+ mapping = {"ns.othername" : str (tmp_path / "pkg" )}
634
+ namespaces = {"ns" : []}
635
+
636
+ template = _finder_template (str (uuid4 ()), mapping , namespaces )
637
+ with contexts .save_paths (), contexts .save_sys_modules ():
638
+ for mod in ("ns" , "ns.othername" ):
639
+ sys .modules .pop (mod , None )
640
+
641
+ self .install_finder (template )
642
+ pkg = import_module ("ns.othername" )
643
+ expected = str ((tmp_path / "pkg" ).resolve ())
644
+ assert_path (pkg , expected )
645
+ assert pkg .a == 13
646
+
647
+ foo = import_module ("ns.othername.foo" )
648
+ assert foo .b == 37
649
+
650
+ bar = import_module ("ns.othername.foo.bar" )
651
+ assert bar .c == 42
652
+
653
+ with pytest .raises (ImportError , match = "\' NS\' " ):
654
+ import_module ("NS.othername.foo" )
655
+
656
+ with pytest .raises (ImportError , match = "\' ns\\ .othername\\ .FOO\\ '" ):
657
+ import_module ("ns.othername.FOO" )
658
+
659
+ with pytest .raises (ImportError , match = "\' ns\\ .othername\\ .foo\\ .BAR\\ '" ):
660
+ import_module ("ns.othername.foo.BAR" )
661
+
580
662
581
663
def test_pkg_roots (tmp_path ):
582
664
"""This test focus in getting a particular implementation detail right.
0 commit comments