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 (
1216class APITests (
1317 fixtures .EggInfoPkg ,
1418 fixtures .DistInfoPkg ,
19+ fixtures .DistInfoPkgWithDot ,
1520 fixtures .EggInfoFile ,
1621 unittest .TestCase ):
1722
@@ -31,6 +36,12 @@ def test_for_name_does_not_exist(self):
3136 with self .assertRaises (PackageNotFoundError ):
3237 distribution ('does-not-exist' )
3338
39+ def test_name_normalization (self ):
40+ names = 'pkg.dot' , 'pkg_dot' , 'pkg-dot' , 'pkg..dot' , 'Pkg.Dot'
41+ for name in names :
42+ with self .subTest (name ):
43+ assert distribution (name ).metadata ['Name' ] == 'pkg.dot'
44+
3445 def test_for_top_level (self ):
3546 self .assertEqual (
3647 distribution ('egginfo-pkg' ).read_text ('top_level.txt' ).strip (),
@@ -146,6 +157,14 @@ def test_more_complex_deps_requires_text(self):
146157 assert deps == expected
147158
148159
160+ class LegacyDots (fixtures .DistInfoPkgWithDotLegacy , unittest .TestCase ):
161+ def test_name_normalization (self ):
162+ names = 'pkg.dot' , 'pkg_dot' , 'pkg-dot' , 'pkg..dot' , 'Pkg.Dot'
163+ for name in names :
164+ with self .subTest (name ):
165+ assert distribution (name ).metadata ['Name' ] == 'pkg.dot'
166+
167+
149168class OffSysPathTests (fixtures .DistInfoPkgOffPath , unittest .TestCase ):
150169 def test_find_distributions_specified_path (self ):
151170 dists = Distribution .discover (path = [str (self .site_dir )])
0 commit comments