11import re
22import textwrap
3- import unittest
3+
4+ try :
5+ import unittest2 as unittest
6+ except ImportError :
7+ import unittest
48
59from . import fixtures
610from importlib_metadata import (
2226class APITests (
2327 fixtures .EggInfoPkg ,
2428 fixtures .DistInfoPkg ,
29+ fixtures .DistInfoPkgWithDot ,
2530 fixtures .EggInfoFile ,
2631 unittest .TestCase ):
2732
@@ -41,6 +46,12 @@ def test_for_name_does_not_exist(self):
4146 with self .assertRaises (PackageNotFoundError ):
4247 distribution ('does-not-exist' )
4348
49+ def test_name_normalization (self ):
50+ names = 'pkg.dot' , 'pkg_dot' , 'pkg-dot' , 'pkg..dot' , 'Pkg.Dot'
51+ for name in names :
52+ with self .subTest (name ):
53+ assert distribution (name ).metadata ['Name' ] == 'pkg.dot'
54+
4455 def test_for_top_level (self ):
4556 self .assertEqual (
4657 distribution ('egginfo-pkg' ).read_text ('top_level.txt' ).strip (),
@@ -156,6 +167,14 @@ def test_more_complex_deps_requires_text(self):
156167 assert deps == expected
157168
158169
170+ class LegacyDots (fixtures .DistInfoPkgWithDotLegacy , unittest .TestCase ):
171+ def test_name_normalization (self ):
172+ names = 'pkg.dot' , 'pkg_dot' , 'pkg-dot' , 'pkg..dot' , 'Pkg.Dot'
173+ for name in names :
174+ with self .subTest (name ):
175+ assert distribution (name ).metadata ['Name' ] == 'pkg.dot'
176+
177+
159178class OffSysPathTests (fixtures .DistInfoPkgOffPath , unittest .TestCase ):
160179 def test_find_distributions_specified_path (self ):
161180 dists = Distribution .discover (path = [str (self .site_dir )])
0 commit comments