14
14
EntryPoint ,
15
15
MetadataPathFinder ,
16
16
PackageNotFoundError ,
17
+ distribution ,
17
18
distributions ,
18
19
entry_points ,
19
20
metadata ,
@@ -87,15 +88,17 @@ def pkg_with_dashes(site_dir):
87
88
metadata = metadata_dir / 'METADATA'
88
89
with metadata .open ('w' , encoding = 'utf-8' ) as strm :
89
90
strm .write ('Version: 1.0\n ' )
90
- return 'my-pkg'
91
+ return 'my-pkg' , 'my_pkg'
91
92
92
93
def test_dashes_in_dist_name_found_as_underscores (self ):
93
94
"""
94
95
For a package with a dash in the name, the dist-info metadata
95
96
uses underscores in the name. Ensure the metadata loads.
96
97
"""
97
- pkg_name = self .pkg_with_dashes (self .site_dir )
98
- assert version (pkg_name ) == '1.0'
98
+ pkg_name , norm_pkg_name = self .pkg_with_dashes (self .site_dir )
99
+ dist = distribution (pkg_name )
100
+ assert dist ._normalized_name == norm_pkg_name
101
+ assert dist .version == '1.0'
99
102
100
103
@staticmethod
101
104
def pkg_with_mixed_case (site_dir ):
@@ -108,16 +111,40 @@ def pkg_with_mixed_case(site_dir):
108
111
metadata = metadata_dir / 'METADATA'
109
112
with metadata .open ('w' , encoding = 'utf-8' ) as strm :
110
113
strm .write ('Version: 1.0\n ' )
111
- return 'CherryPy '
114
+ return 'CheRRypY' , 'cherrypy '
112
115
113
116
def test_dist_name_found_as_any_case (self ):
114
117
"""
115
118
Ensure the metadata loads when queried with any case.
116
119
"""
117
- pkg_name = self .pkg_with_mixed_case (self .site_dir )
118
- assert version (pkg_name ) == '1.0'
119
- assert version (pkg_name .lower ()) == '1.0'
120
- assert version (pkg_name .upper ()) == '1.0'
120
+ pkg_name , norm_pkg_name = self .pkg_with_mixed_case (self .site_dir )
121
+ for name_variant in (pkg_name , pkg_name .lower (), pkg_name .upper ()):
122
+ dist = distribution (name_variant )
123
+ assert dist ._normalized_name == norm_pkg_name
124
+ assert dist .version == '1.0'
125
+
126
+ @staticmethod
127
+ def pkg_with_replaced_chars (site_dir ):
128
+ """
129
+ Create minimal metadata for a package with some
130
+ characters replaced by PEP 503 normalization
131
+ in the name.
132
+ """
133
+ metadata_dir = site_dir / 'zope..inter_face-4.2.dist-info'
134
+ metadata_dir .mkdir ()
135
+ metadata = metadata_dir / 'METADATA'
136
+ with metadata .open ('w' , encoding = 'utf-8' ) as strm :
137
+ strm .write ('Version: 4.2\n ' )
138
+ return 'zope-inter._FACE' , 'zope_inter_face'
139
+
140
+ def test_dist_name_pep503_normalization (self ):
141
+ """
142
+ Ensure the distribution name is properly normalized.
143
+ """
144
+ pkg_name , norm_pkg_name = self .pkg_with_replaced_chars (self .site_dir )
145
+ dist = distribution (pkg_name )
146
+ assert dist ._normalized_name == norm_pkg_name
147
+ assert dist .version == '4.2'
121
148
122
149
123
150
class NonASCIITests (fixtures .OnSysPath , fixtures .SiteDir , unittest .TestCase ):
0 commit comments