1import unittest 2 3from mypyc.namegen import ( 4 NameGenerator, exported_name, candidate_suffixes, make_module_translation_map 5) 6 7 8class TestNameGen(unittest.TestCase): 9 def test_candidate_suffixes(self) -> None: 10 assert candidate_suffixes('foo') == ['', 'foo.'] 11 assert candidate_suffixes('foo.bar') == ['', 'bar.', 'foo.bar.'] 12 13 def test_exported_name(self) -> None: 14 assert exported_name('foo') == 'foo' 15 assert exported_name('foo.bar') == 'foo___bar' 16 17 def test_make_module_translation_map(self) -> None: 18 assert make_module_translation_map( 19 ['foo', 'bar']) == {'foo': 'foo.', 'bar': 'bar.'} 20 assert make_module_translation_map( 21 ['foo.bar', 'foo.baz']) == {'foo.bar': 'bar.', 'foo.baz': 'baz.'} 22 assert make_module_translation_map( 23 ['zar', 'foo.bar', 'foo.baz']) == {'foo.bar': 'bar.', 24 'foo.baz': 'baz.', 25 'zar': 'zar.'} 26 assert make_module_translation_map( 27 ['foo.bar', 'fu.bar', 'foo.baz']) == {'foo.bar': 'foo.bar.', 28 'fu.bar': 'fu.bar.', 29 'foo.baz': 'baz.'} 30 31 def test_name_generator(self) -> None: 32 g = NameGenerator([['foo', 'foo.zar']]) 33 assert g.private_name('foo', 'f') == 'foo___f' 34 assert g.private_name('foo', 'C.x.y') == 'foo___C___x___y' 35 assert g.private_name('foo', 'C.x.y') == 'foo___C___x___y' 36 assert g.private_name('foo.zar', 'C.x.y') == 'zar___C___x___y' 37 assert g.private_name('foo', 'C.x_y') == 'foo___C___x_y' 38 assert g.private_name('foo', 'C_x_y') == 'foo___C_x_y' 39 assert g.private_name('foo', 'C_x_y') == 'foo___C_x_y' 40 assert g.private_name('foo', '___') == 'foo______3_' 41